-
Notifications
You must be signed in to change notification settings - Fork 293
Expand file tree
/
Copy pathnext-sitemap.config.js
More file actions
80 lines (75 loc) · 3.03 KB
/
Copy pathnext-sitemap.config.js
File metadata and controls
80 lines (75 loc) · 3.03 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
// Generated by scripts/generate-sitemap-excludes.js (runs during prebuild).
// Contains paths with noindex:true or a canonical pointing to a different URL.
let sitemapExcludes = [];
try {
sitemapExcludes = require("./.sitemap-excludes.json");
} catch {
// File not yet generated (e.g. first run without prebuild). Silently ignore.
}
// Per-page metadata { loc, lastmod, title, description } for every content
// page — used for additionalPaths so that server-rendered pages (blog,
// changelog, faq, handbook, etc.) that are NOT statically pre-built are still
// included in the sitemap, each with an accurate <lastmod> derived from git.
let allPages = [];
try {
allPages = require("./.sitemap-all-pages.json");
} catch {
// File not yet generated. Silently ignore.
}
const BASE_URL = process.env.CF_PAGES_URL ?? "https://langfuse.com";
// Tolerate the legacy string[] shape in case a stale cache is present.
const pageEntries = allPages.map((p) =>
typeof p === "string" ? { loc: p } : p,
);
const pageByLoc = new Map(pageEntries.map((p) => [p.loc, p]));
// The homepage is not a content page, so it has no frontmatter date. Use the
// most recent content change as a sensible freshness signal for "/".
const latestLastmod = pageEntries.reduce((max, p) => {
if (!p.lastmod) return max;
return !max || Date.parse(p.lastmod) > Date.parse(max) ? p.lastmod : max;
}, undefined);
/** @type {import('next-sitemap').IConfig} */
module.exports = {
siteUrl: BASE_URL,
generateRobotsTxt: true,
changefreq: "daily",
// Never emit build-time timestamps. With autoLastmod, next-sitemap stamps
// every page with `new Date()` on each build, making all <lastmod> values
// identical and useless as a freshness signal for search engines and AI
// crawlers. The real per-page lastmod is supplied via additionalPaths below.
autoLastmod: false,
// Provide every content page explicitly so server-rendered pages
// (not statically built) are included. next-sitemap deduplicates: when a page
// is also discovered from the build output, the additionalPaths entry below
// overwrites its fields, so our accurate lastmod wins.
additionalPaths: async () => {
const rootLastmod = pageByLoc.get("/")?.lastmod || latestLastmod;
const entries = [
// Root
{
loc: "/",
priority: 1,
changefreq: "daily",
...(rootLastmod ? { lastmod: rootLastmod } : {}),
},
];
for (const page of pageEntries) {
if (page.loc === "/") continue; // already added above with priority
entries.push({
loc: page.loc,
changefreq: "daily",
...(page.lastmod ? { lastmod: page.lastmod } : {}),
});
}
return entries;
},
exclude: [
// Exclude _meta files and non-content routes
"*/_meta",
// Pages with noindex:true or a canonical override (generated by prebuild script).
// Cookbook duplicate routes are already omitted from allPages.
...sitemapExcludes,
// Exclude API routes for static export
...(process.env.STATIC_EXPORT === "true" ? ["/api/*"] : []),
],
};