feat(SW-200): Added noindex property to seo metadata in contentstack and added implementation

This commit is contained in:
Erik Tiekstra
2024-11-15 09:25:54 +01:00
parent 6aba0d8f52
commit 50f285776a
19 changed files with 159 additions and 160 deletions

27
utils/jsonSchemas.ts Normal file
View File

@@ -0,0 +1,27 @@
import { env } from "@/env/server"
import type { BreadcrumbList, ListItem, WithContext } from "schema-dts"
import type { Breadcrumbs } from "@/types/trpc/routers/contentstack/breadcrumbs"
export function generateBreadcrumbsSchema(breadcrumbs: Breadcrumbs) {
const itemListElement: ListItem[] = breadcrumbs.map((item, index) => ({
"@type": "ListItem",
position: index + 1,
name: item.title,
// Only include "item" if "href" exists; otherwise, omit it
...(item.href ? { item: `${env.PUBLIC_URL}${item.href}` } : {}),
}))
const jsonLd: WithContext<BreadcrumbList> = {
"@context": "https://schema.org",
"@type": "BreadcrumbList",
itemListElement,
}
return {
key: "breadcrumbs",
type: "application/ld+json",
jsonLd,
}
}