aboutsummaryrefslogtreecommitdiff
path: root/src/utils/schemas/blogSchema.ts
blob: 66a9bae6cc88311276e4a8e1bee8e83fe92ffc76 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import type { WithContext, CollectionPage } from "schema-dts";
import type { CollectionEntry } from "astro:content";

export type BlogSchemaParams = {
	readonly posts: CollectionEntry<"blog">[];
	readonly siteUrl: string;
	readonly title: string;
};

export default ({ siteUrl, title, posts }: BlogSchemaParams): WithContext<CollectionPage> => ({
	"@context": "https://schema.org",
	"@type": "CollectionPage",
	"url": new URL("/blog/", siteUrl).toString(),
	"name": title,
	"mainEntity": {
		"@type": "ItemList",
		"itemListElement": posts.map((post, index) => ({
			"@type": "ListItem",
			"position": index + 1,
			"url": new URL(`/blog/${post.slug}`, siteUrl).toString(),
			"name": post.data.title,
		})),
	},
});