|
@@ -1,54 +1,54 @@
|
|
|
#!/usr/bin/node
|
|
#!/usr/bin/node
|
|
|
|
|
|
|
|
-const fs = require('fs')
|
|
|
|
|
-const path = require('path')
|
|
|
|
|
-const yaml = require('yaml')
|
|
|
|
|
|
|
+const fs = require("fs");
|
|
|
|
|
+const path = require("path");
|
|
|
|
|
+const yaml = require("yaml");
|
|
|
|
|
|
|
|
-const puppeteer = require('puppeteer')
|
|
|
|
|
-const pug = require('pug')
|
|
|
|
|
|
|
+const puppeteer = require("puppeteer");
|
|
|
|
|
+const pug = require("pug");
|
|
|
|
|
|
|
|
const cv = yaml.parse(fs.readFileSync("./cv.yaml", { encoding: "utf8" }));
|
|
const cv = yaml.parse(fs.readFileSync("./cv.yaml", { encoding: "utf8" }));
|
|
|
|
|
|
|
|
function changeExt(filePath, new_) {
|
|
function changeExt(filePath, new_) {
|
|
|
- parsed = path.parse(filePath)
|
|
|
|
|
- return path.join(parsed.dir, `${path.basename(parsed.name)}.${new_}`)
|
|
|
|
|
|
|
+ parsed = path.parse(filePath);
|
|
|
|
|
+ return path.join(parsed.dir, `${path.basename(parsed.name)}.${new_}`);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function createHtml(pug_file) {
|
|
function createHtml(pug_file) {
|
|
|
- const rendered = pug.renderFile(pug_file, cv)
|
|
|
|
|
- const html_path = changeExt(pug_file, "html")
|
|
|
|
|
-
|
|
|
|
|
- fs.writeFile(html_path, rendered, (err) => {
|
|
|
|
|
- if (err) throw err;
|
|
|
|
|
- })
|
|
|
|
|
- console.log(`Wrote HTML file to ${html_path}`)
|
|
|
|
|
- return html_path
|
|
|
|
|
|
|
+ const rendered = pug.renderFile(pug_file, cv);
|
|
|
|
|
+ const html_path = changeExt(pug_file, "html");
|
|
|
|
|
+
|
|
|
|
|
+ fs.writeFile(html_path, rendered, (err) => {
|
|
|
|
|
+ if (err) throw err;
|
|
|
|
|
+ });
|
|
|
|
|
+ console.log(`Wrote HTML file to ${html_path}`);
|
|
|
|
|
+ return html_path;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async function printPDF(url) {
|
|
async function printPDF(url) {
|
|
|
- const browser = await puppeteer.launch({ headless: "new" });
|
|
|
|
|
- const page = await browser.newPage();
|
|
|
|
|
- await page.goto(url, { waitUntil: 'networkidle0' });
|
|
|
|
|
- const pdf = await page.pdf({ format: 'A4' });
|
|
|
|
|
|
|
+ const browser = await puppeteer.launch({ headless: "new" });
|
|
|
|
|
+ const page = await browser.newPage();
|
|
|
|
|
+ await page.goto(url, { waitUntil: "networkidle0" });
|
|
|
|
|
+ const pdf = await page.pdf({ format: "A4" });
|
|
|
|
|
|
|
|
- await browser.close();
|
|
|
|
|
- return pdf
|
|
|
|
|
|
|
+ await browser.close();
|
|
|
|
|
+ return pdf;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function exportToPdf(htmlFile) {
|
|
function exportToPdf(htmlFile) {
|
|
|
- url = `file://${path.resolve(htmlFile)}`
|
|
|
|
|
- pdf_path = changeExt(htmlFile, "pdf")
|
|
|
|
|
-
|
|
|
|
|
- printPDF(url).then((pdf) => {
|
|
|
|
|
- fs.writeFile(pdf_path, pdf, (err) => {
|
|
|
|
|
- if (err) throw err;
|
|
|
|
|
- })
|
|
|
|
|
- console.log(`Wrote PDF file to ${pdf_path}`)
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ url = `file://${path.resolve(htmlFile)}`;
|
|
|
|
|
+ pdf_path = changeExt(htmlFile, "pdf");
|
|
|
|
|
+
|
|
|
|
|
+ printPDF(url).then((pdf) => {
|
|
|
|
|
+ fs.writeFile(pdf_path, pdf, (err) => {
|
|
|
|
|
+ if (err) throw err;
|
|
|
|
|
+ });
|
|
|
|
|
+ console.log(`Wrote PDF file to ${pdf_path}`);
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-local_pug_path = './resume.pug'
|
|
|
|
|
-local_pdf_path = changeExt(local_pug_path, "pdf")
|
|
|
|
|
|
|
+local_pug_path = "./resume.pug";
|
|
|
|
|
+local_pdf_path = changeExt(local_pug_path, "pdf");
|
|
|
|
|
|
|
|
-local_html_path = createHtml(local_pug_path)
|
|
|
|
|
-exportToPdf(local_html_path)
|
|
|
|
|
|
|
+local_html_path = createHtml(local_pug_path);
|
|
|
|
|
+exportToPdf(local_html_path);
|