/** * Social card — `npm run og`. * * Renders public/og.png (1200×630) from the SVG template below, using the * site's own faces from src/fonts via a private fontconfig so the card is the * site (Archivo display, DM Mono labels) rather than whatever the build box * happens to have installed. The PNG is committed and served as a static * asset — it is NOT rendered at build time on purpose: Vercel's image has * different fonts, and a card that changes shape per environment is worse * than one that changes only when someone re-runs this. * * Re-run after the dataset changes so the counts on the card stay honest. */ import { mkdirSync, writeFileSync, readFileSync, readdirSync, existsSync } from 'node:fs'; import { spawnSync } from 'node:child_process'; import { fileURLToPath } from 'node:url'; import { dirname, join, resolve } from 'node:path'; import { tmpdir } from 'node:os'; const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..'); const FONTS = join(ROOT, 'src', 'fonts'); const facets = JSON.parse(readFileSync(join(ROOT, 'src/data/facets.json'), 'utf8')); const c = facets.counts; const n = (x) => Number(x || 0).toLocaleString('en-US'); // A private fontconfig that sees only the site's faces. sharp's bundled // FreeType registers WOFF2 (fc-list sees them) but cannot rasterise their // glyphs — every run came out as tofu — so decompress to TTF first. Needs // `woff2_decompress` (package "woff2") or fonttools+brotli on PATH; both are // tried. Must be in place before sharp (libvips → pango → fontconfig) loads. const fcDir = join(tmpdir(), 'daemonbins-og-fc'); const ttfDir = join(fcDir, 'ttf'); mkdirSync(join(fcDir, 'cache'), { recursive: true }); mkdirSync(ttfDir, { recursive: true }); function decompress(woff2, ttf) { let r = spawnSync('woff2_decompress', [woff2], { stdio: 'ignore' }); if (r.status === 0) { // woff2_decompress writes .ttf beside the input; move it. const beside = woff2.replace(/\.woff2$/, '.ttf'); if (existsSync(beside)) { writeFileSync(ttf, readFileSync(beside)); spawnSync('rm', ['-f', beside]); return true; } } r = spawnSync('fonttools', ['ttLib.woff2', 'decompress', '-o', ttf, woff2], { stdio: 'ignore' }); return r.status === 0 && existsSync(ttf); } let converted = 0; for (const f of readdirSync(FONTS).filter((f) => f.endsWith('.woff2'))) { const ttf = join(ttfDir, f.replace(/\.woff2$/, '.ttf')); if (existsSync(ttf) || decompress(join(FONTS, f), ttf)) converted++; } if (!converted) { console.warn('og: custom WOFF2 faces unavailable; using the system fallback fonts.'); } else { writeFileSync(join(fcDir, 'fonts.conf'), ` ${ttfDir} ${join(fcDir, 'cache')} `); process.env.FONTCONFIG_FILE = join(fcDir, 'fonts.conf'); } const sharp = (await import('sharp')).default; // Rosé Pine (night) — the card is always the dark plate, like the code blocks. const P = { base: '#191724', surface: '#1f1d2e', overlay: '#26233a', text: '#e0def4', subtle: '#908caa', muted: '#6e6a86', love: '#eb6f92', rose: '#ebbcba', gold: '#f6c177', iris: '#c4a7e7', foam: '#9ccfd8', pine: '#3e8fb0', }; // Noto Sans Display is the masthead wordmark face (tokens.css --font-wordmark); // the Archivo subsets do not survive the WOFF2→TTF trip, so the card uses the // wordmark face for all display text. const DISPLAY = "'Noto Sans Display', 'Archivo', 'Liberation Sans', sans-serif"; const MONO = "'DM Mono', 'JetBrains Mono', 'Liberation Mono', monospace"; const decks = [ { tag: 'GTFOBins', acc: P.foam, n: c.bySource?.GTFOBins }, { tag: 'LOLBAS', acc: P.iris, n: c.bySource?.LOLBAS }, { tag: 'WADComs', acc: P.gold, n: c.bySource?.WADComs }, { tag: 'LOOBins', acc: P.rose, n: c.bySource?.LOOBins }, { tag: 'DÆMON', acc: P.love, n: c.bySource?.DAEMON }, ]; const svg = ` ^: 00 · LIVING OFF THE LAND lotl.daemon-sec.xyz DÆMONBins the Off-the-Land Almanac ${n(c.techniques)} techniques · ${n(c.tools)} tools GTFOBins × LOLBAS × WADComs × LOOBins — merged, resynced, extended · MITRE ATT&CK mapped ${decks.map((d, i) => { const x = 55 + i * 220; return ` ${n(d.n)} ${d.tag.toUpperCase()}`; }).join('\n ')} `; const outSvg = join(ROOT, 'public', 'og.svg'); const outPng = join(ROOT, 'public', 'og.png'); writeFileSync(outSvg, svg); // librsvg maps the SVG's px to 72 dpi; rasterise at 2× and downsample to the // exact 1200×630 so type edges stay crisp on retina previews. const png = await sharp(Buffer.from(svg), { density: 144 }) .resize(1200, 630, { fit: 'fill', kernel: 'lanczos3' }) .png({ compressionLevel: 9, palette: false }) .toBuffer(); writeFileSync(outPng, png); const meta = await sharp(png).metadata(); console.log(`wrote public/og.svg (${svg.length} B) and public/og.png (${png.length} B, ${meta.width}×${meta.height})`);