* docs: create a new UI docs project (#13233) * docs: create a new UI docs project * fix installation errors * docs: migrate UI docs content to new project (#13241) * Fix content * added examples for some components * finish adding examples * lint fix * fix build errors * delete empty files * path fixes + refactor * fix build error
41 lines
930 B
TypeScript
41 lines
930 B
TypeScript
import { readdirSync } from "fs"
|
|
import path from "path"
|
|
import { getFileSlugSync } from "docs-utils"
|
|
|
|
type Options = {
|
|
basePath: string
|
|
}
|
|
|
|
export function retrieveMdxPages({ basePath }: Options): string[] {
|
|
function retrieveMdxFilesInPath(dir: string): string[] {
|
|
const urls = []
|
|
const files = readdirSync(dir, {
|
|
withFileTypes: true,
|
|
})
|
|
|
|
for (const file of files) {
|
|
const filePath = path.join(dir, file.name)
|
|
if (file.isDirectory()) {
|
|
if (!file.name.startsWith("_")) {
|
|
urls.push(...retrieveMdxFilesInPath(filePath))
|
|
}
|
|
continue
|
|
} else if (file.name !== "page.mdx") {
|
|
continue
|
|
}
|
|
|
|
const slug = getFileSlugSync(filePath)
|
|
|
|
const url = (slug || filePath.replace(basePath, ""))
|
|
.replace(file.name, "")
|
|
.replace(/\/$/, "")
|
|
|
|
urls.push(url)
|
|
}
|
|
|
|
return urls
|
|
}
|
|
|
|
return retrieveMdxFilesInPath(basePath)
|
|
}
|