fix: 🐛 add transform so prevent generation of invalid markup
Occasionally, WebC components in Markdown cause unintended paragraph tags to appear in places which produce invalid markup and break styling
This commit is contained in:
parent
db8cf3f93c
commit
23c06bcd3a
3 changed files with 243 additions and 5 deletions
|
@ -1,6 +1,7 @@
|
|||
import eleventyPluginNavigation from '@11ty/eleventy-navigation';
|
||||
import eleventyPluginWebc from '@11ty/eleventy-plugin-webc';
|
||||
import { eleventyImagePlugin } from '@11ty/eleventy-img';
|
||||
import htmlminifier from 'html-minifier-terser';
|
||||
|
||||
const IMAGE_TRANSFORM_OPTS = {
|
||||
// Set global default options
|
||||
|
@ -31,8 +32,24 @@ export default async function (eleventyConfig) {
|
|||
collection.getFilteredByGlob('./src/jarek/*.md')
|
||||
);
|
||||
|
||||
eleventyConfig.addTransform('minhtml', function (content) {
|
||||
if ((this.page.outputPath || '').endsWith('.html')) {
|
||||
return htmlminifier.minify(content, {
|
||||
// keepClosingSlash: true,
|
||||
removeEmptyElements: true,
|
||||
collapseWhitespace: true,
|
||||
ignoreCustomFragments: [
|
||||
/<(use|path)[^>]*>(?:(?!<\/(use|path)>)[\s\S])*?<\/(use|path)>/,
|
||||
/<div[^>]*class="color-box"[^>]*>(?:(?!<\/div>)[\s\S])*?<\/div>/,
|
||||
/<nav[^>]*class="gallery-nav"[^>]*>.*?<\/nav>/
|
||||
]
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
eleventyConfig.addPlugin(eleventyPluginWebc, {
|
||||
components: ['src/components/**/*.webc', 'npm:@11ty/eleventy-img/*.webc']
|
||||
components: ['src/components/**/*.webc', 'npm:@11ty/eleventy-img/*.webc'],
|
||||
useTransform: false
|
||||
});
|
||||
eleventyConfig.addPlugin(eleventyPluginNavigation);
|
||||
eleventyConfig.addPlugin(eleventyImagePlugin, IMAGE_TRANSFORM_OPTS);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue