-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
74 lines (54 loc) · 1.52 KB
/
build.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
'use strict';
var fs = require('fs');
var glob = require('glob');
var through = require('through2');
var replacestream = require('replacestream');
var marked = require('marked');
var highlight = require('highlight.js');
var options = {
gfm: true,
tables: true,
breaks: true,
highlight: function (code) {
return highlight.highlightAuto(code).value;
}
};
marked.setOptions(options);
var indexContent = [];
fs.createReadStream('README.md')
.pipe(replacestream('.md)', '.html)'))
.pipe(through(function(chunk, enc, callback) {
this.push(chunk);
callback();
}))
.on('data', function(data) {
indexContent.push(data);
})
.on('end', function () {
var md = marked(indexContent.toString());
fs.createReadStream('./template.html')
.pipe(replacestream('{{md}}', md))
.pipe(replacestream('{{path}}', '.'))
.pipe(fs.createWriteStream('index.html'));
});
glob('**/*.md', function (er, files) {
files.forEach(function(file) {
var content = [];
fs.createReadStream(file)
.pipe(replacestream('.md)', '.html)'))
.pipe(through(function(chunk, enc, callback) {
this.push(chunk);
callback();
}))
.on('data', function(data) {
content.push(data);
})
.on('end', function () {
var md = marked(content.toString());
fs.createReadStream('./template.html')
.pipe(replacestream('{{md}}', md))
.pipe(replacestream('{{path}}', '..'))
.pipe(fs.createWriteStream(file.replace('.md', '.html')));
});
});
});