@@ -2,7 +2,7 @@ require("dotenv").config();
22const Webmentions = require ( "eleventy-plugin-webmentions" ) ;
33const pluginRss = require ( "@11ty/eleventy-plugin-rss" ) ;
44const Image = require ( "@11ty/eleventy-img" ) ;
5- const htmlmin = require ( "html-minifier" ) ;
5+ const htmlmin = require ( "html-minifier-terser " ) ;
66const outdent = require ( "outdent" ) ;
77const pluginNavigation = require ( "@11ty/eleventy-navigation" ) ;
88const pluginSyntaxHighlight = require ( "@11ty/eleventy-plugin-syntaxhighlight" ) ;
@@ -11,6 +11,8 @@ const markdownItAttrs = require("markdown-it-attrs");
1111const pluginTOC = require ( "eleventy-plugin-toc" ) ;
1212const pluginFilters = require ( "./_config/filters.js" ) ;
1313const pluginShortCodes = require ( "./_config/shortcode.js" ) ;
14+ const processCSS = require ( "./_build/process-css.js" ) ;
15+ const { fingerprintAssets } = require ( "./_build/fingerprint-assets.js" ) ;
1416
1517/** Maps a config of attribute-value pairs to an HTML string
1618 * representing those same attribute-value pairs.
@@ -31,31 +33,35 @@ const imageShortcode = async (
3133 alt ,
3234 className = undefined ,
3335 widths = [ 400 , 800 , 1280 ] ,
34- formats = [ "webp" , "jpeg" ] ,
36+ formats = [ "avif" , " webp", "jpeg" ] ,
3537 sizes = "100vw"
3638) => {
3739 const imageMetadata = await Image ( src , {
3840 widths : [ ...widths , null ] ,
3941 formats : [ ...formats , null ] ,
4042 outputDir : "_site/media/images" ,
4143 urlPath : "/media/images" ,
44+ sharpAvifOptions : {
45+ quality : 80 ,
46+ effort : 4 ,
47+ } ,
48+ sharpWebpOptions : {
49+ quality : 85 ,
50+ } ,
51+ sharpJpegOptions : {
52+ quality : 85 ,
53+ progressive : true ,
54+ } ,
4255 } ) ;
56+
4357 const sourceHtmlString = Object . values ( imageMetadata )
44- // Map each format to the source HTML markup
4558 . map ( ( images ) => {
46- // The first entry is representative of all the others
47- // since they each have the same shape
4859 const { sourceType } = images [ 0 ] ;
49-
50- // Use our util from earlier to make our lives easier
5160 const sourceAttributes = stringifyAttributes ( {
5261 type : sourceType ,
53- // srcset needs to be a comma-separated attribute
5462 srcset : images . map ( ( image ) => image . srcset ) . join ( ", " ) ,
5563 sizes,
5664 } ) ;
57-
58- // Return one <source> per format
5965 return `<source ${ sourceAttributes } >` ;
6066 } )
6167 . join ( "\n" ) ;
@@ -91,12 +97,20 @@ module.exports = function (eleventyConfig) {
9197 // 11ty plugins
9298 eleventyConfig . addPlugin ( pluginRss ) ;
9399
94- // Only add Webmentions if token is provided
95- if ( process . env . WEBMENTIONS_TOKEN ) {
100+ // Only add Webmentions if token is provided (CI usually won't have it)
101+ const webmentionsToken = process . env . WEBMENTIONS_TOKEN ;
102+ const hasWebmentionsToken =
103+ typeof webmentionsToken === "string" && webmentionsToken . trim ( ) . length > 0 ;
104+
105+ if ( hasWebmentionsToken ) {
96106 eleventyConfig . addPlugin ( Webmentions , {
97107 domain : "benkutil.com" ,
98- token : process . env . WEBMENTIONS_TOKEN ,
108+ token : webmentionsToken ,
99109 } ) ;
110+ } else {
111+ eleventyConfig . addGlobalData ( "webmentions" , [ ] ) ;
112+ eleventyConfig . addFilter ( "webmentionsForPage" , ( ) => [ ] ) ;
113+ eleventyConfig . addFilter ( "webmentionCountForPage" , ( ) => 0 ) ;
100114 }
101115
102116 eleventyConfig . addPlugin ( pluginNavigation ) ;
@@ -141,16 +155,19 @@ module.exports = function (eleventyConfig) {
141155 } ) ;
142156 } ) ;
143157
144- // Pass through Tufte CSS and fonts
145- eleventyConfig . addPassthroughCopy ( "src/css" ) ;
158+ // Pass through fonts (CSS is processed separately)
146159 eleventyConfig . addPassthroughCopy ( "src/et-book" ) ;
160+ eleventyConfig . addPassthroughCopy ( "src/media/favicons" ) ;
161+
162+ // Process CSS with PostCSS
163+ eleventyConfig . on ( "eleventy.before" , async ( ) => {
164+ await processCSS ( ) ;
165+ } ) ;
147166
148167 // run these configs in production only
149168 if ( process . env . ELEVENTY_ENV === "production" ) {
150169 eleventyConfig . addTransform ( "htmlmin" , function ( content , outputPath ) {
151- // find html files
152170 if ( outputPath && outputPath . endsWith ( ".html" ) ) {
153- // configure html-minify
154171 let minified = htmlmin . minify ( content , {
155172 useShortDoctype : true ,
156173 removeComments : true ,
@@ -162,6 +179,11 @@ module.exports = function (eleventyConfig) {
162179
163180 return content ;
164181 } ) ;
182+
183+ // Fingerprint assets after build completes
184+ eleventyConfig . on ( "eleventy.after" , async ( ) => {
185+ await fingerprintAssets ( ) ;
186+ } ) ;
165187 }
166188
167189 // Directory changes
0 commit comments