Refactor JSON-LD generation for homepage to use ItemList instead of BreadcrumbList, enhancing category representation and SEO structure.
This commit is contained in:
@@ -232,27 +232,35 @@ const generateHomepageJsonLd = (baseUrl, config, categories = []) => {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
// Generate BreadcrumbList for all categories
|
// Generate ItemList for all categories (more appropriate for homepage)
|
||||||
const breadcrumbJsonLd = {
|
const categoriesListJsonLd = {
|
||||||
"@context": "https://schema.org",
|
"@context": "https://schema.org",
|
||||||
"@type": "BreadcrumbList",
|
"@type": "ItemList",
|
||||||
|
"name": "Produktkategorien",
|
||||||
|
"description": "Alle verfügbaren Produktkategorien in unserem Online-Shop",
|
||||||
|
"numberOfItems": categories.filter(category => category.seoName).length,
|
||||||
"itemListElement": categories
|
"itemListElement": categories
|
||||||
.filter(category => category.seoName) // Only include categories with seoName
|
.filter(category => category.seoName) // Only include categories with seoName
|
||||||
.map((category, index) => ({
|
.map((category, index) => ({
|
||||||
"@type": "ListItem",
|
"@type": "ListItem",
|
||||||
"position": index + 1,
|
"position": index + 1,
|
||||||
"name": category.name,
|
"name": category.name,
|
||||||
"item": `${baseUrl}/Kategorie/${category.seoName}`
|
"url": `${baseUrl}/Kategorie/${category.seoName}`,
|
||||||
|
"item": {
|
||||||
|
"@type": "Thing",
|
||||||
|
"name": category.name,
|
||||||
|
"url": `${baseUrl}/Kategorie/${category.seoName}`
|
||||||
|
}
|
||||||
}))
|
}))
|
||||||
};
|
};
|
||||||
|
|
||||||
// Return both JSON-LD scripts
|
// Return both JSON-LD scripts
|
||||||
const websiteScript = `<script type="application/ld+json">${JSON.stringify(websiteJsonLd)}</script>`;
|
const websiteScript = `<script type="application/ld+json">${JSON.stringify(websiteJsonLd)}</script>`;
|
||||||
const breadcrumbScript = categories.length > 0
|
const categoriesScript = categories.length > 0
|
||||||
? `<script type="application/ld+json">${JSON.stringify(breadcrumbJsonLd)}</script>`
|
? `<script type="application/ld+json">${JSON.stringify(categoriesListJsonLd)}</script>`
|
||||||
: '';
|
: '';
|
||||||
|
|
||||||
return websiteScript + (breadcrumbScript ? '\n' + breadcrumbScript : '');
|
return websiteScript + (categoriesScript ? '\n' + categoriesScript : '');
|
||||||
};
|
};
|
||||||
|
|
||||||
const generateSitemapJsonLd = (allCategories = [], baseUrl, config) => {
|
const generateSitemapJsonLd = (allCategories = [], baseUrl, config) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user