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/pages/404.astro | 20 +++++++++++-------- src/pages/blog/[...slug].astro | 44 +++++++++++++++++++++++++++++------------- src/pages/blog/index.astro | 20 ++++++++++++++----- src/pages/index.astro | 12 +++++------- 4 files changed, 63 insertions(+), 33 deletions(-) (limited to 'src/pages') diff --git a/src/pages/404.astro b/src/pages/404.astro index 3ec9feb..e76215e 100644 --- a/src/pages/404.astro +++ b/src/pages/404.astro @@ -8,16 +8,20 @@ const description = "The page you're looking for doesn't exist!"; const preview = config.og.defaultPreview; const lang = "en"; -const schema = pageSchema({ - siteUrl: new URL("/", Astro.site).toString(), - page: "/404", - title, - description, - lang, -}); +const siteUrl = new URL("/", Astro.site).toString(); + +const schema = [ + pageSchema({ + siteUrl, + page: "/404", + title, + description, + lang, + }), +]; --- - +

404

Page not found

diff --git a/src/pages/blog/[...slug].astro b/src/pages/blog/[...slug].astro index 3bd2c61..5ba6b3b 100644 --- a/src/pages/blog/[...slug].astro +++ b/src/pages/blog/[...slug].astro @@ -1,9 +1,13 @@ --- import { type CollectionEntry, getCollection, render } from "astro:content"; -import Comments from "../../components/Comments.astro"; -import Layout from "../../layouts/BaseLayout.astro"; import blogPostSchema from "../../utils/schemas/blogPostSchema"; +import breadcrumbSchema from "../../utils/schemas/breadcrumbSchema"; +import Comments from "../../components/Comments.astro"; import dayjs from "dayjs"; +import Layout from "../../layouts/BaseLayout.astro"; +import personSchema from "../../utils/schemas/personSchema"; +import websiteSchema from "../../utils/schemas/websiteSchema"; +import { config } from "../../config"; type Props = CollectionEntry<"blog">; @@ -33,17 +37,31 @@ const dateModified = post.data.dateModified?.toISOString(); const datePublished = post.data.datePublished.toISOString(); const formattedDate = dayjs(post.data.datePublished.toString()).format("MMMM DD, YYYY"); -const schema = blogPostSchema({ - siteUrl: new URL("/", Astro.site).toString(), - dateModified, - datePublished, - description, - isBasedOn, - lang, - preview, - slug, - title, -}); +const siteUrl = new URL("/", Astro.site).toString(); + +const schema = [ + websiteSchema({ siteUrl, name: config.og.website, description, lang }), + personSchema({ siteUrl }), + blogPostSchema({ + siteUrl, + dateModified, + datePublished, + description, + isBasedOn, + lang, + preview, + slug, + title, + }), + breadcrumbSchema({ + siteUrl, + items: [ + { name: "Home", url: "/" }, + { name: "Blog", url: "/blog/" }, + { name: title, url: `/blog/${slug}` }, + ], + }), +]; ---