eleventy-webpack
eleventy-webpack copied to clipboard
Image shortcode error with “jpg” file extensions
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;
Thanks, will have a look !