// Renders every template + variant to previews/*.html and a gallery at previews/index.html. // pnpm preview → uses the production site for images and links // SITE_URL=http://localhost:3000 pnpm preview import { mkdirSync, rmSync, writeFileSync } from 'node:fs'; import { catalog, escapeHtml } from '../src/index.js'; const ctx = { siteUrl: process.env.SITE_URL ?? 'https://grv.ethiopiatrustfund.org', adminUrl: process.env.ADMIN_URL ?? 'https://admin.grv.ethiopiatrustfund.org', }; const out = 'previews'; rmSync(out, { recursive: true, force: true }); mkdirSync(out, { recursive: true }); const links: string[] = []; let lastGroup = ''; let count = 0; for (const entry of catalog(ctx)) { if (entry.group !== lastGroup) { links.push(`

${escapeHtml(entry.group)}

`); lastGroup = entry.group; } for (const v of entry.variants) { const file = `${entry.id}${v.id === 'default' ? '' : `--${v.id}`}.html`; const mail = v.render(); writeFileSync(`${out}/${file}`, mail.html); writeFileSync(`${out}/${file.replace(/\.html$/, '.txt')}`, `Subject: ${mail.subject}\n\n${mail.text}\n`); links.push( `${escapeHtml(entry.name)}${v.id === 'default' ? '' : ` · ${escapeHtml(v.label)}`}`, ); count++; } } writeFileSync( `${out}/index.html`, ` GRV email templates
Pick an email
`, ); console.log(`Wrote ${count} previews to ${out}/ (open ${out}/index.html)`);