From 5e818d804d5d38beff0f3754a006333752fd5082 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 22 Apr 2026 16:11:58 +0000 Subject: refactor: update schema handling and improve SEO metadata - Changed schema type from WithContext to Thing[] in Head, BaseLayout, and JsonLd components for better flexibility. - Added optional robots meta tag to Head component. - Updated JSON-LD generation in JsonLd component to include a structured payload. - Enhanced page and blog schemas to support breadcrumb and person schemas for improved SEO. - Introduced new utility schemas for website and person to streamline schema generation. - Refactored existing schemas to align with the new structure and ensure consistency across components. --- src/utils/schemas/blogSchema.ts | 46 +++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 18 deletions(-) (limited to 'src/utils/schemas/blogSchema.ts') 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 => ({ - "@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, + })), + }, + }; +}; -- cgit v1.2.3