65007c49f6
* docs: support generating sidebar items with tags * small fix * fix dependencies * test * test fix * test fix * test fix * test fix * another fix * revert change * fix for resources
43 lines
952 B
TypeScript
43 lines
952 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)
|
|
|
|
urls.push(
|
|
slug ||
|
|
filePath
|
|
.replace(basePath, "")
|
|
.replace(file.name, "")
|
|
.replace(/\/$/, "")
|
|
)
|
|
}
|
|
|
|
return urls
|
|
}
|
|
|
|
return retrieveMdxFilesInPath(basePath)
|
|
}
|