Fix sitemap generation for docs content (#220)
This commit is contained in:
parent
0e75e07660
commit
d23b4eebfb
@ -10,6 +10,7 @@ const __dirname = dirname(__filename);
|
|||||||
|
|
||||||
const DIST_DIR = join(__dirname, "../dist/client");
|
const DIST_DIR = join(__dirname, "../dist/client");
|
||||||
const GUIDE_CONTENT_DIR = join(__dirname, "../content/guides");
|
const GUIDE_CONTENT_DIR = join(__dirname, "../content/guides");
|
||||||
|
const DOCS_CONTENT_DIR = join(__dirname, "../content/docs");
|
||||||
|
|
||||||
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(/\/+$/, "");
|
||||||
@ -20,12 +21,13 @@ const STATIC_PATHS = [
|
|||||||
"/privacy",
|
"/privacy",
|
||||||
"/terms-and-conditions",
|
"/terms-and-conditions",
|
||||||
"/guides",
|
"/guides",
|
||||||
|
"/docs",
|
||||||
"/features",
|
"/features",
|
||||||
"/features/mcp",
|
"/features/mcp",
|
||||||
...Object.values(FEATURE_PAGE_SLUGS).map((slug) => `/features/${slug}`),
|
...Object.values(FEATURE_PAGE_SLUGS).map((slug) => `/features/${slug}`),
|
||||||
];
|
];
|
||||||
|
|
||||||
function getGuideEntries(dir = GUIDE_CONTENT_DIR, segments = []) {
|
function getContentEntries(contentDir, basePath, dir = contentDir, segments = []) {
|
||||||
if (!existsSync(dir)) {
|
if (!existsSync(dir)) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@ -38,7 +40,10 @@ function getGuideEntries(dir = GUIDE_CONTENT_DIR, segments = []) {
|
|||||||
const entryPath = join(dir, entry.name);
|
const entryPath = join(dir, entry.name);
|
||||||
|
|
||||||
if (entry.isDirectory()) {
|
if (entry.isDirectory()) {
|
||||||
return getGuideEntries(entryPath, [...segments, entry.name]);
|
return getContentEntries(contentDir, basePath, entryPath, [
|
||||||
|
...segments,
|
||||||
|
entry.name,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!entry.isFile() || !/\.(md|mdx)$/i.test(entry.name)) {
|
if (!entry.isFile() || !/\.(md|mdx)$/i.test(entry.name)) {
|
||||||
@ -46,9 +51,14 @@ function getGuideEntries(dir = GUIDE_CONTENT_DIR, segments = []) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const slug = entry.name.replace(/\.(md|mdx)$/i, "");
|
const slug = entry.name.replace(/\.(md|mdx)$/i, "");
|
||||||
|
const pathSegments = slug === "index" ? segments : [...segments, slug];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
path: `/guides/${[...segments, slug].join("/")}`,
|
path:
|
||||||
|
pathSegments.length > 0
|
||||||
|
? `${basePath}/${pathSegments.join("/")}`
|
||||||
|
: basePath,
|
||||||
lastmod: statSync(entryPath).mtime.toISOString(),
|
lastmod: statSync(entryPath).mtime.toISOString(),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@ -72,8 +82,11 @@ function main() {
|
|||||||
for (const path of STATIC_PATHS) {
|
for (const path of STATIC_PATHS) {
|
||||||
entries.set(path, { path, lastmod: null });
|
entries.set(path, { path, lastmod: null });
|
||||||
}
|
}
|
||||||
for (const guide of getGuideEntries()) {
|
for (const entry of [
|
||||||
entries.set(guide.path, guide);
|
...getContentEntries(GUIDE_CONTENT_DIR, "/guides"),
|
||||||
|
...getContentEntries(DOCS_CONTENT_DIR, "/docs"),
|
||||||
|
]) {
|
||||||
|
entries.set(entry.path, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
const sorted = Array.from(entries.values()).sort((a, b) =>
|
const sorted = Array.from(entries.values()).sort((a, b) =>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user