aboutsummaryrefslogtreecommitdiff
path: root/src/utils/schemas/blogSchema.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/schemas/blogSchema.ts')
-rw-r--r--src/utils/schemas/blogSchema.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/utils/schemas/blogSchema.ts b/src/utils/schemas/blogSchema.ts
new file mode 100644
index 0000000..77f4632
--- /dev/null
+++ b/src/utils/schemas/blogSchema.ts
@@ -0,0 +1,26 @@
+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",
+ "itemListOrder": "https://schema.org/ItemListOrderDescending",
+ "numberOfItems": posts.length,
+ "itemListElement": posts.map((post, index) => ({
+ "@type": "ListItem",
+ "position": index + 1,
+ "url": new URL(`/blog/${post.slug}`, siteUrl).toString(),
+ "name": post.data.title,
+ })),
+ },
+});