Resolve result images against an absolute baseUrl

Relative images were resolved against the page URL, but only the
pathname was kept, so with a baseUrl on another domain the image
still loaded from the search site. Keep the origin when the page URL
has one, in the Component UI's resolveUrl filter and in both Default
UI result templates. result_with_subs.svelte didn't resolve images at
all before.

Fixes #573
This commit is contained in:
dualfroz committed 2026-10-03 01:33:54 +02:00
1 parent ed42ec389b
commit 573bb96204
6 files changed
+139 -5

No files matched your search

+3 -2
View File
@@ -9,9 +9,10 @@
let meta = [];
const resolveImageUrl = (src, pageUrl) => {
if (!src || /^[a-z][a-z0-9+.-]*:/i.test(src) || /^\/\//.test(src) || src.startsWith("/")) return src;
if (!src || /^[a-z][a-z0-9+.-]*:/i.test(src) || /^\/\//.test(src)) return src;
try {
return new URL(src, new URL(pageUrl || "/", "https://p")).pathname;
const url = new URL(src, new URL(pageUrl || "/", "https://p"));
return url.origin === "https://p" ? url.pathname + url.search + url.hash : url.href;
} catch {
return src;
}