11const Image = require ( "@11ty/eleventy-img" ) ;
2+ const fs = require ( "fs" ) ;
3+
4+ const imageOptions = {
5+ widths : [ 320 , 640 , 960 , 1280 , 1600 ] ,
6+ formats : [ "avif" , "webp" ] ,
7+ urlPath : "/img/" ,
8+ outputDir : "./dist/img/" ,
9+ sharpAvifOptions : {
10+ quality : 50 ,
11+ } ,
12+ sharpWebpOptions : {
13+ quality : 65 ,
14+ } ,
15+ } ;
216
317const picture = async function (
418 src ,
@@ -8,18 +22,14 @@ const picture = async function (
822 sizes = "(min-width: 64rem) 1024px, 100vw" ,
923 fetchpriority = undefined
1024) {
11- const metadata = await Image ( src , {
12- widths : [ 320 , 640 , 960 , 1280 , 1600 ] ,
13- formats : [ "avif" , "webp" ] ,
14- urlPath : "/img/" ,
15- outputDir : "./dist/img/" ,
16- sharpAvifOptions : {
17- quality : 50 ,
18- } ,
19- sharpWebpOptions : {
20- quality : 65 ,
21- } ,
22- } ) ;
25+ // Use statsSync to compute expected output filenames without processing
26+ const stats = Image . statsSync ( src , imageOptions ) ;
27+ const allExist = Object . values ( stats )
28+ . flat ( )
29+ . every ( ( s ) => fs . existsSync ( `${ imageOptions . outputDir } ${ s . filename } ` ) ) ;
30+
31+ // Skip expensive Sharp processing if all output files already exist (e.g. from CI cache)
32+ const metadata = allExist ? stats : await Image ( src , imageOptions ) ;
2333
2434 const imageAttributes = {
2535 title,
0 commit comments