aboutsummaryrefslogtreecommitdiff
path: root/src/utils/schemas/blogSchema.ts
blob: ff3ce651f4fae37a78b7fd346bd1420fc5720240 (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
25
26
27
28
29
30
31
32
33
34
35
36
import type { CollectionPage } from "schema-dts";
import type { CollectionEntry } from "astro:content";
import { websiteId } from "./ids";

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

export default ({ siteUrl, title, description, lang, posts }: BlogSchemaParams): CollectionPage => {
	const url = new URL("/blog/", siteUrl).toString();

	return {
		"@type": "CollectionPage",
		"@id": url,
		"url": url,
		"name": title,
		"description": description,
		"inLanguage": lang,
		"isPartOf": { "@id": websiteId(siteUrl) },
		"mainEntity": {
			"@type": "ItemList",
			"itemListOrder": "https://schema.org/ItemListOrderDescending",
			"numberOfItems": posts.length,
			"itemListElement": posts.map((post, index) => ({
				"@type": "ListItem",
				"position": index + 1,
				"url": new URL(`/blog/${post.id}`, siteUrl).toString(),
				"name": post.data.title,
			})),
		},
	};
};