| 468 | } |
| 469 | |
| 470 | function collectLocaleFiles(enFiles: Map<string, { relPath: string; content: string }>): FileInfo[] { |
| 471 | const results: FileInfo[] = []; |
| 472 | function walk(dir: string) { |
| 473 | for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { |
| 474 | const full = path.join(dir, entry.name); |
| 475 | if (entry.isDirectory()) walk(full); |
| 476 | else if (entry.isFile() && entry.name.endsWith(".md")) { |
| 477 | const raw = fs.readFileSync(full, "utf8"); |
| 478 | const parsed = matter(raw); |
| 479 | const permalink = parsed.data?.permalink as string | undefined; |
| 480 | if (!permalink) continue; |
| 481 | const enInfo = enFiles.get(permalink); |
| 482 | if (!enInfo) continue; |
| 483 | results.push({ |
| 484 | absPath: full, |
| 485 | relPath: path.relative(localeDir, full), |
| 486 | enRelPath: enInfo.relPath, |
| 487 | permalink, |
| 488 | frontmatter: parsed.data as Record<string, unknown>, |
| 489 | content: parsed.content, |
| 490 | }); |
| 491 | } |
| 492 | } |
| 493 | } |
| 494 | walk(localeDir); |
| 495 | return results; |
| 496 | } |
| 497 | |
| 498 | function collectEnFiles(): Map<string, { relPath: string; content: string }> { |
| 499 | const map = new Map<string, { relPath: string; content: string }>(); |