// Renders the share image background (src/og-bg.ts), the fallback public/og.png, // the PNG icons, the maskable icon, and the monochrome notification badge with headless Chrome. // Per-event share images are drawn on the server from src/og-bg.ts (see src/og.ts). // Needs playwright-core resolvable (node_modules is gitignored) and network for Google Fonts. // Usage: node scripts/render-assets.mjs import { chromium } from 'playwright-core' import { writeFileSync, readFileSync } from 'node:fs' import { FAVICON_SVG as favicon, HERO_SVG as hero } from '../src/art.ts' const fonts = '' const og = (withText) => `${fonts} ${[60,140,220,300,380,460,540,620,700,780,860,940,1020,1100,1180].map((x,i)=>{const y=30+Math.abs(Math.sin((x/310)*Math.PI))*55*(x%620<310?1:0.6);return ''}).join('')}
${hero}
${withText ? `
You're invited

Pie
Night

Let us know what pie you're bringing!

` : ''} ` const icon = (size, pad) => `
${favicon.replace('` const browser = await chromium.launch({ executablePath: process.env.CHROME || undefined }) async function shot(html, w, h, out, opts = {}) { const page = await browser.newPage({ viewport: { width: w, height: h } }) await page.setContent(html, { waitUntil: 'networkidle' }) await page.evaluate(() => document.fonts.ready) await page.screenshot({ path: new URL(`../${out}`, import.meta.url).pathname, ...opts }) await page.close() } await shot(og(true), 1200, 630, 'public/og.png') await shot(og(false), 1200, 630, 'scripts/og-bg.png') const bg = readFileSync(new URL('./og-bg.png', import.meta.url)) writeFileSync(new URL('../src/og-bg.ts', import.meta.url), `// Generated by scripts/render-assets.mjs: the cozy share image background (string lights, table, pie, leaves) with no text.\nexport const OG_BG_PNG_BASE64 = '${bg.toString('base64')}'\n`) const badge = `
${favicon.replace('` await shot(badge, 96, 96, 'public/badge-96.png', { omitBackground: true }) const maskable = `
${favicon.replace('` await shot(maskable, 512, 512, 'public/icon-maskable-512.png') await shot(icon(192, 16), 192, 192, 'public/icon-192.png') await shot(icon(512, 44), 512, 512, 'public/icon-512.png') await shot(icon(180, 14), 180, 180, 'public/apple-touch-icon.png') // Community listing icon (.kody/icon.png): the pie on a warm evening tile, like the share image. const listing = `
${''.repeat(5)}
${favicon.replace('
` await shot(listing, 512, 512, '.kody/icon.png', { omitBackground: true }) await browser.close() console.log('rendered')