Normalize map image URLs
This commit is contained in:
parent
8fa842ecb7
commit
c4b7f6cb90
|
|
@ -17,12 +17,13 @@ export default function TemplateMarkerCard({
|
||||||
const spec = mode === "mini" ? template?.mini_spec_json : template?.full_spec_json;
|
const spec = mode === "mini" ? template?.mini_spec_json : template?.full_spec_json;
|
||||||
|
|
||||||
const data = useMemo(() => {
|
const data = useMemo(() => {
|
||||||
|
const rawImage = post?.image_large || post?.image_small || post?.image || post?.media_url || "";
|
||||||
return {
|
return {
|
||||||
headline: post?.title || "Untitled",
|
headline: post?.title || "Untitled",
|
||||||
source: post?.source || (post?.author ? `by ${post.author}` : "") || (post?.sub_category || ""),
|
source: post?.source || (post?.author ? `by ${post.author}` : "") || (post?.sub_category || ""),
|
||||||
summary: post?.snippet || post?.body || post?.content || "",
|
summary: post?.snippet || post?.body || post?.content || "",
|
||||||
url: post?.url || "",
|
url: post?.url || "",
|
||||||
image: post?.image_large || post?.image_small || post?.image || post?.media_url || "",
|
image: normalizeImageUrl(rawImage),
|
||||||
};
|
};
|
||||||
}, [post]);
|
}, [post]);
|
||||||
|
|
||||||
|
|
@ -63,3 +64,11 @@ export default function TemplateMarkerCard({
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function normalizeImageUrl(raw) {
|
||||||
|
const value = (raw || "").toString().trim();
|
||||||
|
if (!value) return "";
|
||||||
|
if (value.startsWith("//")) return `https:${value}`;
|
||||||
|
if (value.startsWith("http://")) return `https://${value.slice(7)}`;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -224,7 +224,7 @@ function heroImageForPost(post) {
|
||||||
post?.image ||
|
post?.image ||
|
||||||
post?.media_url ||
|
post?.media_url ||
|
||||||
"";
|
"";
|
||||||
const v = (raw || "").toString().trim();
|
const v = normalizeImageUrl(raw);
|
||||||
if (v) return v;
|
if (v) return v;
|
||||||
const cat = normCatLabel(post);
|
const cat = normCatLabel(post);
|
||||||
return `/og/category?cat=${encodeURIComponent(cat)}`;
|
return `/og/category?cat=${encodeURIComponent(cat)}`;
|
||||||
|
|
@ -249,6 +249,14 @@ function formatRelativeTime(createdAt) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function normalizeImageUrl(raw) {
|
||||||
|
const value = (raw || "").toString().trim();
|
||||||
|
if (!value) return "";
|
||||||
|
if (value.startsWith("//")) return `https:${value}`;
|
||||||
|
if (value.startsWith("http://")) return `https://${value.slice(7)}`;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
function closeCenteredOverlay(map) {
|
function closeCenteredOverlay(map) {
|
||||||
try {
|
try {
|
||||||
const ov = map?.__swCenteredOverlay;
|
const ov = map?.__swCenteredOverlay;
|
||||||
|
|
@ -788,7 +796,9 @@ export function createSimpleMarkerForPost(post, mapRef, markersRef, expandedElRe
|
||||||
|
|
||||||
// Pas d'offset pour les marqueurs simples (ils sont petits)
|
// Pas d'offset pour les marqueurs simples (ils sont petits)
|
||||||
const color = getMarkerColorForCategory(post?.category);
|
const color = getMarkerColorForCategory(post?.category);
|
||||||
const img = post?.image_small || post?.image || post?.image_large || post?.media_url || "";
|
const img = normalizeImageUrl(
|
||||||
|
post?.image_small || post?.image || post?.image_large || post?.media_url || "",
|
||||||
|
);
|
||||||
|
|
||||||
const root = document.createElement("div");
|
const root = document.createElement("div");
|
||||||
root.classList.add("sw-appear");
|
root.classList.add("sw-appear");
|
||||||
|
|
|
||||||
|
|
@ -268,7 +268,15 @@ export function adaptPostToTemplateData(post) {
|
||||||
const summary = post?.snippet || post?.body || "";
|
const summary = post?.snippet || post?.body || "";
|
||||||
const url = post?.url || "";
|
const url = post?.url || "";
|
||||||
const rawImage = post?.image_large || post?.image_small || post?.image || post?.media_url || "";
|
const rawImage = post?.image_large || post?.image_small || post?.image || post?.media_url || "";
|
||||||
const image = rawImage || `/og/category?cat=${encodeURIComponent((post?.category || "NEWS").toString().toUpperCase())}&variant=mini`;
|
const image = normalizeImageUrl(rawImage) || `/og/category?cat=${encodeURIComponent((post?.category || "NEWS").toString().toUpperCase())}&variant=mini`;
|
||||||
const categoryIcon = getCategoryIcon(post);
|
const categoryIcon = getCategoryIcon(post);
|
||||||
return { headline, source, summary, url, image, categoryIcon };
|
return { headline, source, summary, url, image, categoryIcon };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function normalizeImageUrl(raw) {
|
||||||
|
const value = (raw || "").toString().trim();
|
||||||
|
if (!value) return "";
|
||||||
|
if (value.startsWith("//")) return `https:${value}`;
|
||||||
|
if (value.startsWith("http://")) return `https://${value.slice(7)}`;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue