Skip to content

Commit c72bdb7

Browse files
authored
Merge pull request #210 from Nextjs-ja-translation/feature/listup-script
Feature: add list up all document markdown script
2 parents 02c02ce + 43f423e commit c72bdb7

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

scripts/listup-mainstream-docs.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const fetch = require('node-fetch');
2+
3+
const organization = 'vercel';
4+
const repository = 'next.js';
5+
const basePath = 'docs';
6+
7+
const auth = { Accept: 'application/vnd.github.v3+json' };
8+
9+
const githubURL = `https://api.github.com/repos/${organization}/${repository}/contents/${basePath}`;
10+
11+
const getAllFilesInRepository = async function (githubURL) {
12+
const res = await fetch(githubURL, { method: 'GET', headers: auth });
13+
const data = await res.json();
14+
15+
return (
16+
await Promise.all(
17+
data.map(async ({ path, name, type, html_url }) => {
18+
if (type === 'dir') {
19+
return await getAllFilesInRepository(`${githubURL}/${name}`);
20+
}
21+
22+
return {
23+
name: path,
24+
url: html_url
25+
};
26+
})
27+
)
28+
).flat();
29+
};
30+
31+
(async () => {
32+
const files = await getAllFilesInRepository(githubURL);
33+
34+
console.log(`${files.map(file => `- [ ] [${file.name}](${file.url})`).join('\n')}`);
35+
})();

0 commit comments

Comments
 (0)