docs: fix sitemap of ui docs (#11928)

This commit is contained in:
Shahed Nasser
2025-03-21 12:04:18 +02:00
committed by GitHub
parent 4c33586946
commit a3f4560263
3 changed files with 34 additions and 18 deletions

View File

@@ -4,9 +4,13 @@ import { getFileSlugSync } from "docs-utils"
type Options = {
basePath: string
testFileName?: boolean
}
export function retrieveMdxPages({ basePath }: Options): string[] {
export function retrieveMdxPages({
basePath,
testFileName = true,
}: Options): string[] {
function retrieveMdxFilesInPath(dir: string): string[] {
const urls = []
const files = readdirSync(dir, {
@@ -20,19 +24,26 @@ export function retrieveMdxPages({ basePath }: Options): string[] {
urls.push(...retrieveMdxFilesInPath(filePath))
}
continue
} else if (file.name !== "page.mdx") {
} else if (
(testFileName && file.name !== "page.mdx") ||
(!testFileName && !file.name.endsWith(".mdx"))
) {
continue
}
const slug = getFileSlugSync(filePath)
urls.push(
slug ||
filePath
.replace(basePath, "")
.replace(file.name, "")
.replace(/\/$/, "")
)
let url = slug || filePath.replace(basePath, "")
if (testFileName || file.name === "index.mdx") {
url = url.replace(file.name, "")
} else {
url = url.replace(".mdx", "")
}
url = url.replace(/\/$/, "")
urls.push(url)
}
return urls