Skip to content

Commit

Permalink
Minimize html (#532)
Browse files Browse the repository at this point in the history
* minimizes html

* quick package fix

* removes clean-html

---------

Co-authored-by: Shawn Thompson <[email protected]>
  • Loading branch information
acev0010 and shawnthompson authored Jan 8, 2024
1 parent b190bbe commit f90ee74
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 188 deletions.
13 changes: 13 additions & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const markdownItAnchor = require('markdown-it-anchor');
const markdownItAttrs = require('markdown-it-attrs');
const { EleventyHtmlBasePlugin } = require('@11ty/eleventy');
const { stripHtml } = require('string-strip-html');
const htmlmin = require("html-minifier");
const { dynamicImport } = require('tsimportlib');

module.exports = function (eleventyConfig) {
Expand Down Expand Up @@ -37,6 +38,18 @@ module.exports = function (eleventyConfig) {

eleventyConfig.addPlugin(EleventyHtmlBasePlugin);

// Minify HTML output
eleventyConfig.addTransform("htmlmin", function(content, outputPath) {
if (outputPath && outputPath.endsWith(".html")) {
return htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true
});
}
return content;
});

eleventyConfig.addFilter("localeMatch", function (collection) {
const { locale } = this.ctx; // avoid retrieving it for each item
return collection.filter((item) => item.data.locale === locale);
Expand Down
Loading

0 comments on commit f90ee74

Please sign in to comment.