aboutsummaryrefslogtreecommitdiff
path: root/src/utils/schemas/breadcrumbSchema.ts
blob: e1a1ea37292074ecec198550f229c788611f4561 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import type { BreadcrumbList } from "schema-dts";

export type BreadcrumbItem = {
	readonly name: string;
	readonly url: string;
};

export type BreadcrumbSchemaParams = {
	readonly items: BreadcrumbItem[];
	readonly siteUrl: string;
};

export default ({ items, siteUrl }: BreadcrumbSchemaParams): BreadcrumbList => ({
	"@type": "BreadcrumbList",
	"itemListElement": items.map((item, index) => ({
		"@type": "ListItem",
		"position": index + 1,
		"name": item.name,
		"item": new URL(item.url, siteUrl).toString(),
	})),
});