11import path from 'node:path' ;
22import os from 'node:os' ;
3+ import fs from 'node:fs' ;
34import htmlmin from 'html-minifier-terser' ;
45import minifyXml from 'minify-xml' ;
56import { parseHTML } from 'linkedom' ;
@@ -11,12 +12,9 @@ const isProdMode = process.env.NODE_ENV === 'production';
1112
1213async function processImage ( { imageElement, inputPath, options, attributes } ) {
1314 const imageStats = await Image ( inputPath , {
14- filenameFormat : ( hash , src , width , format ) => {
15- const extension = path . extname ( src ) ;
16- const name = path . basename ( src , extension ) ;
17- return `${ hash } -${ name } -${ width } .${ format } ` ;
18- } ,
19- ...options ,
15+ outputDir : '.cache/@11ty/_images' ,
16+ urlPath : '/_images/' ,
17+ ...options
2018 } ) ;
2119
2220 const imageAttributes = Object . assign (
@@ -53,7 +51,6 @@ export default function(eleventyConfig) {
5351 }
5452
5553 const articleSourceFolder = path . dirname ( this . page . inputPath ) ;
56- const outputArticleImagesFolder = path . join ( path . dirname ( this . page . outputPath ) , 'images' ) ;
5754
5855 await Promise . all ( images . map ( async ( image ) => {
5956 const fullImagePath = path . join ( articleSourceFolder , image . src ) ;
@@ -69,8 +66,6 @@ export default function(eleventyConfig) {
6966 formats : isProdMode && ! isGif
7067 ? [ 'svg' , 'avif' , 'webp' , 'auto' ]
7168 : [ 'svg' , 'webp' , 'auto' ] ,
72- outputDir : outputArticleImagesFolder ,
73- urlPath : 'images/' ,
7469 svgShortCircuit : true ,
7570 sharpOptions : {
7671 animated : true ,
@@ -108,7 +103,6 @@ export default function(eleventyConfig) {
108103
109104 await Promise . all ( images . map ( async ( image ) => {
110105 const fullImagePath = path . join ( eleventyConfig . dir . input , image . src ) ;
111- const avatarsOutputFolder = path . dirname ( path . join ( eleventyConfig . dir . output , image . src ) ) ;
112106
113107 await processImage ( {
114108 imageElement : image ,
@@ -124,8 +118,6 @@ export default function(eleventyConfig) {
124118 formats : isProdMode
125119 ? [ 'svg' , 'avif' , 'webp' , 'auto' ]
126120 : [ 'svg' , 'webp' , 'auto' ] ,
127- outputDir : avatarsOutputFolder ,
128- urlPath : image . src . split ( '/' ) . slice ( 0 , - 1 ) . join ( '/' ) ,
129121 svgShortCircuit : true ,
130122 } ,
131123 } ) ;
@@ -134,6 +126,12 @@ export default function(eleventyConfig) {
134126 return document . toString ( ) ;
135127 } ) ;
136128
129+ eleventyConfig . on ( 'eleventy.after' , ( ) => {
130+ const from = '.cache/@11ty/_images/' ;
131+ const to = path . join ( eleventyConfig . directories . output , '_images' ) ;
132+ fs . cpSync ( from , to , { recursive : true } ) ;
133+ } ) ;
134+
137135 eleventyConfig . addTransform ( 'lazyYouTube' , ( content , outputPath ) => {
138136 let articles = / a r t i c l e s \/ ( [ a - z A - Z 0 - 9 _ - ] + ) \/ i n d e x \. h t m l / i;
139137 let iframes = / < i f r a m e s r c = " h t t p s : \/ \/ w w w \. y o u t u b e \. c o m \/ e m b e d \/ ( [ a - z A - Z 0 - 9 _ - ] + ) " ( .* ?) > < \/ i f r a m e > / ig;
0 commit comments