From 17f9a467d7c0f427ae9d1cd579988a26615311c7 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sat, 14 Jun 2025 11:25:17 +0000 Subject: refactor: update blog post date handling and schema - Replaced `pubDate` with `datePublished` in blog post components for consistency. - Updated sorting logic in blog sections to use `datePublished`. - Enhanced blog post schema to include `dateModified` for better structured data representation. - Adjusted various blog markdown files to reflect the new date fields. --- src/pages/404.astro | 1 + src/pages/blog/[...slug].astro | 13 ++++++++----- src/pages/blog/index.astro | 4 ++-- src/pages/index.astro | 1 + 4 files changed, 12 insertions(+), 7 deletions(-) (limited to 'src/pages') diff --git a/src/pages/404.astro b/src/pages/404.astro index 4215a60..072c6e7 100644 --- a/src/pages/404.astro +++ b/src/pages/404.astro @@ -9,6 +9,7 @@ const lang = "en"; const schema = websiteSchema({ siteUrl: new URL("/", Astro.site).toString(), title, + description, }); --- diff --git a/src/pages/blog/[...slug].astro b/src/pages/blog/[...slug].astro index 3cfdf31..deb98ac 100644 --- a/src/pages/blog/[...slug].astro +++ b/src/pages/blog/[...slug].astro @@ -27,15 +27,18 @@ const description = post.data.description; const author = post.data.author; const lang = post.data.lang; -const formattedData = dayjs(post.data.pubDate.toString()).format("MMMM DD, YYYY"); -const data = post.data.pubDate.toISOString(); +const formattedDate = dayjs(post.data.datePublished.toString()).format("MMMM DD, YYYY"); +const datePublished = post.data.datePublished.toISOString(); +const dateModified = post.data.dateModified?.toISOString(); +const slug = post.slug; const schema = blogPostSchema({ siteUrl: new URL("/", Astro.site).toString(), title, description, - slug: post.slug, - datePublished: data, + slug, + datePublished, + dateModified, author, lang, }); @@ -57,7 +60,7 @@ const schema = blogPostSchema({

Posted - + by {author}  •  {remarkPluginFrontmatter.minutesRead} diff --git a/src/pages/blog/index.astro b/src/pages/blog/index.astro index fd8b376..de5a0a9 100644 --- a/src/pages/blog/index.astro +++ b/src/pages/blog/index.astro @@ -10,10 +10,10 @@ const posts = await getCollection("blog", ({ data }) => { return data.draft !== true; }); -posts.sort((a, b) => b.data.pubDate.getTime() - a.data.pubDate.getTime()); +posts.sort((a, b) => b.data.datePublished.getTime() - a.data.datePublished.getTime()); const postsByYear = posts.reduce[]>>((acc, post) => { - const year = post.data.pubDate.getFullYear().toString(); + const year = post.data.datePublished.getFullYear().toString(); if (!acc[year]) { acc[year] = []; } diff --git a/src/pages/index.astro b/src/pages/index.astro index fb52e79..eaa5298 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -12,6 +12,7 @@ const lang = "en"; const schema = websiteSchema({ siteUrl: new URL("/", Astro.site).toString(), title, + description, }); --- -- cgit v1.2.3