Add KDP cover PDF generator

scripts/cover.js computes the exact cover canvas dimensions from the
page count in book-meta.json (written by build.js), using the KDP
Premium Color spine formula (0.002347 in/page), and renders a
Nunjucks template to a single PDF containing back cover, spine, and
front cover with bleed (0.125 in) and safe-zone overlay guides.

- `pnpm cover`  — generate output/cover.pdf
- `pnpm all`    — build interior + both PDFs in one command
- Cover artwork slots: images/cover/front.png, images/cover/back.png

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-03 17:29:10 +02:00
parent ae82edac2c
commit 1037b84eaa
6 changed files with 552 additions and 3 deletions
+8 -2
View File
@@ -64,8 +64,14 @@ async function build() {
const outPath = join(root, 'output', 'book.html');
await writeFile(outPath, html, 'utf-8');
const pageCount = stories.reduce((acc, s) => acc + s.scenes.length * 2, 0) + 5;
console.log(`Built output/book.html — ${stories.length} stories, ~${pageCount} pages`);
// title page + copyright + TOC + (4 scenes × 2 pages per story) + finale
const pageCount = 3 + stories.reduce((acc, s) => acc + s.scenes.length * 2, 0) + 1;
await writeFile(
join(root, 'output', 'book-meta.json'),
JSON.stringify({ pageCount, storyCount: stories.length, builtAt: new Date().toISOString() }, null, 2),
'utf-8'
);
console.log(`Built output/book.html — ${stories.length} stories, ${pageCount} pages`);
}
build().catch(err => { console.error(err); process.exit(1); });