-
Notifications
You must be signed in to change notification settings - Fork 81
/
docs.js
59 lines (50 loc) · 1.48 KB
/
docs.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var marked = require('marked');
var fs = require('fs');
// Configs
var configs = {
files: ['index.md', 'getting-started.md', 'components.md'],
pathIn: 'src/docs',
pathOut: './'
};
// Get the header, footer, and nav
var header = fs.readFileSync(`${configs.pathIn}/header.html`, 'utf8');
var footer = fs.readFileSync(`${configs.pathIn}/footer.html`, 'utf8');
var nav = [
{
url: 'getting-started.html',
label: 'Getting Started'
},
{
url: 'components.html',
label: 'Components'
},
{
url: 'https://github.com/cferdinandi/kraken/archive/master.zip',
label: 'Download'
}
];
// Get the navigation menu
var getNav = function (filename) {
return nav.map(function (item) {
if (filename === item.url) return `<li class="text-muted">${item.label}</li>`;
return `<li><a href="${item.url}">${item.label}</a></li>`;
}).join('');
};
// Create the directory path
fs.mkdir(configs.pathOut, { recursive: true }, function (err) {
// If there's an error, throw it
if (err) throw err;
// Loop through each doc and convert to markdown
configs.files.forEach(function (file) {
var filename = file.slice(0, file.length - 3) + '.html';
fs.readFile(`${configs.pathIn}/${file}`, 'utf8', function (err, data) {
if (err) throw err;
var md = marked(data);
var head = header.replace('{{navItems}}', getNav(filename));
fs.writeFile(`${configs.pathOut}/${filename}`, (head + md + footer), function (err){
if (err) throw err;
console.log(`Generated ${filename}`);
});
});
});
});