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:
1 parent
ed42ec389b
commit
573bb96204
6 files changed
+139
-5
No files matched your search
@@ -10,6 +10,16 @@
|
||||
let non_root_sub_results = [];
|
||||
let has_root_sub_result = false;
|
||||
|
||||
const resolveImageUrl = (src, pageUrl) => {
|
||||
if (!src || /^[a-z][a-z0-9+.-]*:/i.test(src) || /^\/\//.test(src)) return src;
|
||||
try {
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
const thin_sub_results = (results, limit) => {
|
||||
if (results.length <= limit) {
|
||||
return results;
|
||||
@@ -26,6 +36,9 @@
|
||||
const load = async (r) => {
|
||||
data = await r.data();
|
||||
data = process_result?.(data) ?? data;
|
||||
if (data.meta?.image) {
|
||||
data = { ...data, meta: { ...data.meta, image: resolveImageUrl(data.meta.image, data.meta.url || data.url) } };
|
||||
}
|
||||
meta = Object.entries(data.meta).filter(([key]) => !skipMeta.includes(key));
|
||||
if (Array.isArray(data.sub_results)) {
|
||||
has_root_sub_result =
|
||||
|
||||
Reference in new issue
Block a user