Ajout du schema JSON-LD BreadcrumbList sur les pages internes
Fil d'Ariane automatique basé sur le pathname : Accueil → Section → Sous-page. Adapté aux 3 langues (Accueil/Home/الرئيسية). Absent sur les pages d'accueil.
This commit is contained in:
parent
d44f190845
commit
a12f0880bf
1 changed files with 36 additions and 0 deletions
|
|
@ -92,6 +92,37 @@ const articleJsonLd =
|
|||
}
|
||||
: null;
|
||||
|
||||
// BreadcrumbList JSON-LD (all pages except home)
|
||||
const breadcrumbJsonLd = !isHomePage
|
||||
? (() => {
|
||||
const segments = pathname.split("/").filter(Boolean);
|
||||
// Build cumulative paths: /en/code → [{name: "Home", url: /en}, {name: "Code", url: /en/code}]
|
||||
const homeUrl = locale === "fr" ? "/" : `/${locale}`;
|
||||
const homeName = locale === "ar" ? "الرئيسية" : locale === "en" ? "Home" : "Accueil";
|
||||
const items = [{ name: homeName, url: new URL(homeUrl, siteUrl).href }];
|
||||
// Skip locale prefix for building readable names
|
||||
const startIdx = locale !== "fr" ? 1 : 0;
|
||||
let cumulativePath = locale !== "fr" ? `/${locale}` : "";
|
||||
for (let i = startIdx; i < segments.length; i++) {
|
||||
cumulativePath += `/${segments[i]}`;
|
||||
const name = decodeURIComponent(segments[i])
|
||||
.replace(/-/g, " ")
|
||||
.replace(/^\w/, (c) => c.toUpperCase());
|
||||
items.push({ name, url: new URL(cumulativePath, siteUrl).href });
|
||||
}
|
||||
return {
|
||||
"@context": "https://schema.org",
|
||||
"@type": "BreadcrumbList",
|
||||
itemListElement: items.map((item, i) => ({
|
||||
"@type": "ListItem",
|
||||
position: i + 1,
|
||||
name: item.name,
|
||||
item: item.url,
|
||||
})),
|
||||
};
|
||||
})()
|
||||
: null;
|
||||
|
||||
// WebSite JSON-LD (only on home pages)
|
||||
const websiteJsonLd = isHomePage
|
||||
? {
|
||||
|
|
@ -150,6 +181,11 @@ const websiteJsonLd = isHomePage
|
|||
<script type="application/ld+json" set:html={JSON.stringify(articleJsonLd)} />
|
||||
)}
|
||||
|
||||
<!-- JSON-LD BreadcrumbList (inner pages only) -->
|
||||
{breadcrumbJsonLd && (
|
||||
<script type="application/ld+json" set:html={JSON.stringify(breadcrumbJsonLd)} />
|
||||
)}
|
||||
|
||||
<!-- JSON-LD WebSite (home pages only) -->
|
||||
{websiteJsonLd && (
|
||||
<script type="application/ld+json" set:html={JSON.stringify(websiteJsonLd)} />
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue