Skip to content

Commit 068037f

Browse files
committed
chore: fix bookify
1 parent fcc984a commit 068037f

File tree

4 files changed

+2397
-88
lines changed

4 files changed

+2397
-88
lines changed

.github/workflows/build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111

1212
jobs:
1313
build:
14-
runs-on: ubuntu-20.04
14+
runs-on: ubuntu-latest
1515
permissions:
1616
contents: write
1717

bookify.js

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env node
22

3-
const fs = require("fs");
3+
const fs = require("fs/promises");
44
const path = require("path");
55
const yargs = require("yargs/yargs");
66
const { hideBin } = require("yargs/helpers");
7-
const markdownpdf = require("markdown-pdf");
7+
const { mdToPdf } = require("md-to-pdf");
88

99
const argv = yargs(hideBin(process.argv))
1010
.option("paper", {
@@ -31,25 +31,44 @@ const chapters = [
3131
"Cloud.md",
3232
].map((f) => path.resolve(f));
3333

34-
// Verify that every chapter exists before starting
35-
for (const file of chapters) {
36-
if (!fs.existsSync(file)) {
37-
console.error(`✗ Missing chapter: ${file}`);
38-
process.exit(1);
34+
(async () => {
35+
// Ensure all chapters exist
36+
for (const file of chapters) {
37+
try {
38+
await fs.access(file);
39+
} catch {
40+
console.error(`✗ Missing chapter: ${file}`);
41+
process.exit(1);
42+
}
3943
}
40-
}
4144

42-
const outputPath = path.resolve("Guides/Red_Teaming_TTPs.pdf");
45+
const pageBreak = "\n\n<div class=\"page-break\"></div>\n\n";
46+
const combinedMarkdown = (
47+
await Promise.all(chapters.map((f) => fs.readFile(f, "utf8")))
48+
).join(pageBreak);
4349

44-
markdownpdf({
45-
paperFormat: argv.paper,
46-
cssPath: argv.css ? path.resolve(argv.css) : undefined,
47-
})
48-
.concat.from.paths(chapters)
49-
.to(outputPath, function (err) {
50-
if (err) {
51-
console.error("PDF generation failed:", err);
52-
process.exit(1);
53-
}
50+
await fs.mkdir(path.resolve("Guides"), { recursive: true });
51+
const outputPath = path.resolve("Guides/Red_Teaming_TTPs.pdf");
52+
53+
try {
54+
await mdToPdf(
55+
{ content: combinedMarkdown },
56+
{
57+
dest: outputPath,
58+
stylesheet: argv.css ? [path.resolve(argv.css)] : undefined,
59+
pdf_options: {
60+
format: argv.paper,
61+
margin: "25mm",
62+
printBackground: true,
63+
},
64+
launch_options: {
65+
args: ["--no-sandbox", "--disable-setuid-sandbox"], // for CI runners
66+
},
67+
}
68+
);
5469
console.log(`✓ PDF generated at ${outputPath}`);
55-
});
70+
} catch (err) {
71+
console.error("PDF generation failed:", err);
72+
process.exit(1);
73+
}
74+
})();

0 commit comments

Comments
 (0)