Update PostLayout.astro

This commit is contained in:
2026-06-15 23:57:27 +08:00
committed by GitHub
parent a4c7f50e17
commit 9381ea4008
+6 -30
View File
@@ -13,51 +13,27 @@ type Props = {
}; };
const { site } = config; const { site } = config;
const { title, description, ogImage, canonicalURL, pubDatetime, modDatetime } = Astro.props; const { title, description, ogImage, canonicalURL, pubDatetime, modDatetime } = Astro.props;
const commentPath = Astro.url.pathname; const commentPath = Astro.url.pathname;
const structuredData = { 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 }),
},
],
};
--- ---
<Layout {title} {description} {ogImage} {canonicalURL}> <Layout {title} {description} {ogImage} {canonicalURL}>
<Fragment slot="head"> <Fragment slot="head">
<meta property="og:type" content="article" /> <meta property="og:type" content="article" />
{ {pubDatetime && <meta property="article:published_time" content={pubDatetime.toISOString()} />}
pubDatetime && ( {modDatetime && <meta property="article:modified_time" content={modDatetime.toISOString()} />}
<meta property="article:published_time" content={pubDatetime.toISOString()} />
)
}
{
modDatetime && (
<meta property="article:modified_time" content={modDatetime.toISOString()} />
)
}
<script type="application/ld+json" is:inline set:html={JSON.stringify(structuredData)} /> <script type="application/ld+json" is:inline set:html={JSON.stringify(structuredData)} />
</Fragment> </Fragment>
<slot /> <slot />
{ <!-- 评论区:限制宽度,并只对文章页显示 -->
commentPath.startsWith("/posts/") && ( {commentPath.startsWith("/posts/") && (
<div class="mx-auto max-w-2xl"> <div class="mx-auto max-w-2xl">
<TwikooComments envId="http://47.108.235.131:40063/" path={commentPath} /> <TwikooComments envId="http://47.108.235.131:40063/" path={commentPath} />
</div> </div>
) )}
}
</Layout> </Layout>