-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (42 loc) · 1.46 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
var processPage = require('./src/main').processPage
var fs = require('fs');
var mkdirp = require('mkdirp');
var path = require('path');
var Promise = require("bluebird");
Promise.promisifyAll(fs);
module.exports = {
hooks: {
init: function() {
var myconfig = this.config.get("pluginsConfig.plantuml");
var outputDir = this.output.root();
var log = this.log;
var config = this.config;
outputDir = '_book'; //test
var outputImagesDir = path.join(outputDir, myconfig.imagesDir);
mkdirp.sync(outputImagesDir);
config.set("pluginsConfig.plantuml.output", outputDir);
config.set("pluginsConfig.plantuml.root", config.get("root"));
// check if imagesDir exists
log.info("checking for "+ path.join(config.get("root"), myconfig.imagesDir) +" existance...");
return fs.statAsync(path.join(config.get("root"), myconfig.imagesDir))
.then(function(){
log.info(" ok.\n");
})
.catch(function(){
log.info(" does not exist, not using image cache.\n");
config.set("pluginsConfig.plantuml.cacheImages", false);
});
},
"page:before": function(page) {
var config = this.config.get("pluginsConfig.plantuml");
return processPage(page.content, page.path, config)
.then(function(content){
page.content = content;
return page;
})
.catch(function(error){
console.error(error);
});
}
}
};