Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.

Commit 0adac55

Browse files
committed
Bumps Eleventy Image to v6.0.0
Updates code to accommadet new shape of object returned by `generateObject()`
1 parent 04fe6da commit 0adac55

File tree

5 files changed

+17
-8
lines changed

5 files changed

+17
-8
lines changed

lib/img2picture.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ function generatePicture(metadata, attrs, options) {
134134
return tagObjectToHTML(tagsObject);
135135
}
136136

137-
return `<picture ${objectToHTMLAttributes(pictureAttrs)}>${tagsObject.picture
137+
// '@children' is internally used in Eleventy Image
138+
// https://github.com/11ty/eleventy-img/blob/092ad7a03caa08e2704690e88255da182a3acb1d/src/generate-html.js#L5
139+
const children = tagsObject?.picture?.["@children"];
140+
return `<picture ${objectToHTMLAttributes(pictureAttrs)}>${children
138141
.map(tagObjectToHTML)
139142
.join("")}</picture>`;
140143
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"author": "Saneef Ansari <hello@saneef.com> (https://saneef.com/)",
2424
"license": "MIT",
2525
"dependencies": {
26-
"@11ty/eleventy-img": "^5.0.0",
26+
"@11ty/eleventy-img": "^6.0.2",
2727
"cheerio": "^1.0.0-rc.12",
2828
"debug": "^4.3.4",
2929
"entities": "^4.5.0"

tests/snapshots/svgs.js.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,26 @@ The actual snapshot is saved in `svgs.js.snap`.
44

55
Generated by [AVA](https://avajs.dev).
66

7-
## Optimizes SVG image, generates AVIF, WebP, SVG, JPEG formats, and puts them in <picture>
7+
## Optimizes SVG image, generates AVIF, WebP, SVG formats, and puts them in <picture>
88

99
> Snapshot 1
1010
11-
'<html><head></head><body><picture><source type="image/avif" srcset="/images/Ghostscript_Tiger-150w.avif 150w, /images/Ghostscript_Tiger-300w.avif 300w, /images/Ghostscript_Tiger-900w.svg 900w" sizes="100vw"><source type="image/webp" srcset="/images/Ghostscript_Tiger-150w.webp 150w, /images/Ghostscript_Tiger-900w.svg 900w" sizes="100vw"><source type="image/svg+xml" srcset="/images/Ghostscript_Tiger-900w.svg 900w" sizes="100vw"><img alt="Ghostscript Tiger" loading="lazy" decoding="async" src="/images/Ghostscript_Tiger-150w.jpeg" width="900" height="900" srcset="/images/Ghostscript_Tiger-150w.jpeg 150w, /images/Ghostscript_Tiger-900w.svg 900w" sizes="100vw"></picture></body></html>'
11+
'<html><head></head><body><picture><source type="image/avif" srcset="/images/Ghostscript_Tiger-150w.avif 150w, /images/Ghostscript_Tiger-300w.avif 300w, /images/Ghostscript_Tiger-900w.svg 900w" sizes="100vw"><source type="image/webp" srcset="/images/Ghostscript_Tiger-150w.webp 150w, /images/Ghostscript_Tiger-900w.svg 900w" sizes="100vw"><img alt="Ghostscript Tiger" loading="lazy" decoding="async" src="/images/Ghostscript_Tiger-900w.svg" width="900" height="900"></picture></body></html>'
1212

1313
## Optimizes SVG image to other formats when `svgShortCircuit: false`
1414

1515
> Snapshot 1
1616
17-
'<html><head></head><body><picture><source type="image/svg+xml" srcset="/images/Ghostscript_Tiger-900w.svg 900w" sizes="100vw"><source type="image/avif" srcset="/images/Ghostscript_Tiger-150w.avif 150w, /images/Ghostscript_Tiger-300w.avif 300w, /images/Ghostscript_Tiger-450w.avif 450w, /images/Ghostscript_Tiger-600w.avif 600w, /images/Ghostscript_Tiger-750w.avif 750w, /images/Ghostscript_Tiger-900w.avif 900w, /images/Ghostscript_Tiger-1050w.avif 1050w, /images/Ghostscript_Tiger-1200w.avif 1200w, /images/Ghostscript_Tiger-1350w.avif 1350w" sizes="100vw"><source type="image/webp" srcset="/images/Ghostscript_Tiger-150w.webp 150w, /images/Ghostscript_Tiger-300w.webp 300w, /images/Ghostscript_Tiger-450w.webp 450w, /images/Ghostscript_Tiger-600w.webp 600w, /images/Ghostscript_Tiger-750w.webp 750w, /images/Ghostscript_Tiger-900w.webp 900w, /images/Ghostscript_Tiger-1050w.webp 1050w, /images/Ghostscript_Tiger-1200w.webp 1200w, /images/Ghostscript_Tiger-1350w.webp 1350w" sizes="100vw"><img alt="Ghostscript Tiger" loading="lazy" decoding="async" src="/images/Ghostscript_Tiger-150w.jpeg" width="1350" height="1350" srcset="/images/Ghostscript_Tiger-150w.jpeg 150w, /images/Ghostscript_Tiger-300w.jpeg 300w, /images/Ghostscript_Tiger-450w.jpeg 450w, /images/Ghostscript_Tiger-600w.jpeg 600w, /images/Ghostscript_Tiger-750w.jpeg 750w, /images/Ghostscript_Tiger-900w.jpeg 900w, /images/Ghostscript_Tiger-1050w.jpeg 1050w, /images/Ghostscript_Tiger-1200w.jpeg 1200w, /images/Ghostscript_Tiger-1350w.jpeg 1350w" sizes="100vw"></picture></body></html>'
17+
'<html><head></head><body><picture><source type="image/avif" srcset="/images/Ghostscript_Tiger-150w.avif 150w, /images/Ghostscript_Tiger-300w.avif 300w, /images/Ghostscript_Tiger-450w.avif 450w, /images/Ghostscript_Tiger-600w.avif 600w, /images/Ghostscript_Tiger-750w.avif 750w, /images/Ghostscript_Tiger-900w.avif 900w, /images/Ghostscript_Tiger-1050w.avif 1050w, /images/Ghostscript_Tiger-1200w.avif 1200w, /images/Ghostscript_Tiger-1350w.avif 1350w" sizes="100vw"><source type="image/webp" srcset="/images/Ghostscript_Tiger-150w.webp 150w, /images/Ghostscript_Tiger-300w.webp 300w, /images/Ghostscript_Tiger-450w.webp 450w, /images/Ghostscript_Tiger-600w.webp 600w, /images/Ghostscript_Tiger-750w.webp 750w, /images/Ghostscript_Tiger-900w.webp 900w, /images/Ghostscript_Tiger-1050w.webp 1050w, /images/Ghostscript_Tiger-1200w.webp 1200w, /images/Ghostscript_Tiger-1350w.webp 1350w" sizes="100vw"><img alt="Ghostscript Tiger" loading="lazy" decoding="async" src="/images/Ghostscript_Tiger-900w.svg" width="900" height="900"></picture></body></html>'
1818

1919
## Process SVG image and skip to other formats when `svgShortCircuit: true`
2020

2121
> Snapshot 1
2222
2323
'<html><head></head><body><img alt="Ghostscript Tiger" loading="lazy" decoding="async" src="/images/Ghostscript_Tiger-900w.svg" width="900" height="900"></body></html>'
24+
25+
## Optimizes SVG image, generates AVIF, WebP, SVG, JPEG formats, and puts them in <picture>
26+
27+
> Snapshot 1
28+
29+
'<html><head></head><body><picture><source type="image/avif" srcset="/images/Ghostscript_Tiger-150w.avif 150w, /images/Ghostscript_Tiger-300w.avif 300w, /images/Ghostscript_Tiger-900w.svg 900w" sizes="100vw"><source type="image/webp" srcset="/images/Ghostscript_Tiger-150w.webp 150w, /images/Ghostscript_Tiger-900w.svg 900w" sizes="100vw"><img alt="Ghostscript Tiger" loading="lazy" decoding="async" src="/images/Ghostscript_Tiger-900w.svg" width="900" height="900"></picture></body></html>'

tests/snapshots/svgs.js.snap

-64 Bytes
Binary file not shown.

tests/svgs.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const baseOptions = {
2121
formats: ["avif", "webp", "svg", "jpeg"],
2222
};
2323

24-
test("Optimizes SVG image, generates AVIF, WebP, SVG, JPEG formats, and puts them in <picture>", async (t) => {
24+
test("Optimizes SVG image, generates AVIF, WebP, SVG formats, and puts them in <picture>", async (t) => {
2525
const input =
2626
'<img src="/images/Ghostscript_Tiger.svg" alt="Ghostscript Tiger">';
2727
const outputPath = "file.html";
@@ -38,10 +38,10 @@ test("Optimizes SVG image, generates AVIF, WebP, SVG, JPEG formats, and puts the
3838
t.true(existsSync(svgFilePath));
3939

4040
const { width: smallestImgWidth } = imageSize(
41-
path.join(imagesOutputDir, "Ghostscript_Tiger-150w.jpeg"),
41+
path.join(imagesOutputDir, "Ghostscript_Tiger-150w.webp"),
4242
);
4343
const { width: largestImgWidth } = imageSize(
44-
path.join(imagesOutputDir, "Ghostscript_Tiger-1350w.jpeg"),
44+
path.join(imagesOutputDir, "Ghostscript_Tiger-1350w.webp"),
4545
);
4646

4747
t.is(smallestImgWidth, 150);

0 commit comments

Comments
 (0)