diff --git a/src/components/Map/TemplateMarkerCard.jsx b/src/components/Map/TemplateMarkerCard.jsx index c708464..4fd2d07 100644 --- a/src/components/Map/TemplateMarkerCard.jsx +++ b/src/components/Map/TemplateMarkerCard.jsx @@ -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; +} diff --git a/src/components/Map/markerManager.js b/src/components/Map/markerManager.js index 6455bb9..5cbc5a7 100644 --- a/src/components/Map/markerManager.js +++ b/src/components/Map/markerManager.js @@ -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"); diff --git a/src/components/Map/templateSpecs.js b/src/components/Map/templateSpecs.js index 3285e7d..bca4d04 100644 --- a/src/components/Map/templateSpecs.js +++ b/src/components/Map/templateSpecs.js @@ -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; +}