-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerateDocsMeta.ts
More file actions
30 lines (25 loc) · 1.03 KB
/
generateDocsMeta.ts
File metadata and controls
30 lines (25 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Generates public/docs/{lang}/{pageId}/sections.yml for each page directory.
// Each sections.yml lists the .md files in that directory in display order.
import { writeFile } from "node:fs/promises";
import { join } from "node:path";
import { getMarkdownSections, getPagesList } from "@/lib/docs";
const docsDir = join(process.cwd(), "public", "docs");
const langEntries = await getPagesList();
const langIdsJson = JSON.stringify(langEntries.map((lang) => lang.id));
await writeFile(join(docsDir, "languages.json"), langIdsJson, "utf-8");
console.log(
`Generated languages.json (${langEntries.length} languages: ${langEntries.map((lang) => lang.id).join(", ")})`
);
for (const lang of langEntries) {
for (const page of lang.pages) {
const sections = await getMarkdownSections(lang.id, page.slug);
await writeFile(
join(docsDir, lang.id, page.slug, "sections.json"),
JSON.stringify(sections),
"utf-8"
);
console.log(
`Generated ${lang.id}/${page.slug}/sections.json (${sections.length} files)`
);
}
}