Enhance JSON-LD generation for homepage and sitemap by including category data, improving SEO structure and breadcrumb support.
This commit is contained in:
@@ -313,7 +313,8 @@ const renderApp = async (categoryData, socket) => {
|
|||||||
? "index.html"
|
? "index.html"
|
||||||
: "index.prerender.html";
|
: "index.prerender.html";
|
||||||
const homeMetaTags = generateHomepageMetaTags(shopConfig.baseUrl, shopConfig);
|
const homeMetaTags = generateHomepageMetaTags(shopConfig.baseUrl, shopConfig);
|
||||||
const homeJsonLd = generateHomepageJsonLd(shopConfig.baseUrl, shopConfig);
|
const homepageCategories = categoryData ? collectAllCategories(categoryData) : [];
|
||||||
|
const homeJsonLd = generateHomepageJsonLd(shopConfig.baseUrl, shopConfig, homepageCategories);
|
||||||
const combinedHomeMeta = homeMetaTags + "\n" + homeJsonLd;
|
const combinedHomeMeta = homeMetaTags + "\n" + homeJsonLd;
|
||||||
const homeSuccess = render(
|
const homeSuccess = render(
|
||||||
homeComponent,
|
homeComponent,
|
||||||
@@ -385,8 +386,8 @@ const renderApp = async (categoryData, socket) => {
|
|||||||
|
|
||||||
// Special handling for Sitemap page to include category data
|
// Special handling for Sitemap page to include category data
|
||||||
if (page.filename === "sitemap" && categoryData) {
|
if (page.filename === "sitemap" && categoryData) {
|
||||||
const allCategories = collectAllCategories(categoryData);
|
const sitemapCategories = collectAllCategories(categoryData);
|
||||||
metaTags = generateSitemapJsonLd(allCategories, shopConfig.baseUrl, shopConfig);
|
metaTags = generateSitemapJsonLd(sitemapCategories, shopConfig.baseUrl, shopConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special handling for Konfigurator page to include SEO tags
|
// Special handling for Konfigurator page to include SEO tags
|
||||||
|
|||||||
@@ -196,9 +196,9 @@ const generateHomepageMetaTags = (baseUrl, config) => {
|
|||||||
`;
|
`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const generateHomepageJsonLd = (baseUrl, config) => {
|
const generateHomepageJsonLd = (baseUrl, config, categories = []) => {
|
||||||
|
|
||||||
const jsonLd = {
|
const websiteJsonLd = {
|
||||||
"@context": "https://schema.org/",
|
"@context": "https://schema.org/",
|
||||||
"@type": "WebSite",
|
"@type": "WebSite",
|
||||||
name: config.brandName,
|
name: config.brandName,
|
||||||
@@ -232,9 +232,27 @@ const generateHomepageJsonLd = (baseUrl, config) => {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
return `<script type="application/ld+json">${JSON.stringify(
|
// Generate BreadcrumbList for all categories
|
||||||
jsonLd
|
const breadcrumbJsonLd = {
|
||||||
)}</script>`;
|
"@context": "https://schema.org",
|
||||||
|
"@type": "BreadcrumbList",
|
||||||
|
"itemListElement": categories
|
||||||
|
.filter(category => category.seoName) // Only include categories with seoName
|
||||||
|
.map((category, index) => ({
|
||||||
|
"@type": "ListItem",
|
||||||
|
"position": index + 1,
|
||||||
|
"name": category.name,
|
||||||
|
"item": `${baseUrl}/Kategorie/${category.seoName}`
|
||||||
|
}))
|
||||||
|
};
|
||||||
|
|
||||||
|
// Return both JSON-LD scripts
|
||||||
|
const websiteScript = `<script type="application/ld+json">${JSON.stringify(websiteJsonLd)}</script>`;
|
||||||
|
const breadcrumbScript = categories.length > 0
|
||||||
|
? `<script type="application/ld+json">${JSON.stringify(breadcrumbJsonLd)}</script>`
|
||||||
|
: '';
|
||||||
|
|
||||||
|
return websiteScript + (breadcrumbScript ? '\n' + breadcrumbScript : '');
|
||||||
};
|
};
|
||||||
|
|
||||||
const generateSitemapJsonLd = (allCategories = [], baseUrl, config) => {
|
const generateSitemapJsonLd = (allCategories = [], baseUrl, config) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user