返回 CodeWhale
sitemap.ts
根目录 / web / app / sitemap.ts
1 import type { MetadataRoute } from "next";
2 import { DOC_TOPICS } from "@/lib/docs-map";
3 import { contentLocalesForPath } from "@/lib/i18n/content-locales";
4 import { SITE_URL } from "@/lib/page-meta";
5 import { REDIRECTED_ROUTES } from "@/lib/route-redirects";
6
7 const PATHS = ["", "/app", "/computer-use", "/docs", "/faq", "/changelog", "/contribute", "/ratatui", "/legal/terms", "/legal/privacy"];
8
9 function buildTime(): Date {
10 const committed = Date.parse(process.env.NEXT_PUBLIC_CODEWHALE_SOURCE_COMMITTED_AT ?? "");
11 return new Date(Number.isFinite(committed) ? committed : Date.now());
12 }
13
14 export default function sitemap(): MetadataRoute.Sitemap {
15 const lastModified = buildTime();
16 const docsPaths = DOC_TOPICS
17 .filter((topic) => topic.hasPage)
18 .map((topic) => topic.sitePath ? `/${topic.sitePath}` : `/docs/${topic.slug}`);
19 const paths = [...new Set([...PATHS, ...docsPaths])]
20 .filter((path) => !REDIRECTED_ROUTES.includes(path.split("/")[1] ?? ""));
21 return paths.flatMap((path) =>
22 contentLocalesForPath(path || "/").map((locale) => ({
23 url: `${SITE_URL}/${locale}${path}`,
24 lastModified,
25 alternates: {
26 languages: Object.fromEntries(
27 contentLocalesForPath(path || "/").map((l) => [
28 l,
29 `${SITE_URL}/${l}${path}`,
30 ]),
31 ),
32 },
33 })),
34 );
35 }
36
36 lines TYPESCRIPT