30 lines
625 B
JavaScript
30 lines
625 B
JavaScript
const fs = require("fs");
|
|
const path = require("path");
|
|
const templateFile = path.join(__dirname, "theme/template.html");
|
|
|
|
function replaceTokens(str, data) {
|
|
const tokenRegex = /{(.*?)}/g;
|
|
|
|
str = str.replace(tokenRegex, (match, token) => {
|
|
let value = data;
|
|
|
|
console.log("Token, " , token)
|
|
for (let key of token.split(".")) {
|
|
value = value[key];
|
|
}
|
|
console.log(match, value)
|
|
return value;
|
|
});
|
|
|
|
return str;
|
|
}
|
|
|
|
const render = (resume) => {
|
|
let template = fs.readFileSync(templateFile, { encoding: "utf-8" });
|
|
return replaceTokens(template, resume);
|
|
};
|
|
|
|
module.exports = {
|
|
render,
|
|
};
|