Files
MyBlog-Next/src/layouts/PostLayout.astro
T
2026-06-16 12:06:04 +08:00

54 lines
1.6 KiB
Plaintext

---
import Layout from "./Layout.astro";
import config from "@/config";
import TwikooComments from "../components/TwikooComments.astro";
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 commentPath = Astro.url.pathname;
// 结构化数据(保持你原来的实现,此处仅作示例)
const structuredData = {
"@context": "https://schema.org",
"@type": "Article",
headline: title,
description: description,
// ... 其他字段按你的原有逻辑填充
};
---
<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()} />
)}
<script type="application/ld+json" is:inline set:html={JSON.stringify(structuredData)} />
</Fragment>
<!-- 文章主体内容(来自各个 Markdown 文件中的内容) -->
<slot />
<!-- 仅在文章页面显示评论区,并通过插槽放到 footer 之前 -->
{commentPath.startsWith("/posts/") && (
<Fragment slot="after-content">
<div class="mx-auto max-w-2xl px-4 sm:px-6">
<TwikooComments envId="http://47.108.235.131:40063/" path={commentPath} />
</div>
</Fragment>
)}
</Layout>