-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoc-gen.js
33 lines (28 loc) · 932 Bytes
/
toc-gen.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
'use strict';
const Toc = require('markdown-toc');
const Fs = require('fs');
const Docs = require('./docs.json')
const internals = {
filename: './DOCS.md'
};
function joinDocs() {
Fs.truncateSync(internals.filename);
for (let i = 0; i < Docs.length; ++i) {
const data = Fs.readFileSync('./docs/' + Docs[i], 'utf8');
Fs.appendFileSync(internals.filename, data)
}
}
internals.generate = function() {
const version = 1;
const api = Fs.readFileSync(internals.filename, 'utf8');
const tocOptions = {
bullets: '-',
slugify: function(text) {
return text.toLowerCase().replace(/\s/g, '-').replace(/[^\w-]/g, '');
}
};
const output = Toc.insert(api, tocOptions).replace(/<!-- version -->(.|\n)*<!-- versionstop -->/, '<!-- version -->\n# SoundCTL API v' + version + ' Documentation\n<!-- versionstop -->');
Fs.writeFileSync(internals.filename, output);
};
joinDocs();
internals.generate();