From 8f04acb50c251ea4c7d2688819141357826bb11c Mon Sep 17 00:00:00 2001 From: mzaxd Date: Sun, 22 Feb 2026 19:24:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9ESEO=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=20(robots.txt,=20sitemap.xml,=20404=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 robots.ts 生成搜索引擎爬虫指令 - 新增 sitemap.ts 动态生成站点地图(含所有项目页面) - 新增自定义 404 页面,支持中英文 - 新增 catchAll 路由捕获未匹配路径 - 更新翻译文件添加 404 页面文案 --- src/app/[locale]/[...catchAll]/page.tsx | 5 +++ src/app/[locale]/not-found.tsx | 32 ++++++++++++++ src/app/robots.ts | 16 +++++++ src/app/sitemap.ts | 55 +++++++++++++++++++++++++ src/messages/en.json | 32 +++++++++++++- src/messages/zh.json | 32 +++++++++++++- 6 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 src/app/[locale]/[...catchAll]/page.tsx create mode 100644 src/app/[locale]/not-found.tsx create mode 100644 src/app/robots.ts create mode 100644 src/app/sitemap.ts diff --git a/src/app/[locale]/[...catchAll]/page.tsx b/src/app/[locale]/[...catchAll]/page.tsx new file mode 100644 index 0000000..19fb7ca --- /dev/null +++ b/src/app/[locale]/[...catchAll]/page.tsx @@ -0,0 +1,5 @@ +import { notFound } from 'next/navigation' + +export default function CatchAllPage() { + notFound() +} diff --git a/src/app/[locale]/not-found.tsx b/src/app/[locale]/not-found.tsx new file mode 100644 index 0000000..a5a8881 --- /dev/null +++ b/src/app/[locale]/not-found.tsx @@ -0,0 +1,32 @@ +import Link from 'next/link' +import { getTranslations } from 'next-intl/server' + +export default async function NotFound() { + const t = await getTranslations('notFound') + + return ( +
+

404

+

+ {t('title')} +

+

+ {t('description')} +

+
+ + {t('backHome')} + + + {t('browseProjects')} + +
+
+ ) +} diff --git a/src/app/robots.ts b/src/app/robots.ts new file mode 100644 index 0000000..e6c45f8 --- /dev/null +++ b/src/app/robots.ts @@ -0,0 +1,16 @@ +import { MetadataRoute } from 'next' + +export default function robots(): MetadataRoute.Robots { + const baseUrl = process.env.NEXT_PUBLIC_SITE_URL || 'https://agentpark.ai' + + return { + rules: [ + { + userAgent: '*', + allow: '/', + disallow: ['/api/', '/private/'], + }, + ], + sitemap: `${baseUrl}/sitemap.xml`, + } +} diff --git a/src/app/sitemap.ts b/src/app/sitemap.ts new file mode 100644 index 0000000..caa12fa --- /dev/null +++ b/src/app/sitemap.ts @@ -0,0 +1,55 @@ +import { MetadataRoute } from 'next' +import { getProjects } from '@/hooks/useProjects' + +export default async function sitemap(): Promise { + const baseUrl = process.env.NEXT_PUBLIC_SITE_URL || 'https://agentpark.ai' + + // 获取所有项目 + const { projects } = await getProjects({ limit: 1000 }) + + // 静态页面 + const staticPages: MetadataRoute.Sitemap = [ + { + url: `${baseUrl}/zh`, + lastModified: new Date(), + changeFrequency: 'daily', + priority: 1, + }, + { + url: `${baseUrl}/en`, + lastModified: new Date(), + changeFrequency: 'daily', + priority: 1, + }, + { + url: `${baseUrl}/zh/projects`, + lastModified: new Date(), + changeFrequency: 'daily', + priority: 0.9, + }, + { + url: `${baseUrl}/en/projects`, + lastModified: new Date(), + changeFrequency: 'daily', + priority: 0.9, + }, + ] + + // 项目详情页(中英文) + const projectPages: MetadataRoute.Sitemap = projects.flatMap((project) => [ + { + url: `${baseUrl}/zh/projects/${project.slug}`, + lastModified: project.updatedAt, + changeFrequency: 'weekly' as const, + priority: 0.8, + }, + { + url: `${baseUrl}/en/projects/${project.slug}`, + lastModified: project.updatedAt, + changeFrequency: 'weekly' as const, + priority: 0.8, + }, + ]) + + return [...staticPages, ...projectPages] +} diff --git a/src/messages/en.json b/src/messages/en.json index cca6d74..d5cf535 100644 --- a/src/messages/en.json +++ b/src/messages/en.json @@ -36,7 +36,31 @@ "browseByTagsSection": "BROWSE BY TAGS", "featuredProjectsSection": "FEATURED PROJECTS", "viewAll": "VIEW ALL", - "viewAllProjects": "VIEW ALL PROJECTS" + "viewAllProjects": "VIEW ALL PROJECTS", + "insightsSection": "Site Overview", + "statsTotalProjects": "Total Projects", + "statsActiveProjects": "Active Projects", + "statsArchivedProjects": "Archived Projects", + "statsTotalTags": "Total Tags", + "statsNewProjects7d": "New in 7 Days", + "rankingsSection": "Project Rankings", + "latestRankingTitle": "Latest Additions", + "starsRankingTitle": "GitHub Stars Ranking", + "window24h": "24H", + "window7d": "7D", + "window30d": "30D", + "noLatestProjects": "No new projects in this time window", + "noStarsProjects": "No stars data available", + "viewAllLatest": "View all latest projects", + "viewAllByStars": "View all by stars", + "tagInsightsSection": "Tag Popularity & Distribution", + "topTagsTitle": "Top Tags", + "categoryDistributionTitle": "Category Distribution", + "tagsUnit": "tags", + "projectsUnit": "projects", + "noTagData": "No tag metrics available", + "recentTimelineSection": "Recent Additions Timeline", + "noTimelineProjects": "No recent additions yet" }, "project": { "backToProjects": "BACK TO PROJECTS", @@ -104,6 +128,12 @@ "about": "About", "submitProject": "SUBMIT PROJECT" }, + "notFound": { + "title": "Page Not Found", + "description": "Sorry, the page you're looking for doesn't exist or has been moved.", + "backHome": "Back to Home", + "browseProjects": "Browse Projects" + }, "layout": { "announcement": "DISCOVER THE FUTURE OF AI AGENTS", "announcementHref": "/projects", diff --git a/src/messages/zh.json b/src/messages/zh.json index 85473fc..70d9b3b 100644 --- a/src/messages/zh.json +++ b/src/messages/zh.json @@ -36,7 +36,31 @@ "browseByTagsSection": "按标签浏览", "featuredProjectsSection": "精选项目", "viewAll": "查看全部", - "viewAllProjects": "查看全部项目" + "viewAllProjects": "查看全部项目", + "insightsSection": "站点概览", + "statsTotalProjects": "项目总数", + "statsActiveProjects": "活跃项目", + "statsArchivedProjects": "归档项目", + "statsTotalTags": "标签总数", + "statsNewProjects7d": "近7天新增", + "rankingsSection": "项目榜单", + "latestRankingTitle": "最新入库榜", + "starsRankingTitle": "GitHub Stars 榜", + "window24h": "24小时", + "window7d": "7天", + "window30d": "30天", + "noLatestProjects": "该时间窗口暂无新增项目", + "noStarsProjects": "暂无可展示的 Stars 数据", + "viewAllLatest": "查看全部最新项目", + "viewAllByStars": "查看全部 Stars 排序", + "tagInsightsSection": "标签热度与分布", + "topTagsTitle": "热门标签", + "categoryDistributionTitle": "分类分布", + "tagsUnit": "个标签", + "projectsUnit": "个项目", + "noTagData": "暂无标签统计数据", + "recentTimelineSection": "最近新增时间线", + "noTimelineProjects": "暂无最近新增项目" }, "project": { "backToProjects": "返回项目列表", @@ -104,6 +128,12 @@ "about": "关于", "submitProject": "提交项目" }, + "notFound": { + "title": "页面未找到", + "description": "抱歉,您访问的页面不存在或已被移除。", + "backHome": "返回首页", + "browseProjects": "浏览项目" + }, "layout": { "announcement": "发现 AI 代理的未来", "announcementHref": "/projects",