From 7704f70db1c756f28f557bd13875a29b11419ef7 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 15 Nov 2024 06:58:32 +0100 Subject: [PATCH] fix: replace `//` characters in ipx urls --- nuxt.config.ts | 4 ---- package.json | 3 +++ patches/@nuxt__image.patch | 14 ++++++++++++++ pnpm-lock.yaml | 9 +++++++-- 4 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 patches/@nuxt__image.patch diff --git a/nuxt.config.ts b/nuxt.config.ts index 593a3ec3..6afb7ac6 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -174,10 +174,6 @@ export default defineNuxtConfig({ '$1', ) - if (route.fileName?.endsWith('.html') && route.contents) { - route.contents = route.contents.replace(/(src|href|srcset)="\/_ipx[^"]+"/g, r => r.replaceAll('//', '/')) - } - if (route.error) { if (route.route.startsWith('/_ipx')) { console.warn('Could not prerender', route.route) diff --git a/package.json b/package.json index 1c6b4d3b..afe528c0 100644 --- a/package.json +++ b/package.json @@ -110,6 +110,9 @@ "@unhead/vue": "1.11.11", "unhead": "1.11.11", "vue": "3.5.12" + }, + "patchedDependencies": { + "@nuxt/image": "patches/@nuxt__image.patch" } } } diff --git a/patches/@nuxt__image.patch b/patches/@nuxt__image.patch new file mode 100644 index 00000000..43308029 --- /dev/null +++ b/patches/@nuxt__image.patch @@ -0,0 +1,14 @@ +diff --git a/dist/runtime/providers/ipx.js b/dist/runtime/providers/ipx.js +index 434c1a9ffa42cfcff730623dd22cdf89f1efcc47..5e914567a6743e5e2527eed61f88489bd58c8624 100644 +--- a/dist/runtime/providers/ipx.js ++++ b/dist/runtime/providers/ipx.js +@@ -24,7 +24,8 @@ export const getImage = (src, { modifiers = {}, baseURL } = {}, ctx) => { + baseURL = joinURL(ctx.options.nuxt.baseURL, "/_ipx"); + } + return { +- url: joinURL(baseURL, params, encodePath(src)) ++ // TODO: port to ipxStatic ++ url: joinURL(baseURL, params, encodePath(src).replace(/\/\//g, '/')) + }; + }; + export const validateDomains = true; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 788b4db7..87239d0c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -16,6 +16,11 @@ overrides: unhead: 1.11.11 vue: 3.5.12 +patchedDependencies: + '@nuxt/image': + hash: xp2pdlshg2i2ybrtq5wt4pfx6y + path: patches/@nuxt__image.patch + importers: .: @@ -49,7 +54,7 @@ importers: version: 0.10.2(ioredis@5.4.1)(magicast@0.3.5)(rollup@4.24.4)(vite@5.4.11(@types/node@22.9.0)(terser@5.36.0))(webpack-sources@3.2.3) '@nuxt/image': specifier: 1.8.1 - version: 1.8.1(ioredis@5.4.1)(magicast@0.3.5)(rollup@4.24.4)(webpack-sources@3.2.3) + version: 1.8.1(patch_hash=xp2pdlshg2i2ybrtq5wt4pfx6y)(ioredis@5.4.1)(magicast@0.3.5)(rollup@4.24.4)(webpack-sources@3.2.3) '@nuxt/scripts': specifier: ^0.9.5 version: 0.9.5(@nuxt/devtools@1.6.0(rollup@4.24.4)(vite@5.4.11(@types/node@22.9.0)(terser@5.36.0))(vue@3.5.12(typescript@5.6.3))(webpack-sources@3.2.3))(@unocss/webpack@0.64.0(rollup@4.24.4)(webpack@5.96.1(esbuild@0.23.1)))(@vue/compiler-core@3.5.12)(change-case@5.4.4)(ioredis@5.4.1)(magicast@0.3.5)(nuxt@3.14.159(@parcel/watcher@2.5.0)(@types/node@22.9.0)(eslint@9.14.0(jiti@2.4.0))(ioredis@5.4.1)(magicast@0.3.5)(optionator@0.9.4)(rollup@4.24.4)(stylelint@16.10.0(typescript@5.6.3))(terser@5.36.0)(typescript@5.6.3)(vite@5.4.11(@types/node@22.9.0)(terser@5.36.0))(vue-tsc@2.1.10(typescript@5.6.3))(webpack-sources@3.2.3))(postcss@8.4.49)(rollup@4.24.4)(typescript@5.6.3)(vite@5.4.11(@types/node@22.9.0)(terser@5.36.0))(vue@3.5.12(typescript@5.6.3))(webpack-sources@3.2.3)(webpack@5.96.1(esbuild@0.23.1)) @@ -8665,7 +8670,7 @@ snapshots: - vite - webpack-sources - '@nuxt/image@1.8.1(ioredis@5.4.1)(magicast@0.3.5)(rollup@4.24.4)(webpack-sources@3.2.3)': + '@nuxt/image@1.8.1(patch_hash=xp2pdlshg2i2ybrtq5wt4pfx6y)(ioredis@5.4.1)(magicast@0.3.5)(rollup@4.24.4)(webpack-sources@3.2.3)': dependencies: '@nuxt/kit': 3.14.159(magicast@0.3.5)(rollup@4.24.4)(webpack-sources@3.2.3) consola: 3.2.3 -- knotmirror 0.0.1