-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
81 lines (66 loc) · 2.13 KB
/
main.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
80
81
var eta = require("eta")
const pretty = require('pretty');
const marked = require("marked");
const utils = require("./src/utils");
var path = require("path")
var renderer = new marked.Renderer();
var config;
var src;
var build;
function highlight(code, language) {
const hljs = require("highlight.js");
const validLanguage = hljs.getLanguage(language) ? language : "plaintext";
return hljs.highlight(validLanguage, code).value;
}
renderer.code = function(code, language) {
return `<pre><code class="language-${language} hljs">${highlight(code,language)}</code></pre>`
}
renderer.table = function(header, body) {
return `<table class="table table-hover">${header}${body}</table>`
}
marked.setOptions({
renderer: renderer,
// highlight: function(code, language) {return highlight(code,language);},
pedantic: false,
gfm: true,
breaks: false,
sanitize: false,
smartLists: true,
smartypants: false,
xhtml: false
});
function parse_md(mdfile) {return marked(utils.read(mdfile));};
let conf_file = process.argv[2];
config = JSON.parse(utils.read(conf_file,'b'));
src = path.resolve(path.dirname(conf_file));
if (!('build' in config)) {
config.build = './public';
}
build = path.resolve(path.join(src, config.build));
utils.mkdir(build);
if (!('assets' in config)) {
config.assets = ['./assets'];
}
config.assets.forEach(asset => {
utils.rcopy(path.join(src,asset),path.join(build,path.basename(asset)));
});
if (!('layouts' in config)) {
config.layouts = './layouts'
}
eta.configure({views: src + '/' + config.layouts});
config.pages.forEach(page => {
page.footer = config.footer
if (!('title' in page)) {
page.title = config.title;
}
if (page.body.indexOf('.md') > -1) {
page.body = parse_md(path.join(src,page.body));
}
if ('navbar' in config) {page.navbar = config.navbar;}
page.websmith_version = utils.version();
let html = eta.render(`<% layout('${page.layout}') %> \n<%~ it.body %>`, page);
// let html = eta.renderFile(src + '/' + page.layout, page);
// let html = eta.render(utils.read(src + '/' + page.layout + '.eta'), page)
let out = path.join(build, page.name)
utils.write(out, pretty(html));
});