From 6d11758584e34fdd7f6f2b4290296c33fb37bfb7 Mon Sep 17 00:00:00 2001 From: QihanNX Date: Tue, 16 Jun 2026 17:29:09 +0800 Subject: [PATCH] Update PostLayout.astro --- src/layouts/PostLayout.astro | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/src/layouts/PostLayout.astro b/src/layouts/PostLayout.astro index 83c556d..db3491c 100644 --- a/src/layouts/PostLayout.astro +++ b/src/layouts/PostLayout.astro @@ -3,7 +3,35 @@ import Layout from "./Layout.astro"; import config from "@/config"; import Twikoo from '@/components/Twikoo.astro'; -// ... 前面的 props 和 structuredData 代码保持不变 ... +type Props = { + title?: string; + description?: string; + ogImage?: string; + canonicalURL?: string; + pubDatetime?: Date; + modDatetime?: Date | null; +}; + +const { site } = config; + +const { title, description, ogImage, canonicalURL, pubDatetime, modDatetime } = + Astro.props; + +const structuredData = { + "@context": "https://schema.org", + "@type": "BlogPosting", + headline: title ?? site.title, + image: ogImage, + ...(pubDatetime && { datePublished: pubDatetime.toISOString() }), + ...(modDatetime && { dateModified: modDatetime.toISOString() }), + author: [ + { + "@type": "Person", + name: site.author, + ...(site.profile && { url: site.profile }), + }, + ], +}; --- @@ -14,10 +42,8 @@ import Twikoo from '@/components/Twikoo.astro';