minify html

This commit is contained in:
Tommy Parnell
2023-12-02 20:29:48 -05:00
parent 8ffdd67c35
commit 7de6259fb2
21 changed files with 132 additions and 434 deletions

View File

@@ -1,5 +1,6 @@
const { DateTime } = require("luxon");
const markdownItAnchor = require("markdown-it-anchor");
const htmlmin = require("html-minifier");
const pluginRss = require("@11ty/eleventy-plugin-rss");
const pluginSyntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
@@ -99,6 +100,20 @@ module.exports = function(eleventyConfig) {
.filter(tag => ["all", "nav", "post", "posts"].indexOf(tag) === -1);
});
eleventyConfig.addTransform("htmlmin", function(content) {
// Prior to Eleventy 2.0: use this.outputPath instead
if( this.page.outputPath && this.page.outputPath.endsWith(".html") ) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true
});
return minified;
}
return content;
});
// Customize Markdown library settings:
// eleventyConfig.amendLibrary("md", mdLib => {
// mdLib.use(markdownItAnchor, {