mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 07:33:07 +08:00
Update PostLayout.astro
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
import Layout from "./Layout.astro";
|
import Layout from "./Layout.astro";
|
||||||
import config from "@/config";
|
import config from "@/config";
|
||||||
import TwikooComments from "../components/TwikooComments.astro";
|
import Twikoo from '@/components/Twikoo.astro';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
title?: string;
|
title?: string;
|
||||||
@@ -13,41 +13,58 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const { site } = config;
|
const { site } = config;
|
||||||
const { title, description, ogImage, canonicalURL, pubDatetime, modDatetime } = Astro.props;
|
|
||||||
|
|
||||||
const commentPath = Astro.url.pathname;
|
const { title, description, ogImage, canonicalURL, pubDatetime, modDatetime } =
|
||||||
|
Astro.props;
|
||||||
|
|
||||||
// 结构化数据(保持你原来的实现,此处仅作示例)
|
|
||||||
const structuredData = {
|
const structuredData = {
|
||||||
"@context": "https://schema.org",
|
"@context": "https://schema.org",
|
||||||
"@type": "Article",
|
"@type": "BlogPosting",
|
||||||
headline: title,
|
headline: title ?? site.title,
|
||||||
description: description,
|
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">
|
||||||
|
<!-- Override og:type for article pages -->
|
||||||
<meta property="og:type" content="article" />
|
<meta property="og:type" content="article" />
|
||||||
{pubDatetime && (
|
|
||||||
<meta property="article:published_time" content={pubDatetime.toISOString()} />
|
{
|
||||||
)}
|
pubDatetime && (
|
||||||
{modDatetime && (
|
<meta
|
||||||
<meta property="article:modified_time" content={modDatetime.toISOString()} />
|
property="article:published_time"
|
||||||
)}
|
content={pubDatetime.toISOString()}
|
||||||
<script type="application/ld+json" is:inline set:html={JSON.stringify(structuredData)} />
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
{
|
||||||
|
modDatetime && (
|
||||||
|
<meta
|
||||||
|
property="article:modified_time"
|
||||||
|
content={modDatetime.toISOString()}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
<script
|
||||||
|
type="application/ld+json"
|
||||||
|
is:inline
|
||||||
|
set:html={JSON.stringify(structuredData)}
|
||||||
|
/>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
|
|
||||||
<!-- 文章主体内容(来自各个 Markdown 文件中的内容) -->
|
<article>
|
||||||
<slot />
|
<slot />
|
||||||
|
</article>
|
||||||
<!-- 仅在文章页面显示评论区,并通过插槽放到 footer 之前 -->
|
<Twikoo />
|
||||||
{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>
|
</Layout>
|
||||||
|
|||||||
Reference in New Issue
Block a user