From 616b1ad3899ba7a179cd2b80ff317b4c91853102 Mon Sep 17 00:00:00 2001 From: tone Date: Wed, 24 Dec 2025 14:03:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=89=8D=E7=AB=AF=E6=B7=BB=E5=8A=A0rob?= =?UTF-8?q?ots.ts=E5=92=8Csitemap.ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/frontend/app/robots.ts | 12 ++++++++++ apps/frontend/app/sitemap.ts | 45 ++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 apps/frontend/app/robots.ts create mode 100644 apps/frontend/app/sitemap.ts diff --git a/apps/frontend/app/robots.ts b/apps/frontend/app/robots.ts new file mode 100644 index 0000000..5191e70 --- /dev/null +++ b/apps/frontend/app/robots.ts @@ -0,0 +1,12 @@ +import { MetadataRoute } from 'next' + +export default function robots(): MetadataRoute.Robots { + return { + rules: { + userAgent: '*', + allow: '/', + disallow: '/console', + }, + sitemap: 'https://www.tonesc.cn/sitemap.xml', + } +} \ No newline at end of file diff --git a/apps/frontend/app/sitemap.ts b/apps/frontend/app/sitemap.ts new file mode 100644 index 0000000..476aebe --- /dev/null +++ b/apps/frontend/app/sitemap.ts @@ -0,0 +1,45 @@ +import { BlogAPI } from '@/lib/api/server' +import { base62 } from '@/lib/utils' +import { MetadataRoute } from 'next' + +export const revalidate = 3600; + +export default async function sitemap(): Promise { + // 获取所有博客 + const blogs = await BlogAPI.list().catch(() => []) + + const blogUrls = blogs.map(blog => { + const cleanId = blog.id.replace(/-/g, '') + const encoded = base62.encode(Buffer.from(cleanId, 'hex')) + return { + url: `https://www.tonesc.cn/blog/${encoded}`, + lastModified: new Date(blog.updatedAt), + changeFrequency: 'weekly' as const, + priority: 0.8, + } + }) + + // 静态页面 + const staticUrls = [ + { + url: 'https://www.tonesc.cn/', + lastModified: new Date(), + changeFrequency: 'yearly' as const, + priority: 1, + }, + { + url: 'https://www.tonesc.cn/blog', + lastModified: new Date(), + changeFrequency: 'daily' as const, + priority: 0.9, + }, + { + url: 'https://www.tonesc.cn/resource', + lastModified: new Date(), + changeFrequency: 'monthly' as const, + priority: 0.7, + }, + ] + + return [...staticUrls, ...blogUrls] +} \ No newline at end of file