2025-06-14 11:01:42 +00:00
|
|
|
import type { WithContext, CollectionPage } from "schema-dts";
|
|
|
|
import type { CollectionEntry } from "astro:content";
|
2025-06-11 23:20:36 +00:00
|
|
|
|
|
|
|
export type BlogSchemaParams = {
|
2025-06-14 11:25:17 +00:00
|
|
|
readonly posts: CollectionEntry<"blog">[];
|
2025-06-11 23:20:36 +00:00
|
|
|
readonly siteUrl: string;
|
|
|
|
readonly title: string;
|
|
|
|
};
|
|
|
|
|
2025-06-14 11:01:42 +00:00
|
|
|
export default ({ siteUrl, title, posts }: BlogSchemaParams): WithContext<CollectionPage> => ({
|
2025-06-11 23:20:36 +00:00
|
|
|
"@context": "https://schema.org",
|
2025-06-14 11:01:42 +00:00
|
|
|
"@type": "CollectionPage",
|
2025-06-11 23:20:36 +00:00
|
|
|
"url": new URL("/blog/", siteUrl).toString(),
|
|
|
|
"name": title,
|
2025-06-14 11:01:42 +00:00
|
|
|
"mainEntity": {
|
|
|
|
"@type": "ItemList",
|
2025-06-14 11:47:17 +00:00
|
|
|
"itemListOrder": "https://schema.org/ItemListOrderDescending",
|
|
|
|
"numberOfItems": posts.length,
|
2025-06-14 11:01:42 +00:00
|
|
|
"itemListElement": posts.map((post, index) => ({
|
|
|
|
"@type": "ListItem",
|
|
|
|
"position": index + 1,
|
|
|
|
"url": new URL(`/blog/${post.slug}`, siteUrl).toString(),
|
|
|
|
"name": post.data.title,
|
|
|
|
})),
|
|
|
|
},
|
2025-06-11 23:20:36 +00:00
|
|
|
});
|