forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsitemap.ts
More file actions
115 lines (103 loc) · 4.1 KB
/
Copy pathsitemap.ts
File metadata and controls
115 lines (103 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Next.js App Router sitemap. Emits one entry per (root URL, framework
// variant) pair so search engines can crawl every framework-scoped doc
// at its self-canonical URL.
//
// The expansion is:
// - Root URL (/)
// - Bare unscoped pages (/<slug>) from src/content/docs/**.mdx
// - Framework-scoped pages (/<fw>/<slug>) bare slugs × every registered
// integration, plus per-framework
// override pages under
// src/content/docs/integrations/
// - Reference (/reference/<slug>) from src/content/reference/
// - AG-UI (/ag-ui/<slug>) from src/content/ag-ui/
//
// Each entry's `lastModified` is resolved via resolveLastModified —
// frontmatter `lastmod` first, then file mtime, then `new Date()`.
import type { MetadataRoute } from "next";
import {
getAgUiPages,
getBareDocsPages,
getBaseUrl,
getFrameworkOverridePages,
getReferencePages,
resolveLastModified,
} from "@/lib/sitemap-helpers";
import { getDocsFolder, getIntegrations } from "@/lib/registry";
// Force-dynamic so the sitemap is regenerated per request and reads
// the LIVE NEXT_PUBLIC_BASE_URL via getRuntimeConfig(). Without this
// Next.js would statically prerender the sitemap at build time and
// freeze whichever value `process.env.NEXT_PUBLIC_BASE_URL` had at
// `next build` — defeating the runtime-config switch.
export const dynamic = "force-dynamic";
export default function sitemap(): MetadataRoute.Sitemap {
const baseUrl = getBaseUrl();
const now = new Date();
const entries: MetadataRoute.Sitemap = [];
// 1. Root / overview.
entries.push({
url: `${baseUrl}/`,
lastModified: now,
});
// 2. Bare unscoped docs and 3. framework-scoped variants. Each bare
// slug generates one bare entry plus N framework-scoped entries — one
// per registered integration. Per-framework override pages are added
// alongside (deduped against the bare × framework cross-product).
const bareDocs = getBareDocsPages();
const integrations = getIntegrations();
// Track every framework-scoped URL we've already emitted so the
// override loop below can skip duplicates without scanning the array.
const seenFrameworkUrls = new Set<string>();
for (const { slug, filePath } of bareDocs) {
const lastModified = resolveLastModified(filePath);
entries.push({
url: `${baseUrl}/${slug}`,
lastModified,
});
for (const integration of integrations) {
const url = `${baseUrl}/${integration.slug}/${slug}`;
seenFrameworkUrls.add(url);
entries.push({ url, lastModified });
}
}
// Framework landing pages: /<framework> on its own.
for (const integration of integrations) {
const url = `${baseUrl}/${integration.slug}`;
seenFrameworkUrls.add(url);
entries.push({ url, lastModified: now });
}
// Per-framework override pages — topics that only exist under
// integrations/<folder>/. These are addressable as /<framework>/<slug>
// and aren't covered by the bare × framework cross-product above.
for (const integration of integrations) {
const folder = getDocsFolder(integration.slug);
for (const { slug, filePath } of getFrameworkOverridePages(folder)) {
const url = `${baseUrl}/${integration.slug}/${slug}`;
if (seenFrameworkUrls.has(url)) continue;
seenFrameworkUrls.add(url);
entries.push({
url,
lastModified: resolveLastModified(filePath),
});
}
}
// 4. Reference docs.
for (const { slug, filePath } of getReferencePages()) {
entries.push({
url: `${baseUrl}/reference/${slug}`,
lastModified: resolveLastModified(filePath),
});
}
// Reference index.
entries.push({ url: `${baseUrl}/reference`, lastModified: now });
// 5. AG-UI.
for (const { slug, filePath } of getAgUiPages()) {
entries.push({
url: `${baseUrl}/ag-ui/${slug}`,
lastModified: resolveLastModified(filePath),
});
}
// AG-UI overview landing.
entries.push({ url: `${baseUrl}/ag-ui`, lastModified: now });
return entries;
}