Skip to content

Commit 7a3bb8f

Browse files
committed
生成されるファイルについてはjsonでよいのでは
1 parent ea22377 commit 7a3bb8f

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

.gitignore

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
/.open-next
44
/cloudflare-env.d.ts
55

6-
# generated docs section file lists (regenerated by npm run generateSections)
7-
/public/docs/**/sections.yml
8-
9-
# generated languages list (regenerated by npm run generateLanguages)
10-
/public/docs/languages.yml
6+
# generated docs section file lists (regenerated by npm run generateDocsMeta)
7+
/public/docs/**/sections.json
8+
/public/docs/languages.json
119

1210
# dependencies
1311
/node_modules

app/lib/docs.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ async function readPublicFile(path: string): Promise<string> {
5959

6060
async function getLanguageIds(): Promise<string[]> {
6161
if (isCloudflare()) {
62-
const raw = await readPublicFile("docs/languages.yml");
63-
return yaml.load(raw) as string[];
62+
const raw = await readPublicFile("docs/languages.json");
63+
return JSON.parse(raw) as string[];
6464
} else {
6565
const docsDir = join(process.cwd(), "public", "docs");
6666
const entries = await readdir(docsDir, { withFileTypes: true });
@@ -95,10 +95,10 @@ export async function getSectionsList(
9595
pageId: string
9696
): Promise<string[]> {
9797
if (isCloudflare()) {
98-
const sectionsYml = await readPublicFile(
99-
`docs/${lang}/${pageId}/sections.yml`
98+
const sectionsJson = await readPublicFile(
99+
`docs/${lang}/${pageId}/sections.json`
100100
);
101-
return yaml.load(sectionsYml) as string[];
101+
return JSON.parse(sectionsJson) as string[];
102102
} else {
103103
function naturalSortMdFiles(a: string, b: string): number {
104104
// -intro.md always comes first

scripts/generateDocsMeta.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,29 @@
33

44
import { writeFile } from "node:fs/promises";
55
import { join } from "node:path";
6-
import yaml from "js-yaml";
76
import { getPagesList, getSectionsList } from "@/lib/docs";
87

98
const docsDir = join(process.cwd(), "public", "docs");
109

1110
const langEntries = await getPagesList();
1211

13-
const yamlContent = yaml.dump(langEntries.map((lang) => lang.id));
14-
await writeFile(join(docsDir, "languages.yml"), yamlContent, "utf-8");
15-
console.log(`Generated languages.yml (${langEntries.length} languages: ${langEntries.map((lang) => lang.id).join(", ")})`);
12+
const langIdsJson = JSON.stringify(langEntries.map((lang) => lang.id));
13+
await writeFile(join(docsDir, "languages.json"), langIdsJson, "utf-8");
14+
console.log(
15+
`Generated languages.json (${langEntries.length} languages: ${langEntries.map((lang) => lang.id).join(", ")})`
16+
);
1617

1718
for (const lang of langEntries) {
1819
for (const page of lang.pages) {
1920
const files = await getSectionsList(lang.id, page.slug);
20-
const yamlContent = yaml.dump(files);
21+
const filesJson = JSON.stringify(files);
2122
await writeFile(
22-
join(docsDir, lang.id, page.slug, "sections.yml"),
23-
yamlContent,
23+
join(docsDir, lang.id, page.slug, "sections.json"),
24+
filesJson,
2425
"utf-8"
2526
);
2627
console.log(
27-
`Generated ${lang.id}/${page.slug}/sections.yml (${files.length} files)`
28+
`Generated ${lang.id}/${page.slug}/sections.json (${files.length} files)`
2829
);
2930
}
3031
}
31-

0 commit comments

Comments
 (0)