-
Notifications
You must be signed in to change notification settings - Fork 21
/
index.js
43 lines (33 loc) · 1.16 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
var fs = require('fs');
var re = /^```uml((.*\n)+?)?```$/im;
var crypto = require('crypto');
var path = require('path');
require('shelljs/global');
var umlPath, mode;
module.exports = {
hooks: {
"init": function() {
umlPath = path.join(this.options.output, 'assets', 'images', 'uml');
mode = this.options._name;
mkdir('-p', umlPath);
}
, "page:before": function(page) {
var content = page.content;
while((match = re.exec(content))) {
var rawBlock = match[0];
var umlBlock = match[1];
var md5 = crypto.createHash('md5').update(umlBlock).digest('hex');
var umlFile = path.join(umlPath, md5+'.uml');
fs.writeFileSync(umlFile, match[1], 'utf8');
if(0 == exec(['java -jar', this.options.pluginsConfig.plantuml.jarPath, '-tsvg', umlFile, '-o', umlPath].join(' ')).code) {
var svgPath = ('serve' == mode) ? '/assets/images/uml/' : ['file://', umlPath, '/'].join('');
var svgTag = ['![](', svgPath, md5, '.svg)'].join('');
page.content = content = content.replace(rawBlock, svgTag);
}
}
return page;
},
"page": function(page) { return page; },
"page:after": function(page) { return page; }
}
};