From 925b144426a9a865e5fd61f8bc05ae0fdac90171 Mon Sep 17 00:00:00 2001 From: Han <1655466387@qq.com> Date: Thu, 20 Feb 2025 19:04:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20SEO=20=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E5=8C=96=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Head.astro | 26 +++++++++++++++++--------- src/layouts/Layout.astro | 7 +++---- src/pages/article/[...article].astro | 5 ++++- src/utils/getCover.ts | 3 ++- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/components/Head.astro b/src/components/Head.astro index f8c8fd2..ebe96fc 100644 --- a/src/components/Head.astro +++ b/src/components/Head.astro @@ -3,8 +3,14 @@ import SITE_CONFIG from "../config"; // 当前页面的 URL 元地址 const canonicalURL = new URL(Astro.url.pathname, Astro.site); // 页面内容的元数据 -const { Title: title, Keywords, Description } = Astro.props; -const { Site, Title, Subtitle, Author, Cover, DNSOptimization } = SITE_CONFIG; +const { Title, Keywords, Description, PageCover } = Astro.props; +const { Site, Title: SiteName, Subtitle, Author, Cover, DNSOptimization } = SITE_CONFIG; +const WebTitle = Title || SiteName; +const SiteCover = Site + Cover; +const WebCover = PageCover || SiteCover; +// Schema.org 结构化数据(JSON-LD) +const WebSiteData = { "@context": "https://schema.org", "@type": "WebSite", name: WebTitle, url: canonicalURL, image: { "@type": "ImageObject", url: SiteCover } }; +const ArticleData = { "@context": "https://schema.org", "@type": "BlogPosting", mainEntityOfPage: { "@type": "WebPage", "@id": canonicalURL.href }, headline: WebTitle, image: [WebCover], author: { "@type": "Person", name: Author, url: Site }, publisher: { "@type": "Organization", name: SiteName, logo: { "@type": "ImageObject", url: SiteCover } } }; // 基础 样式 import "../styles/Base.less"; --- @@ -14,12 +20,12 @@ import "../styles/Base.less"; - {title ? `${title} | ${Title}` : `${Title} - ${Subtitle}`} + {Title ? `${Title} | ${SiteName}` : `${SiteName} - ${Subtitle}`} - + @@ -27,18 +33,20 @@ import "../styles/Base.less"; - + - + - + - + - + + +