-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
52 lines (44 loc) · 1.23 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// ------------------------------------
// #EXPRESS - POSTHTML
// ------------------------------------
'use strict'
const fs = require('fs')
const posthtml = require('posthtml')
/**
* @author Michael Ciniawsky (@michael-ciniawsky) <michael.ciniawsky@gmail.com>
* @description PostHTML View Engine for Express
* @license MIT
*
* @module express-posthtml
* @version 1.1.0
*
* @requires posthtml
*
* @method posthtml
*
* @param {String} path View Path
* @param {Object} options View Options
* @param {Function} cb Callback
*
* @return {Function} cb HTML
*/
module.exports = function (path, options, cb) {
options.extend = options.extend || false
let plugins
if (!options.plugins && !options.extend) {
plugins = options.settings['view options'].plugins || []
} else if (options.extend === true) {
plugins = options.settings['view options'].plugins
plugins = plugins.concat(options.plugins)
} else {
plugins = options.plugins || []
}
options = options.settings['view options'].options || {}
fs.readFile(path, 'utf8', (err, html) => {
if (err) return cb(err)
return posthtml(plugins)
.process(html, options)
.then(result => cb(null, result.html))
.catch((err) => cb(err))
})
}