-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTOC.js
39 lines (36 loc) · 956 Bytes
/
TOC.js
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
31
32
33
34
35
36
37
38
39
const fs = require('fs')
const mdjs = require("@moox/markdown-to-json");
const exclude = [
'.git',
'.github',
'.vscode',
'README.md',
'TOC.js',
'node_modules',
'launch.json',
'package-lock.json',
'package.json',
];
const files = fs.readdirSync('.');
let tocMarkdown = ['# tech-meetings',
''];
files.forEach(file => {
if (exclude.includes(file)) {
return
}
const dirFiles = fs.readdirSync(file);
if (!dirFiles) {
return
}
tocMarkdown.push('## ' + file)
dirFiles.forEach((innerFile) => {
const output = mdjs.markdownAsJsTree(fs.readFileSync(`${file}/${innerFile}`));
if (!output) {
return
}
let data = innerFile.replace('.md', '')
let title = output.title
tocMarkdown.push(`- [${data}](https://github.com/nymedia/tech-meetings/blob/1.x/${file}/${innerFile}): ${title}`)
})
})
console.log(tocMarkdown.join("\n"))