-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
43 lines (28 loc) · 1.1 KB
/
index.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
40
41
42
43
const fs = require('fs-extra');
const glob = require('glob');
const toc = require('markdown-toc');
const data = [];
const top = '[<img width="32" height="32" align="right" src="https://github.githubassets.com/images/icons/emoji/unicode/261d.png" class="emoji" title="TOC">](#readme)';
//------------------------------------------------------------------------------
function start() {
glob.sync('**/*.md', { cwd: `./wiki` }).forEach((file, i) => {
let title = file.replace('.md', '');
if (title != 'Home') {
console.log(title);
data.push(`## [${title.replace(/-/g, ' ')}](../../wiki/${title.replace(/\s/g, '-')}) ${top}`);
data.push(
toc(fs.readFileSync('./wiki/' + file, 'utf8'), {
linkify: function(tok, text, slug, options) {
// update tok.content to how you want it
tok.content = `[${text}](../../wiki/${title}#${slug})`;
return tok;
}
}).content
);
data.push('\n');
}
});
fs.writeFileSync('README.md', data.join('\n'));
}
// Stupid simple … this logic could be way better:
start();