diff options
Diffstat (limited to 'src/utils/schemas/blogSchema.ts')
| -rw-r--r-- | src/utils/schemas/blogSchema.ts | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/src/utils/schemas/blogSchema.ts b/src/utils/schemas/blogSchema.ts index 196f037..ff3ce65 100644 --- a/src/utils/schemas/blogSchema.ts +++ b/src/utils/schemas/blogSchema.ts @@ -1,26 +1,36 @@ -import type { WithContext, CollectionPage } from "schema-dts"; +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, 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.id}`, siteUrl).toString(), - "name": post.data.title, - })), - }, -}); +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, + })), + }, + }; +}; |
