diff --git a/src/components/seo/BreadcrumbJsonLd.tsx b/src/components/seo/BreadcrumbJsonLd.tsx new file mode 100644 index 0000000..cba34b2 --- /dev/null +++ b/src/components/seo/BreadcrumbJsonLd.tsx @@ -0,0 +1,39 @@ +import JsonLd from './JsonLd' + +const SITE_URL = process.env.NEXT_PUBLIC_SITE_URL || 'https://example.com' + +interface BreadcrumbItem { + name: string + /** Relative or absolute URL */ + url: string +} + +interface Props { + items: BreadcrumbItem[] +} + +/** + * Renders Schema.org BreadcrumbList structured data. + * Usage: + * + */ +export default function BreadcrumbJsonLd({ items }: Props) { + const data = { + '@context': 'https://schema.org', + '@type': 'BreadcrumbList', + itemListElement: items.map((item, index) => ({ + '@type': 'ListItem', + position: index + 1, + name: item.name, + item: item.url.startsWith('http') + ? item.url + : `${SITE_URL}${item.url}`, + })), + } + + return +}