-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert-to-pdf.js
30 lines (27 loc) · 1.08 KB
/
convert-to-pdf.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
const fs = require("fs");
const { execSync } = require("child_process");
const path = require("path");
// Search for subfolders within ./content
const contentPath = "./_site/content/slides";
const subfolders = fs
.readdirSync(contentPath, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
.map((dirent) => `${contentPath}/${dirent.name}`);
// Convert index.html files to PDF using DeckTape
subfolders.forEach((subfolder) => {
const folderName = path.basename(subfolder);
const pdfPath = path.join(subfolder, `${folderName}.pdf`);
if (fs.existsSync(pdfPath)) {
// PDF file already exists, skip running DeckTape
console.log(`PDF already exists for ${folderName}, skipping DeckTape.`);
} else {
// Execute DeckTape if the PDF does not exist
const indexPath = path.join(subfolder, "index.html");
try {
execSync(`decktape reveal ${indexPath} ${pdfPath}`, { stdio: "inherit" });
console.log(`DeckTape successfully executed on ${indexPath}`);
} catch (error) {
console.error(`Error running DeckTape on ${indexPath}: ${error}`);
}
}
});