Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: generate pdf for slides #4

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/generate-pdf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Generate PDF Slides

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
pdf-generation:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '21'
- name: Setup and generate PDF
run: |
npm i
npx -y live-server docs --port=8080 --quiet --no-browser &
while ! curl -s http://localhost:8080 > /dev/null; do sleep 1; done
node gen-pdf.js
- uses: actions/upload-artifact@v3
with:
name: presentation-slides
path: slides.pdf
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.pdf
node_modules
processed-slides.md
47 changes: 28 additions & 19 deletions docs/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ body {
font-family: #fff;
font-size: 1rem;
}

/* Required to avoid Chromiium's lazy-loading of fonts */
.space-mono {
font-family: "Space Mono";
position: absolute;
opacity: 0;
}

.remark-code,
.remark-inline-code {
font-family: "Space Mono";
Expand All @@ -15,25 +23,9 @@ body {
.remark-slide-content {
background-color: #000;
font-size: 2rem;
background-image: radial-gradient(
circle at 100% 10%,
#ffffff11 10%,
#000000 60%
),
repeating-linear-gradient(
0deg,
#ffffff22,
#ffffff22 0.5px,
#0000 1px,
#0000 27px
),
repeating-linear-gradient(
90deg,
#ffffff22,
#ffffff22 0.5px,
#0000 1px,
#0000 70px
);
neo773 marked this conversation as resolved.
Show resolved Hide resolved
background-image: url(./img/bg.png);
background-size: cover;
background-position: center;
height: 100%;
color: #fff;

Expand Down Expand Up @@ -73,6 +65,23 @@ body {
color: #000;
}

p.h1 {
display: block;
font-size: 55px;
font-weight: 700;
margin: 0;
padding: 0.6em 0;
}

p.h2 {
display: block;

font-size: 45px;
font-weight: 700;
margin: 0;
padding: 0.6em 0;
}

.font-size-6 {
font-size: 6rem;
}
Expand Down
Binary file added docs/img/bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<script src="https://remarkjs.com/downloads/remark-latest.min.js"></script>
<script>
var slideshow = remark.create({
sourceUrl: "./slides.md",
sourceUrl: "./processed-slides.md",
highlightStyle: "tomorrow-night",
ratio: "16:9",
navigation: {
Expand All @@ -51,5 +51,7 @@
countIncrementalSlides: false,
});
</script>
<!-- Required to avoid Chromiium's lazy-loading of fonts -->
<div class="space-mono">a</div>
neo773 marked this conversation as resolved.
Show resolved Hide resolved
</body>
</html>
31 changes: 31 additions & 0 deletions gen-pdf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import puppeteer from "puppeteer";
import util from "util";
import { exec } from "child_process";

const execPromise = util.promisify(exec);

async function generatePDF() {
await execPromise("node preprocess-markdown.js");
const browser = await puppeteer.launch();
const page = await browser.newPage();

await page.setViewport({
width: 1348,
height: 759,
deviceScaleFactor: 1,
});

await page.goto(`http://127.0.0.1:8080`, {
waitUntil: "networkidle0",
});

await page.pdf({
path: "slides.pdf",
preferCSSPageSize: true,
printBackground: true,
});

await browser.close();
}

generatePDF().catch(console.error);
Loading