From b4185eb6686e282d6511225955f2a164a1aa9fa9 Mon Sep 17 00:00:00 2001 From: yarnom Date: Mon, 1 Jun 2026 17:22:04 +0800 Subject: [PATCH] Add sitemap and SEO metadata --- frontend/site/src/components/SiteNav.astro | 1 + .../site/src/components/seo/SeoHead.astro | 57 +++++++ frontend/site/src/lib/seo.ts | 21 +++ frontend/site/src/lib/siteConfig.ts | 16 +- frontend/site/src/pages/archive/index.astro | 7 +- frontend/site/src/pages/index.astro | 15 +- frontend/site/src/pages/page/[page].astro | 8 +- frontend/site/src/pages/posts/[slug].astro | 41 ++++- frontend/site/src/pages/robots.txt.ts | 14 ++ frontend/site/src/pages/rss.xml.ts | 3 +- frontend/site/src/pages/site-map.astro | 150 ++++++++++++++++++ frontend/site/src/pages/sitemap.xml.ts | 73 +++++++++ frontend/site/src/pages/tags/[tag].astro | 7 +- frontend/site/src/pages/tags/index.astro | 7 +- 14 files changed, 393 insertions(+), 27 deletions(-) create mode 100644 frontend/site/src/components/seo/SeoHead.astro create mode 100644 frontend/site/src/lib/seo.ts create mode 100644 frontend/site/src/pages/robots.txt.ts create mode 100644 frontend/site/src/pages/site-map.astro create mode 100644 frontend/site/src/pages/sitemap.xml.ts diff --git a/frontend/site/src/components/SiteNav.astro b/frontend/site/src/components/SiteNav.astro index f0c93d4..05d4b4f 100644 --- a/frontend/site/src/components/SiteNav.astro +++ b/frontend/site/src/components/SiteNav.astro @@ -3,6 +3,7 @@ const links = [ { href: '/', label: '首页' }, { href: '/archive/', label: '归档' }, { href: '/tags/', label: '标签' }, + { href: '/site-map/', label: '站点地图' }, { href: '/rss.xml', label: 'RSS' } ]; --- diff --git a/frontend/site/src/components/seo/SeoHead.astro b/frontend/site/src/components/seo/SeoHead.astro new file mode 100644 index 0000000..ae5b21f --- /dev/null +++ b/frontend/site/src/components/seo/SeoHead.astro @@ -0,0 +1,57 @@ +--- +import { site } from '../../lib/siteConfig'; +import { absoluteUrl } from '../../lib/seo'; + +type JsonLd = Record | Record[]; + +type Props = { + title?: string; + description?: string; + path?: string; + type?: 'website' | 'article'; + publishedTime?: string; + modifiedTime?: string; + tags?: string[]; + jsonLd?: JsonLd; +}; + +const { + title = site.title, + description = site.description, + path = '/', + type = 'website', + publishedTime, + modifiedTime, + tags = [], + jsonLd +} = Astro.props; + +const pageTitle = title === site.title ? site.title : `${title} | ${site.title}`; +const canonicalUrl = absoluteUrl(path); +const rssUrl = absoluteUrl('/rss.xml'); +--- + + + +{pageTitle} + + + + + + + + + + + + + +{publishedTime && } +{modifiedTime && } +{tags.map((tag) => )} +{ + jsonLd && ( +