eleventy-webpack icon indicating copy to clipboard operation
eleventy-webpack copied to clipboard

Image shortcode error with “jpg” file extensions

Open tedw opened this issue 4 years ago • 1 comments

FYI, after updating @11ty/eleventy-img to 0.8.0 I was getting this error:

TypeError: Cannot read property 'reverse' of undefined

https://github.com/clenemt/eleventy-webpack/blob/2b0242d3abc63c7135bcad11b9fce73e7ff03a00/utils/shortcodes.js#L86

After reading through the changes, it turned out to be related to this fix https://github.com/11ty/eleventy-img/issues/64#issuecomment-778842404.

Regardless of whether the source image uses the jpg or jpeg extension, the returned object will use the jpeg key.

Here’s how I fixed it in my project:

let extension = path.extname(src).slice(1).toLowerCase();

// Normalize “jpg” extension to match what @11ty/eleventy-img does
extension = extension == 'jpg' ? 'jpeg' : extension;

tedw avatar Feb 17 '21 17:02 tedw

Thanks, will have a look !

clenemt avatar Feb 21 '21 14:02 clenemt