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 data = useMemo(() => {
|
||||
const rawImage = post?.image_large || post?.image_small || post?.image || post?.media_url || "";
|
||||
return {
|
||||
headline: post?.title || "Untitled",
|
||||
source: post?.source || (post?.author ? `by ${post.author}` : "") || (post?.sub_category || ""),
|
||||
summary: post?.snippet || post?.body || post?.content || "",
|
||||
url: post?.url || "",
|
||||
image: post?.image_large || post?.image_small || post?.image || post?.media_url || "",
|
||||
image: normalizeImageUrl(rawImage),
|
||||
};
|
||||
}, [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?.media_url ||
|
||||
"";
|
||||
const v = (raw || "").toString().trim();
|
||||
const v = normalizeImageUrl(raw);
|
||||
if (v) return v;
|
||||
const cat = normCatLabel(post);
|
||||
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) {
|
||||
try {
|
||||
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)
|
||||
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");
|
||||
root.classList.add("sw-appear");
|
||||
|
|
|
|||
|
|
@ -268,7 +268,15 @@ export function adaptPostToTemplateData(post) {
|
|||
const summary = post?.snippet || post?.body || "";
|
||||
const url = post?.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);
|
||||
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