-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
48 lines (39 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
44
45
46
47
48
var fs = require("fs");
var path = require('path');
var Handlebars = require("handlebars");
const H = require('just-handlebars-helpers');
var i18n = require('./i18n.js');
var lang = process.env.LANG.slice(0, 2) || 'zh';
Handlebars.registerHelper('i18n', function (key) {
return i18n[lang][key] || ''
})
Handlebars.registerHelper('lang', function (language, options) {
if (language === lang) {
return options.fn(this)
}
})
// Register just-handlebars-helpers with handlebars
H.registerHelpers(Handlebars);
function render(resume) {
var css = fs.readFileSync(__dirname + "/style.css", "utf-8");
var tpl = fs.readFileSync(__dirname + "/resume.hbs", "utf-8");
var partialsDir = path.join(__dirname, 'partials');
var filenames = fs.readdirSync(partialsDir);
filenames.forEach(function (filename) {
var matches = /^([^.]+).hbs$/.exec(filename);
if (!matches) {
return;
}
var name = matches[1];
var filepath = path.join(partialsDir, filename)
var template = fs.readFileSync(filepath, 'utf8');
Handlebars.registerPartial(name, template);
});
return Handlebars.compile(tpl)({
css: css,
resume: resume
});
}
module.exports = {
render: render
};