Refactor helpers and render function
This commit is contained in:
parent
f6a55bc1db
commit
c94e5ac315
40
index.js
40
index.js
|
@ -1,28 +1,20 @@
|
|||
var fs = require('fs')
|
||||
var Handlebars = require('handlebars')
|
||||
const fs = require('fs')
|
||||
const Handlebars = require('handlebars')
|
||||
|
||||
module.exports = {
|
||||
render: render,
|
||||
}
|
||||
|
||||
function render(resume) {
|
||||
var css = fs.readFileSync(__dirname + '/style.css', 'utf-8')
|
||||
var template = fs.readFileSync(__dirname + '/resume.hbs', 'utf-8')
|
||||
return Handlebars.compile(template)({
|
||||
css: css,
|
||||
resume: resume,
|
||||
})
|
||||
}
|
||||
|
||||
Handlebars.registerHelper('formatDate', function (dateString) {
|
||||
const date = new Date(dateString)
|
||||
return date.toLocaleDateString('en', {
|
||||
Handlebars.registerHelper('formatDate', dateString =>
|
||||
new Date(dateString).toLocaleDateString('en', {
|
||||
month: 'short',
|
||||
year: 'numeric',
|
||||
})
|
||||
})
|
||||
}),
|
||||
)
|
||||
|
||||
Handlebars.registerHelper('join', function (arr, separator) {
|
||||
separator = typeof separator === 'string' ? separator : ', '
|
||||
return arr.join(separator)
|
||||
})
|
||||
Handlebars.registerHelper('join', (arr, separator) =>
|
||||
arr.join(typeof separator === 'string' ? separator : ', '),
|
||||
)
|
||||
|
||||
exports.render = resume => {
|
||||
const template = fs.readFileSync(`${__dirname}/resume.hbs`, 'utf-8')
|
||||
const css = fs.readFileSync(`${__dirname}/style.css`, 'utf-8')
|
||||
|
||||
return Handlebars.compile(template)({ css, resume })
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue