-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (35 loc) · 1.02 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
import handlebars from 'handlebars';
import fs from 'node:fs';
import path from 'node:path';
import helpers from './theme/helpers/index.js';
/**
* @param {unknown} resume
* @returns string
*/
export function render(resume) {
const css = fs.readFileSync(import.meta.dirname + '/style.css', 'utf-8');
const template = fs.readFileSync(
import.meta.dirname + '/resume.hbs',
'utf-8'
);
const partialsDir = path.join(import.meta.dirname, 'theme', 'partials');
const filenames = fs.readdirSync(partialsDir);
// Register partials
filenames.forEach((filename) => {
const matches = /^([^.]+).hbs$/.exec(filename);
if (!matches) {
return;
}
const name = matches[1];
const filepath = path.join(partialsDir, filename);
const template = fs.readFileSync(filepath, 'utf8');
handlebars.registerPartial(name, template);
});
Object.entries(helpers).forEach(([name, helper]) =>
handlebars.registerHelper(name, helper)
);
return handlebars.compile(template)({
css,
resume,
});
}