Update PostLayout.astro

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