From b97d3814934113c4911aaa27fee72c23555cd3d0 Mon Sep 17 00:00:00 2001 From: Ben Senescu <44480372+bensenescu@users.noreply.github.com> Date: Thu, 23 Jul 2026 15:20:21 -0700 Subject: [PATCH] Include /library pages in the sitemap (derived from route files) (#423) --- web/scripts/generate-sitemap.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/web/scripts/generate-sitemap.js b/web/scripts/generate-sitemap.js index d3da696..e7ff402 100644 --- a/web/scripts/generate-sitemap.js +++ b/web/scripts/generate-sitemap.js @@ -11,6 +11,7 @@ const __dirname = dirname(__filename); const DIST_DIR = join(__dirname, "../dist/client"); const BLOG_CONTENT_DIR = join(__dirname, "../content/blogs"); 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 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) { if (path === "/") { return `${SITE_URL}/`; @@ -86,7 +114,7 @@ function main() { } const entries = new Map(); - for (const path of STATIC_PATHS) { + for (const path of [...STATIC_PATHS, ...getLibraryPaths()]) { entries.set(path, { path, lastmod: null }); } for (const entry of [