Generate PDF automatically

This commit is contained in:
Anders Englöf Ytterström 2024-10-18 12:41:28 +02:00
parent 0f57a2c305
commit e31c7ef854
6 changed files with 1502 additions and 132 deletions

4
README
View file

@ -1,4 +1,4 @@
1. npm run build or node.index.js 1. npm run build or node index.js
2. copy ./pub to public url 2. copy ./pub to public url
Use "print to PDF" to sync PDF file manually. Use "print to PDF" to sync PDF file manually if needed.

View file

@ -1,6 +1,13 @@
html { html {
font: normal small/1.5 apple-system, system-ui, BlinkMacSystemFont, Segoe UI, font:
Roboto, Helvetica Neue, Arial, sans-serif; normal small/1.5 apple-system,
system-ui,
BlinkMacSystemFont,
Segoe UI,
Roboto,
Helvetica Neue,
Arial,
sans-serif;
background-color: var(--bg-color, #fff); background-color: var(--bg-color, #fff);
color: var(--bg-color, #444); color: var(--bg-color, #444);
} }
@ -31,7 +38,9 @@ figure {
} }
a { a {
color: var(--bg-color, #444); color: var(--bg-color, #444);
transition: background-color 0.3s ease-out, border-bottom-color 0.3s ease-out; transition:
background-color 0.3s ease-out,
border-bottom-color 0.3s ease-out;
} }
p:first-child { p:first-child {
margin-top: 0; margin-top: 0;
@ -229,18 +238,29 @@ the upcoming Container queries was a thing.
} }
@page { @page {
padding: 0; padding: 2cm 0;
margin: 0; margin: 0;
size: A4 portrait; size: A4 portrait;
} }
@media print { @media print {
body { body {
padding: 1cm; padding: 0;
} }
[href$="pdf"] { [href$="pdf"] {
display: none; display: none;
visibility: hidden; visibility: hidden;
} }
a {
border: none !important;
color: #000 !important;
}
.education,
.projects,
.work {
page-break-before: always;
}
} }

View file

@ -4,6 +4,22 @@ var layouts = require("metalsmith-layouts");
var markdown = require("metalsmith-markdown-remarkable"); var markdown = require("metalsmith-markdown-remarkable");
var permalinks = require("@metalsmith/permalinks"); var permalinks = require("@metalsmith/permalinks");
var static = require("metalsmith-static"); var static = require("metalsmith-static");
var puppeteer = require("puppeteer");
var srcHTML = "file:" + __dirname + "/pub/index.html";
var destPDF = "./pub/cv-anders-englof-ytterstrom.pdf";
async function generatePDF() {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(srcHTML, {
waitUntil: "networkidle2",
});
await page.pdf({
path: destPDF,
});
await browser.close();
}
Metalsmith(__dirname) Metalsmith(__dirname)
.source("./src") .source("./src")
@ -31,4 +47,5 @@ Metalsmith(__dirname)
if (err) { if (err) {
throw err; throw err;
} }
generatePDF();
}); });

1334
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -11,6 +11,7 @@
"metalsmith-html-minifier": "^3.0.3", "metalsmith-html-minifier": "^3.0.3",
"metalsmith-layouts": "^1.4.1", "metalsmith-layouts": "^1.4.1",
"metalsmith-markdown-remarkable": "^1.0.2", "metalsmith-markdown-remarkable": "^1.0.2",
"metalsmith-static": "0.0.5" "metalsmith-static": "0.0.5",
"puppeteer": "^23.6.0"
} }
} }