forked from jsonresume/jsonresume-theme-class
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
96 lines (80 loc) · 1.85 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const fs = require("fs");
const Handlebars = require("handlebars");
const { marked } = require("marked");
/**
* Custom renderer for marked, namely to disable unwanted features.
* We only want to allow basic inline elements, like links, bold, or inline-code.
*
* @type {object}
*/
const renderer = {
heading(text) {
return text;
},
html(html) {
return html;
},
hr() {
return '';
},
list(body) {
return body;
},
listitem(text) {
return text;
},
br() {
return '';
},
paragraph(text) {
return text;
}
}
marked.use({ renderer });
Handlebars.registerHelper("date", (body) => {
if (!body) {
return "Present"
}
const date = new Date(body);
const datetime = date.toISOString();
const localeString = date.toLocaleDateString('en-US', {
month: "short",
year: "numeric"
});
return `<time datetime="${datetime}">${localeString}</time>`;
});
Handlebars.registerHelper("markdown", (body) => {
return marked.parse(body);
});
function render(resume) {
const css = fs.readFileSync(__dirname + "/style.css", "utf-8");
const template = fs.readFileSync(__dirname + "/resume.handlebars", "utf-8");
const { profiles } = resume.basics;
if (Array.isArray(profiles)) {
const twitter = profiles.find((profile) => {
return profile.network.toLowerCase().includes('twitter');
});
if (twitter) {
let { username, url } = twitter;
if (!username && url) {
const match = url.match(/https?:\/\/.+?\/([\w]{1,15})/);
if (match.length == 2) {
username = match[1];
}
}
if (username && !username.startsWith('@')) {
username = `@${username}`;
}
resume.custom = {
twitterHandle: username
}
}
}
return Handlebars.compile(template)({
css: css,
resume
});
}
module.exports = {
render: render
};