-
Notifications
You must be signed in to change notification settings - Fork 0
/
ejs-cli.js
executable file
·79 lines (62 loc) · 1.66 KB
/
ejs-cli.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env node
// todo: add an option manager like node-optimist.
var ejs = require('ejs');
var fs = require('fs');
var execSync = require('child_process').execSync;
var data = require('./data.js');
var matchers = require('./matchers');
var executor = function(docPath, headPath, footPath) {
var contentPath = docPath;
if (!contentPath) {
console.error('error: no path provided.')
process.exit(1);
}
var frame = contentPath;
var content = fs.readFileSync(contentPath).toString();
var layoutPath = './src/layout.html';
var layout = fs.readFileSync(layoutPath).toString();
var header = '';
var footer = '';
if (headPath) {
header = fs.readFileSync(headPath).toString();
}
if (footPath) {
footer = fs.readFileSync(footPath).toString();
}
var titleMatch = matchers.getTitleFs(contentPath);
var title = '';
if (titleMatch) {
title = titleMatch[1];
}
content = execSync(
`
cat ${contentPath} |
node columnize.js |
pandoc --from=markdown --to=html
`
).toString();
process.stdout.write(ejs.render(layout, {
data: {
styles: data.styles
},
frameContent: content,
filename: 'src/src/',
index: contentPath.match('index.md') ? true : undefined,
header: header,
footer: footer,
title: title,
prefix: process.env.prefix || 'src/',
requestStyle: '',
bodyClass: data.bodyClass({
frame: frame,
singleColumn: matchers.singleColumn(content)
}),
hasCode: matchers.hasCode(content),
notrack: false,
published: true
}));
}
if (!module.parent) {
executor(process.argv[2], process.argv[3], process.argv[4]);
}
module.exports = executor;