fix image url construction

This commit is contained in:
keyan 2024-03-20 14:18:11 -05:00
parent ecd075f483
commit e8f9a186c6

View File

@ -70,7 +70,7 @@ function ImageProxy ({ src, srcSet: { dimensions, ...srcSetObj } = {}, onClick,
return Object.entries(srcSetObj).reduce((acc, [wDescriptor, url], i, arr) => { return Object.entries(srcSetObj).reduce((acc, [wDescriptor, url], i, arr) => {
// backwards compatibility: we used to replace image urls with imgproxy urls rather just storing paths // backwards compatibility: we used to replace image urls with imgproxy urls rather just storing paths
if (!url.startsWith('http')) { if (!url.startsWith('http')) {
url = `${process.env.NEXT_PUBLIC_IMGPROXY_URL}${url}` url = new URL(url, process.env.NEXT_PUBLIC_IMGPROXY_URL).toString()
} }
return acc + `${url} ${wDescriptor}` + (i < arr.length - 1 ? ', ' : '') return acc + `${url} ${wDescriptor}` + (i < arr.length - 1 ? ', ' : '')
}, '') }, '')
@ -82,7 +82,7 @@ function ImageProxy ({ src, srcSet: { dimensions, ...srcSetObj } = {}, onClick,
if (!srcSetObj) return src if (!srcSetObj) return src
return Object.entries(srcSetObj).reduce((acc, [wDescriptor, url]) => { return Object.entries(srcSetObj).reduce((acc, [wDescriptor, url]) => {
if (!url.startsWith('http')) { if (!url.startsWith('http')) {
url = `${process.env.NEXT_PUBLIC_IMGPROXY_URL}${url}` url = new URL(url, process.env.NEXT_PUBLIC_IMGPROXY_URL).toString()
} }
const w = Number(wDescriptor.replace(/w$/, '')) const w = Number(wDescriptor.replace(/w$/, ''))
return w > acc.w ? { w, url } : acc return w > acc.w ? { w, url } : acc