-
Notifications
You must be signed in to change notification settings - Fork 135
/
index.js
executable file
·54 lines (45 loc) · 1.7 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
49
50
51
52
53
54
const Handlebars = require('handlebars');
const { readFileSync, readdirSync } = require('fs');
const { join } = require('path');
const HELPERS = join(__dirname, 'theme/hbs-helpers');
const { birthDate } = require(join(HELPERS, 'birth-date.js'));
const { dateHelpers } = require(join(HELPERS, 'date-helpers.js'));
const { paragraphSplit } = require(join(HELPERS, 'paragraph-split.js'));
const { toLowerCase } = require(join(HELPERS, 'to-lower-case.js'));
const { spaceToDash } = require(join(HELPERS, 'space-to-dash.js'));
const { MY, Y, DMY } = dateHelpers;
Handlebars.registerHelper('birthDate', birthDate);
Handlebars.registerHelper('MY', MY);
Handlebars.registerHelper('Y', Y);
Handlebars.registerHelper('DMY', DMY);
Handlebars.registerHelper('paragraphSplit', paragraphSplit);
Handlebars.registerHelper('toLowerCase', toLowerCase);
Handlebars.registerHelper('spaceToDash', spaceToDash);
function render(resume) {
const css = readFileSync(`${__dirname}/style.css`, 'utf-8');
const tpl = readFileSync(`${__dirname}/resume.hbs`, 'utf-8');
const partialsDir = join(__dirname, 'theme/partials');
const filenames = readdirSync(partialsDir);
filenames.forEach((filename) => {
const matches = /^([^.]+).hbs$/.exec(filename);
if (!matches) return;
const name = matches[1];
const filepath = join(partialsDir, filename);
const template = readFileSync(filepath, 'utf8');
Handlebars.registerPartial(name, template);
});
return Handlebars.compile(tpl)({
css,
resume,
});
}
const marginValue = '0.8 cm';
const pdfRenderOptions = {
margin: {
top: marginValue,
bottom: marginValue,
left: marginValue,
right: marginValue,
}
}
module.exports = { render, pdfRenderOptions };