docs: fix sitemap of ui docs (#11928)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user