Skip to content

Commit

Permalink
added features block
Browse files Browse the repository at this point in the history
  • Loading branch information
eKrausedivae committed Feb 2, 2024
1 parent 379dca4 commit c408b4f
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 24 deletions.
10 changes: 10 additions & 0 deletions dist/__chunks__/unsafe-html.tmuruS4o.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/__chunks__/unsafe-html.tmuruS4o.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 1 addition & 9 deletions dist/banner/banner.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/banner/banner.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions dist/features/features.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/features/features.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions src/blocks/features/features.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { html, render } from 'lit';
import { unsafeHTML } from 'lit-html/directives/unsafe-html.js';

interface Feature {
icon: string;
textBlock: string;
}

type TemplateArgs = Feature[];

const template = (features: TemplateArgs) => {
return html`
${features.map(
(feature) => html`
<article>
<span class="icon fa-gem">${feature.icon}</span>
<div class="content">${unsafeHTML(feature.textBlock)}</div>
</article>
`
)}
`;
};

export default function (block: HTMLElement) {
const rows = block.querySelectorAll(':scope > div');
let features: Feature[] = [];
[...rows].forEach((row) => {
const icon = row.children[0].innerHTML;
const textBlock = row.children[1].innerHTML;
features.push({ icon, textBlock });
});

block.innerHTML = '';

block.style.removeProperty('display');
render(template(features), block);
}
1 change: 1 addition & 0 deletions types/blocks/features/features.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default function (block: HTMLElement): void;
29 changes: 15 additions & 14 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { defineConfig } from "vite";
import minifyHTML from "rollup-plugin-minify-html-literals";
import { defineConfig } from 'vite';
import minifyHTML from 'rollup-plugin-minify-html-literals';

const { resolve } = require("path");
const { resolve } = require('path');

const isProd = process.env.NODE_ENV === "production";
const isProd = process.env.NODE_ENV === 'production';

export default defineConfig(({ command, mode }) => {
return {
Expand All @@ -15,25 +15,26 @@ export default defineConfig(({ command, mode }) => {
minify: true,
cssMinify: true,
commonjsOptions: {
include: ["node_modules/**"],
include: ['node_modules/**'],
},
emptyOutDir: true,
rollupOptions: {
cache: false,
preserveEntrySignatures: "strict",
preserveEntrySignatures: 'strict',
input: {
styles: resolve(__dirname, "src/styles/sass/main.scss"),
main: resolve(__dirname, "src/main.ts"),
counter: resolve(__dirname, "src/blocks/counter/counter.ts"),
banner: resolve(__dirname, "src/blocks/banner/banner.ts"),
styles: resolve(__dirname, 'src/styles/sass/main.scss'),
main: resolve(__dirname, 'src/main.ts'),
counter: resolve(__dirname, 'src/blocks/counter/counter.ts'),
banner: resolve(__dirname, 'src/blocks/banner/banner.ts'),
features: resolve(__dirname, 'src/blocks/features/features.ts'),
},
output: {
dir: "dist",
dir: 'dist',
assetFileNames: () => {
return "[name]/[name][extname]";
return '[name]/[name][extname]';
},
chunkFileNames: "__chunks__/[name].[hash].js",
entryFileNames: "[name]/[name].js",
chunkFileNames: '__chunks__/[name].[hash].js',
entryFileNames: '[name]/[name].js',
},
plugins: [isProd && minifyHTML()],
},
Expand Down

0 comments on commit c408b4f

Please sign in to comment.