Skip to content

Commit a48bab9

Browse files
committed
optimize image handling
1 parent bbc46f8 commit a48bab9

3 files changed

Lines changed: 42 additions & 28 deletions

File tree

.claude/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(node -e ':*)",
5+
"Read(//c/Projekte/XE/recipe/{split\\($1, a, \"M\"\\); total=a[1]; print \"Total in dist/**)",
6+
"Read(//c/Projekte/XE/recipe/{split\\($1, a, \"M\"\\); images=a[1]; print \"Total in dist/img/**)"
7+
]
8+
}
9+
}

.github/workflows/jekyll-gh-pages.yml

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,34 +38,29 @@ jobs:
3838
node-version: ${{ env.NODE_VERSION }}
3939
cache: 'npm'
4040

41-
- name: Cache Eleventy build artifacts
41+
- name: Cache Eleventy incremental build state
4242
uses: actions/cache@v4
4343
with:
44-
path: |
45-
dist
46-
.cache
47-
_site
48-
key: eleventy-build-${{ runner.os }}-${{ hashFiles('src/**/*', 'content/**/*', 'media/**/*', 'eleventy.config.js', 'postcss.config.js', 'package-lock.json') }}
44+
path: .cache
45+
key: eleventy-build-${{ runner.os }}-${{ hashFiles('eleventy.config.js', 'package-lock.json') }}-${{ github.sha }}
4946
restore-keys: |
50-
eleventy-build-${{ runner.os }}-${{ hashFiles('eleventy.config.js', 'postcss.config.js', 'package-lock.json') }}
51-
47+
eleventy-build-${{ runner.os }}-${{ hashFiles('eleventy.config.js', 'package-lock.json') }}-
48+
5249
- name: Cache processed images
5350
uses: actions/cache@v4
5451
with:
55-
path: |
56-
dist/img
57-
.cache/img
58-
key: eleventy-img-${{ runner.os }}-${{ hashFiles('media/**/*', 'src/_11ty/shortcodes.js') }}
52+
path: dist/img
53+
key: eleventy-img-${{ runner.os }}-${{ hashFiles('src/_11ty/shortcodes.js') }}-${{ github.sha }}
5954
restore-keys: |
60-
eleventy-img-${{ runner.os }}-${{ hashFiles('media/**/*') }}
61-
55+
eleventy-img-${{ runner.os }}-${{ hashFiles('src/_11ty/shortcodes.js') }}-
56+
6257
- name: Cache CSS build
6358
uses: actions/cache@v4
6459
with:
6560
path: dist/styles
66-
key: css-build-${{ runner.os }}-${{ hashFiles('src/site.css', 'src/_styles/**/*', 'postcss.config.js') }}
61+
key: css-build-${{ runner.os }}-${{ hashFiles('postcss.config.js') }}-${{ github.sha }}
6762
restore-keys: |
68-
css-build-${{ runner.os }}-${{ hashFiles('postcss.config.js') }}
63+
css-build-${{ runner.os }}-${{ hashFiles('postcss.config.js') }}-
6964
7065
- name: Install dependencies
7166
run: npm ci

src/_11ty/shortcodes.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
const 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

317
const 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

Comments
 (0)