2020-07-05 14:54:30 +02:00
|
|
|
const fs = require('fs')
|
2020-07-18 22:44:17 +02:00
|
|
|
const path = require('path')
|
2020-07-05 14:54:30 +02:00
|
|
|
const Handlebars = require('handlebars')
|
2018-09-23 20:28:05 +02:00
|
|
|
|
2020-07-18 22:44:17 +02:00
|
|
|
const extname = '.hbs'
|
|
|
|
const partialsDir = path.join(__dirname, 'partials')
|
|
|
|
|
|
|
|
fs.readdirSync(partialsDir)
|
|
|
|
.filter(filename => path.extname(filename) === extname)
|
|
|
|
.map(filename => [
|
|
|
|
filename,
|
|
|
|
fs.readFileSync(path.join(partialsDir, filename), 'utf8'),
|
|
|
|
])
|
|
|
|
.forEach(([filename, template]) =>
|
|
|
|
Handlebars.registerPartial(path.basename(filename, extname), template),
|
|
|
|
)
|
|
|
|
|
2020-07-05 14:54:30 +02:00
|
|
|
Handlebars.registerHelper('formatDate', dateString =>
|
|
|
|
new Date(dateString).toLocaleDateString('en', {
|
2020-07-05 14:19:26 +02:00
|
|
|
month: 'short',
|
|
|
|
year: 'numeric',
|
2020-07-05 14:54:30 +02:00
|
|
|
}),
|
|
|
|
)
|
2018-09-23 20:28:05 +02:00
|
|
|
|
2020-07-05 14:54:30 +02:00
|
|
|
Handlebars.registerHelper('join', (arr, separator) =>
|
|
|
|
arr.join(typeof separator === 'string' ? separator : ', '),
|
|
|
|
)
|
|
|
|
|
|
|
|
exports.render = resume => {
|
2020-07-18 22:44:17 +02:00
|
|
|
const template = fs.readFileSync(path.join(__dirname, 'resume.hbs'), 'utf-8')
|
|
|
|
const css = fs.readFileSync(path.join(__dirname, 'style.css'), 'utf-8')
|
2020-07-05 14:54:30 +02:00
|
|
|
|
|
|
|
return Handlebars.compile(template)({ css, resume })
|
|
|
|
}
|