Skip to content

Open source alternative to Semrush and Ahrefs

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

Ben Senescub97d38149341
diff --git a/web/scripts/generate-sitemap.js b/web/scripts/generate-sitemap.js
index d3da6968..e7ff4028 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 [