Skip to content

Commit 1e70e3d

Browse files
committed
Fix eleventy-img fetch 404 issue
1 parent 8a8bea2 commit 1e70e3d

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

_includes/shortcodes/avatar.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
const Image = require('@11ty/eleventy-img');
22

33
module.exports = async (src, alt, className, outputFormat = 'jpeg') => {
4-
const stats = await Image(src, {
5-
cacheDuration: '12w',
6-
formats: [outputFormat],
7-
outputDir: '_site/assets/avatar/',
8-
widths: [96],
9-
});
4+
if (alt === undefined) {
5+
throw new Error(`Missing ALT attribute from: ${src}`);
6+
}
107

118
const classAttr = className ? `class="${className}"` : '';
129

13-
const props = stats[outputFormat].pop();
10+
try {
11+
const stats = await Image(src, {
12+
cacheDuration: '12w',
13+
formats: [outputFormat],
14+
outputDir: '_site/assets/avatar/',
15+
widths: [96],
16+
});
1417

15-
if (alt === undefined) {
16-
throw new Error(`Missing ALT attribute from: ${src}`);
17-
}
18+
const props = stats[outputFormat].pop();
1819

19-
return `<img ${classAttr} src="${props.outputPath.replace('_site', '')}" alt="${alt}" loading="lazy">`;
20+
return `<img ${classAttr} src="${props.outputPath.replace('_site', '')}" alt="${alt}" loading="lazy">`;
21+
} catch (err) {
22+
// eslint-disable-next-line no-console
23+
console.error(err);
24+
25+
return '';
26+
}
2027
};

0 commit comments

Comments
 (0)