File tree Expand file tree Collapse file tree 1 file changed +18
-11
lines changed
Expand file tree Collapse file tree 1 file changed +18
-11
lines changed Original file line number Diff line number Diff line change 11const Image = require ( '@11ty/eleventy-img' ) ;
22
33module . 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} ;
You can’t perform that action at this time.
0 commit comments