-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake-zine.js
38 lines (31 loc) · 1.18 KB
/
make-zine.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
const fs = require('fs');
const path = require('path');
const handlebars = require('handlebars');
const pdf = require('html-pdf');
const issueName = process.argv.slice(2);
const jsonFileName = `./${issueName}.json`;
const issueData = require(`./issues/${issueName}.json`);
createHTML('layout', issueData, `./output/${issueName}.html`);
function createHTML(templateName, data, outputFileName, type) {
var html = renderFromExternalTemplate(templateName, data);
writeFile(html);
}
function renderFromExternalTemplate(templateName, data) {
var templateFile = fs.readFileSync(path.join('templates', templateName + ".hbs"), "utf8");
var css = fs.readFileSync(path.join('templates', templateName + ".css"), "utf8");
var templateFile = templateFile.replace("{{insert-css}}",css);
console.log(templateFile);
var template = handlebars.compile(templateFile);
return template(data);
}
function writeFile(html){
fs.writeFileSync(`./output/${issueName}.html`, html);
var options = {
"format": "Letter",
"orientation": "portrait"
};
pdf.create(html, options).toFile(`./output/${issueName}.pdf`, function(err, res) {
if (err) return console.log(err);
console.log(res);
});
}