Include /library pages in the sitemap (derived from route files) (#423)

This commit is contained in:
Ben Senescu 2026-07-23 15:20:21 -07:00 committed by GitHub
parent f56972639f
commit b97d381493
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -11,6 +11,7 @@ const __dirname = dirname(__filename);
const DIST_DIR = join(__dirname, "../dist/client"); const DIST_DIR = join(__dirname, "../dist/client");
const BLOG_CONTENT_DIR = join(__dirname, "../content/blogs"); const BLOG_CONTENT_DIR = join(__dirname, "../content/blogs");
const DOCS_CONTENT_DIR = join(__dirname, "../content/docs"); const DOCS_CONTENT_DIR = join(__dirname, "../content/docs");
const LIBRARY_ROUTES_DIR = join(__dirname, "../src/routes/_marketing/library");
const DEFAULT_SITE_URL = "https://openseo.so"; const DEFAULT_SITE_URL = "https://openseo.so";
const SITE_URL = (process.env.SITE_URL ?? DEFAULT_SITE_URL).replace(/\/+$/, ""); const SITE_URL = (process.env.SITE_URL ?? DEFAULT_SITE_URL).replace(/\/+$/, "");
@ -72,6 +73,33 @@ function getContentEntries(
}); });
} }
function getLibraryPaths(dir = LIBRARY_ROUTES_DIR, segments = []) {
if (!existsSync(dir)) {
return [];
}
return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
if (entry.name.startsWith(".")) {
return [];
}
if (entry.isDirectory()) {
return getLibraryPaths(join(dir, entry.name), [...segments, entry.name]);
}
if (!entry.isFile() || !/\.tsx$/i.test(entry.name)) {
return [];
}
const slug = entry.name.replace(/\.tsx$/i, "");
const pathSegments = slug === "index" ? segments : [...segments, slug];
return pathSegments.length > 0
? [`/library/${pathSegments.join("/")}`]
: [];
});
}
function toCanonicalUrl(path) { function toCanonicalUrl(path) {
if (path === "/") { if (path === "/") {
return `${SITE_URL}/`; return `${SITE_URL}/`;
@ -86,7 +114,7 @@ function main() {
} }
const entries = new Map(); const entries = new Map();
for (const path of STATIC_PATHS) { for (const path of [...STATIC_PATHS, ...getLibraryPaths()]) {
entries.set(path, { path, lastmod: null }); entries.set(path, { path, lastmod: null });
} }
for (const entry of [ for (const entry of [