documents/utils/sidebar.ts
2025-01-25 21:32:34 +08:00

16 lines
No EOL
387 B
TypeScript

import { readdirSync } from "fs"
import path from "path"
export const scanDir = (dirname: string) => {
const dirpath = path.resolve(__dirname, `../${dirname}`)
const res = readdirSync(dirpath)
const markdownFileNames = res.filter((name) => name.endsWith('.md'))
return markdownFileNames.map(v => {
return {
filename: v,
link: path.join(dirpath, v)
}
})
}