-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (36 loc) · 921 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
32
33
34
35
36
37
38
39
40
41
42
43
/**
* Created by kimown on 4/24/16.
*/
"use strict";
var Hexo;
try {
Hexo = require('./../hexo/lib/hexo');
}catch (e){
if(e.code == "MODULE_NOT_FOUND"){
console.error(`Please install hexo first`);
console.error(`You can check the guide: https://hexo.io/`);
} else{
console.error(e);
console.error(`You can contact me via github`);
}
return;
}
var hexo = new Hexo();
var post = hexo.post;
module.exports = function (markdown) {
console.time("COST TIME");
this.cacheable();
var callback = this.async();
hexo.init().then(function() {
return hexo.loadPlugin(require.resolve('hexo-renderer-marked'));
}).then(()=>{
post.render(null, {
content: markdown,
engine: 'markdown'
}).then(function(data) {
console.timeEnd("COST TIME");
var html = data.more;
callback(null,html);
});
})
};