From 2ced1825702b06c17c1464c0444aa2fad859ae58 Mon Sep 17 00:00:00 2001 From: sebseb7 Date: Sat, 28 Mar 2026 16:30:39 +0100 Subject: [PATCH] refactor: Update JSON-LD generation in generateProductJsonLd function to separate product and breadcrumb scripts for improved SEO structure --- prerender/seo/product.cjs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/prerender/seo/product.cjs b/prerender/seo/product.cjs index dc2e71e..0ef59f5 100644 --- a/prerender/seo/product.cjs +++ b/prerender/seo/product.cjs @@ -86,7 +86,7 @@ const generateProductJsonLd = (product, baseUrl, config, categoryInfo = null) => const priceValidDate = new Date(); priceValidDate.setMonth(priceValidDate.getMonth() + 3); - const jsonLd = { + const productJsonLd = { "@context": "https://schema.org/", "@type": "Product", name: product.name, @@ -150,9 +150,14 @@ const generateProductJsonLd = (product, baseUrl, config, categoryInfo = null) => }, }; - // Add breadcrumb if category information is available + const productScript = ``; + + // BreadcrumbList is not a valid property on Product; emit as its own JSON-LD block (WebPage path context). if (categoryInfo && categoryInfo.name && categoryInfo.seoName) { - jsonLd.breadcrumb = { + const breadcrumbJsonLd = { + "@context": "https://schema.org/", "@type": "BreadcrumbList", itemListElement: [ { @@ -175,11 +180,13 @@ const generateProductJsonLd = (product, baseUrl, config, categoryInfo = null) => }, ], }; + const breadcrumbScript = ``; + return `${productScript}\n${breadcrumbScript}`; } - return ``; + return productScript; }; module.exports = {