Niels-IO / next-image-export-optimizer

Use Next.js advanced <Image/> component with the static export functionality. Optimizes all static images in an additional step after the Next.js static export.
MIT License
439 stars 52 forks source link

fix: add support for external images with query params #209

Closed mmtftr closed 3 months ago

mmtftr commented 7 months ago

The library didn't work with external images that had URLs with query parameters since it encoded them into the extension, thus making it impossible to know the extension in React.

Problem demonstration

console.log(urlToFilename('https://example.com/image.png?asd=123')) // -> 'example.com_image.png_asd=123'

'png_asd=123' is not a valid extension, so the React component falls back to the original URL, basically making it meaningless to use the library.

My change

My change adds the '.png' back into the filename at the end when there is a nonempty search query.

mmtftr commented 5 months ago

@Niels-IO I think this might be a useful fix for a lot of people, especially those that use google storage images with presigned keys

Niels-IO commented 5 months ago

Hi @mmtftr,

Thanks for the PR!. I will take a look but it might take me until May as I am quite busy now.

Niels-IO commented 3 months ago

Hi @mmtftr,

Thank you very much for your PR. I changed the remote Image functionality quite a bit and your code did help me a lot. I integrated it in #220.

Hopefully, you don't mind that I didn't merge your PR directly.