| 48 | |
| 49 | // 扫描目录中的所有 markdown 文件 |
| 50 | function scanMarkdownFiles(dir, basePath = '') { |
| 51 | const files = [] |
| 52 | const entries = fs.readdirSync(dir, { withFileTypes: true }) |
| 53 | |
| 54 | for (const entry of entries) { |
| 55 | const fullPath = path.join(dir, entry.name) |
| 56 | const relativePath = path.join(basePath, entry.name) |
| 57 | |
| 58 | if (entry.isDirectory()) { |
| 59 | // 跳过特殊目录 |
| 60 | if ( |
| 61 | entry.name === '.vitepress' || |
| 62 | entry.name === 'node_modules' || |
| 63 | entry.name === 'dist' || |
| 64 | entry.name === 'public' |
| 65 | ) { |
| 66 | continue |
| 67 | } |
| 68 | files.push(...scanMarkdownFiles(fullPath, relativePath)) |
| 69 | } else if (entry.isFile() && entry.name.endsWith('.md')) { |
| 70 | files.push(relativePath) |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | return files |
| 75 | } |
| 76 | |
| 77 | // 将 markdown 路径转换为 URL 路径 |
| 78 | function mdPathToUrl(mdPath, locale) { |