// Renders the tutorial cover images into public/covers/ as 2x WebP (3200 x 1920), then their share images into public/og/ (og.mjs). // npm run covers render every cover // npm run covers -- claude render covers whose output path starts with "claude" // Set COVERS_CHROME to a Chrome binary if Playwright's own browser isn't installed. import fs from "node:fs/promises"; import path from "node:path"; import { chromium } from "@playwright/test"; import sharp from "sharp"; import { H, W, page } from "./base.mjs"; import { writeOgImages } from "./og.mjs"; import { COVERS, SCENES } from "./scenes.mjs"; const OUT_DIR = path.join(process.cwd(), "public", "covers"); const only = process.argv[2]; const browser = await chromium.launch({ executablePath: process.env.COVERS_CHROME || undefined }); try { for (const cover of COVERS.filter((c) => !only || c.out.startsWith(only))) { // A fresh page per cover, so each one's scripts run in a clean context const tab = await browser.newPage({ viewport: { width: W, height: H }, deviceScaleFactor: 2 }); const scene = SCENES[cover.scene](cover.variant); const html = page({ seed: cover.out, ...(typeof scene === "string" ? { body: scene } : scene) }); await tab.setContent(html, { waitUntil: "networkidle" }); await tab.evaluate(() => document.fonts.ready); const png = await tab.screenshot({ type: "png" }); const file = path.join(OUT_DIR, `${cover.out}.webp`); await fs.mkdir(path.dirname(file), { recursive: true }); // 2x pixels and full-colour WebP (no chroma subsampling), so the dark gradients and small // particles survive the second encode by next/image without blocking or smearing await sharp(png).webp({ quality: 92, smartSubsample: true, effort: 6 }).toFile(file); await tab.close(); console.log(`covers: wrote ${path.relative(process.cwd(), file)}`); } await writeOgImages(); } catch (e) { console.error("covers: rendering failed:", e); process.exitCode = 1; } finally { await browser.close(); }