forked from yanhaijing/gitbook-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.js
More file actions
27 lines (21 loc) · 712 Bytes
/
build.js
File metadata and controls
27 lines (21 loc) · 712 Bytes
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
/**
* 按照SUMMARY.md 将md文件顺序拼接在一起
*/
var fs = require('fs');
var book = JSON.parse(fs.readFileSync('./book.json').toString());
var summary = fs.readFileSync('./SUMMARY.md').toString();
var output = '# ' + book.title + '\n\n';
var contentArr = summary.match(/\(.*\)/g).map(function (path) {
path = path.slice(1).slice(0, -1);
try {
var res = fs.readFileSync('./' + path).toString();
// pandoc 图片路径修复
res = res.replace('](/img/', '](./img/');
return res;
} catch(e) {
console.log(e.message);
return '';
}
});
output += contentArr.join('\n\n');
fs.writeFileSync(process.env.npm_package_name + '.md', output);