diff --git a/eleventy.config.mjs b/eleventy.config.mjs index 55cd6ad29..78bbd0415 100644 --- a/eleventy.config.mjs +++ b/eleventy.config.mjs @@ -4,6 +4,7 @@ import { EleventyI18nPlugin } from '@11ty/eleventy'; import { PATHS } from '@openinf/portal/build/constants'; import autoprefixer from 'autoprefixer'; import cssnano from 'cssnano'; +import { minify as minifyHtml } from 'html-minifier-terser'; import markdownItAnchor from 'markdown-it-anchor'; import markdownItFootnote from 'markdown-it-footnote'; import markdownItGitHubAlerts from 'markdown-it-github-alerts'; @@ -170,6 +171,38 @@ export default async function (eleventyConfig) { }, }); + // Only the build that publishes. A reader downloads this output; a + // developer reads `_site` in a diff. + if (isProduction) { + eleventyConfig.addTransform('minifyHtml', function (content) { + // Sass partials output nothing, and their `outputPath` is `false` + // rather than absent, which optional chaining does not catch. + const output = this.page.outputPath; + + if (typeof output !== 'string' || !output.endsWith('.html')) { + return content; + } + + return minifyHtml(content, { + // `
` and `