Created
May 22, 2019 20:15
-
-
Save manuelbieh/26add100b90e76678a463e1299fc47d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const express = require('express'); | |
const puppeteer = require('puppeteer'); | |
const dateTime = require('./lib/getTheFuckingTime'); | |
const app = express(); | |
app.use(express.static('public')); | |
const server = app.listen(3000, () => { | |
console.log('SERVER LISTENING ON http://localhost:3000'); | |
(async () => { | |
const browser = await puppeteer.launch({ | |
args: ['--no-sandbox', '--disable-setuid-sandbox'], | |
}); | |
try { | |
const page = await browser.newPage(); | |
const footer = fs.readFileSync('./templates/footer.html').toString(); | |
await page.goto('http://localhost:3000/index.html', { | |
waitUntil: 'networkidle0', | |
}); | |
await page.pdf({ | |
path: `./dist/react-lernen-${dateTime}.pdf`, | |
width: '17cm', | |
height: '24cm', | |
printBackground: true, | |
displayHeaderFooter: true, | |
headerTemplate: '<span></span>', | |
footerTemplate: footer, | |
}); | |
await browser.close(); | |
server.close(); | |
} catch (error) { | |
console.log(error); | |
browser.close(); | |
server.close(); | |
process.exit(1); | |
} | |
})(); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* assets/style.css */ | |
* { | |
box-sizing: border-box; | |
font-variant-ligatures: none; | |
} | |
body { | |
font-family: Roboto, Times New Roman, sans-serif; | |
font-size: 11pt; | |
line-height: 1.65; | |
margin: 0; | |
padding: 0; | |
} | |
/* Working: */ | |
@page { | |
size: a4; | |
margin: 0.5in 0.25in; | |
/* experimental: */ | |
margin-bottom: 0.75in; | |
margin-top: 0.75in; | |
} | |
/* This would allow me to include the cover but the pages are all cut off then */ | |
/* @page :first { | |
margin: 0; | |
} */ | |
@page :left { | |
margin-right: 0.6in; | |
} | |
@page :right { | |
margin-left: 0.6in; | |
} | |
.chapter { | |
margin-left: 0.5in; | |
margin-right: 0.5in; | |
} | |
.chapter { | |
page-break-after: always; | |
position: relative; | |
} | |
@media screen { | |
body { | |
font-size: 15pt; | |
} | |
} | |
@media print { | |
body { | |
font-size: 11pt; | |
} | |
} | |
.cover { | |
display: none; | |
margin: 0; | |
/* page-break-after: avoid; */ | |
} | |
.cover img { | |
width: 100vw; | |
height: 100vh; | |
} | |
pre { | |
font-size: 90%; | |
} | |
pre, | |
code { | |
font-family: Dank Mono, monospace; | |
} | |
h1 { | |
display: flex; | |
margin: 0px; | |
margin-bottom: 24px; | |
color: #242a31; | |
position: relative; | |
margin-top: 32px; | |
} | |
h1:before { | |
content: ' '; | |
position: absolute; | |
top: -24px; | |
left: 0px; | |
height: 1px; | |
width: 100%; | |
background-color: #e6ecf1; | |
} | |
.hljs { | |
overflow: hidden !important; | |
} | |
pre { | |
white-space: pre-wrap; | |
overflow: hidden; | |
} | |
blockquote { | |
border-left: 5px solid #ccc; | |
color: #999; | |
margin-left: 0; | |
padding-left: 1em; | |
} | |
.has-image { | |
text-align: center; | |
} | |
.caption { | |
display: block; | |
font-size: 85%; | |
} | |
@media screen { | |
.chapter { | |
margin: 1in; | |
} | |
.cover { | |
margin: 0; | |
display: none; | |
} | |
#cover { | |
position: relative; | |
} | |
.hint { | |
background-position: 18px 24px; | |
} | |
} | |
img { | |
max-width: 100%; | |
} | |
h1, h2, h3 { | |
page-break-after: avoid; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment