diff --git a/frontend/app/[locale]/blog/[slug]/PostDetails.tsx b/frontend/app/[locale]/blog/[slug]/PostDetails.tsx index d3be7b4d..80d13ea1 100644 --- a/frontend/app/[locale]/blog/[slug]/PostDetails.tsx +++ b/frontend/app/[locale]/blog/[slug]/PostDetails.tsx @@ -158,6 +158,7 @@ const recommendedQuery = groq` publishedAt, "mainImage": mainImage.asset->url, slug, + "categories": categories[]->title, "author": author->{ "name": coalesce(name[$locale], name[lower($locale)], name.uk, name.en, name.pl, name), "image": image.asset->url @@ -212,55 +213,83 @@ export default async function PostDetails({ ].filter(Boolean) as string[]; const authorMeta = authorMetaParts.join(' · '); const categoryLabel = post.categories?.[0]; - const baseUrl = process.env.NEXT_PUBLIC_SITE_URL; - const postUrl = baseUrl - ? `${baseUrl}/${locale}/blog/${slugParam}` + const categoryDisplay = categoryLabel + ? getCategoryLabel(categoryLabel, t) : null; + const baseUrl = process.env.NEXT_PUBLIC_SITE_URL; + const postUrl = baseUrl ? `${baseUrl}/${locale}/blog/${slugParam}` : null; const blogUrl = baseUrl ? `${baseUrl}/${locale}/blog` : null; const description = plainTextFromPortableText(post.body).slice(0, 160); + const categoryHref = categoryLabel + ? `/blog/category/${categoryLabel + .toLowerCase() + .replace(/[^a-z0-9\\s-]/g, '') + .replace(/\\s+/g, '-')}` + : null; + const categoryUrl = + baseUrl && categoryLabel + ? `${baseUrl}/${locale}/blog/category/${categoryLabel + .toLowerCase() + .replace(/[^a-z0-9\\s-]/g, '') + .replace(/\\s+/g, '-')}` + : null; + const breadcrumbsItems = [ + { + name: tNav('blog'), + href: '/blog', + url: blogUrl, + }, + ...(categoryLabel + ? [ + { + name: categoryDisplay || categoryLabel, + href: categoryHref, + url: categoryUrl, + }, + ] + : []), + { + name: post.title, + href: '', + url: postUrl, + }, + ]; const breadcrumbsJsonLd = blogUrl && postUrl ? { '@context': 'https://schema.org', '@type': 'BreadcrumbList', - itemListElement: [ - { + itemListElement: breadcrumbsItems + .filter(item => item.url) + .map((item, index) => ({ '@type': 'ListItem', - position: 1, - name: tNav('blog'), - item: blogUrl, - }, - { - '@type': 'ListItem', - position: 2, - name: post.title, - item: postUrl, - }, - ], - } - : null; - const articleJsonLd = - postUrl - ? { - '@context': 'https://schema.org', - '@type': 'BlogPosting', - headline: post.title, - description: description || undefined, - mainEntityOfPage: postUrl, - url: postUrl, - datePublished: post.publishedAt || undefined, - author: post.author?.name - ? { - '@type': 'Person', - name: post.author.name, - } - : undefined, - image: post.mainImage ? [post.mainImage] : undefined, + position: index + 1, + name: item.name, + item: item.url, + })), } : null; + const articleJsonLd = postUrl + ? { + '@context': 'https://schema.org', + '@type': 'BlogPosting', + headline: post.title, + description: description || undefined, + mainEntityOfPage: postUrl, + url: postUrl, + datePublished: post.publishedAt || undefined, + author: post.author?.name + ? { + '@type': 'Person', + name: post.author.name, + } + : undefined, + image: post.mainImage ? [post.mainImage] : undefined, + } + : null; return ( -
+
{breadcrumbsJsonLd && (