feat(SW-200): Added noindex property to seo metadata in contentstack and added implementation
This commit is contained in:
27
utils/jsonSchemas.ts
Normal file
27
utils/jsonSchemas.ts
Normal 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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user