-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (27 loc) · 877 Bytes
/
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
const piece = require('gulp-piece')
const ssg = require('gulp-ssg')
const rename = require('gulp-rename')
const tap = require('gulp-tap')
const wrap = require('gulp-wrap')
const matter = require('gulp-front-matter')
const gutil = require('gulp-util')
const MarkdownIt = require('markdown-it')
module.exports = params => {
params = params || {}
params.plugins = params.plugins || []
const md = new MarkdownIt()
params.plugins.forEach(plugin => md.use(plugin))
return piece(
matter({ property: 'data', remove: true }),
tap(file => {
file.contents = new Buffer(md.render(file.contents.toString()))
}),
rename({ extname: '.html' }),
ssg(),
wrap(params.template, params.data, { engine: params.engine })
.on('error', err => gutil.log(
gutil.colors.red('Error (gulp-html-book)'),
err.code,
err.message))
)
}