Templates: OTP, team invite, summit invitation, invitation to apply, application saved/received, decisions (finalist, accepted into GRV, shortlisted, not selected), request received for every website form, partner confirmed, orders and tickets, staff notifications. pnpm preview renders a gallery; pnpm sync copies src/ into the backend. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
3.1 KiB
TypeScript
59 lines
3.1 KiB
TypeScript
// 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(`<h2>${escapeHtml(entry.group)}</h2>`);
|
|
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(
|
|
`<a href="${file}" target="view" data-subject="${escapeHtml(mail.subject)}">${escapeHtml(entry.name)}${v.id === 'default' ? '' : ` <span>· ${escapeHtml(v.label)}</span>`}</a>`,
|
|
);
|
|
count++;
|
|
}
|
|
}
|
|
|
|
writeFileSync(
|
|
`${out}/index.html`,
|
|
`<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
<title>GRV email templates</title>
|
|
<style>
|
|
body{margin:0;display:grid;grid-template-columns:300px 1fr;height:100vh;font:14px/1.4 -apple-system,'Segoe UI',sans-serif;color:#1a4034;background:#f4f7f5}
|
|
nav{overflow:auto;padding:20px;background:#1a4034;color:#fff}
|
|
nav h1{font-size:18px;margin:0 0 4px} nav p{margin:0 0 12px;color:#b9d8c9;font-size:12px}
|
|
nav h2{font-size:11px;letter-spacing:.14em;text-transform:uppercase;color:#b9d8c9;margin:18px 0 6px}
|
|
nav a{display:block;padding:7px 10px;border-radius:8px;color:#fff;text-decoration:none} nav a:hover,nav a.on{background:#30614c}
|
|
nav a span{color:#b9d8c9} main{display:flex;flex-direction:column} header{padding:12px 20px;background:#fff;border-bottom:1px solid #e8f2ec;font-weight:600}
|
|
iframe{flex:1;border:0;background:#f4f7f5}
|
|
@media (max-width:760px){body{grid-template-columns:1fr;grid-template-rows:40vh 1fr}}
|
|
</style></head><body>
|
|
<nav><h1>GRV email templates</h1><p>${count} emails · generated by <code>pnpm preview</code></p>${links.join('\n')}</nav>
|
|
<main><header id="subject">Pick an email</header><iframe name="view" title="Email preview"></iframe></main>
|
|
<script>
|
|
const links=[...document.querySelectorAll('nav a')];
|
|
const pick=(a)=>{links.forEach(l=>l.classList.toggle('on',l===a));document.getElementById('subject').textContent='Subject: '+a.dataset.subject;};
|
|
links.forEach(a=>a.addEventListener('click',()=>pick(a)));
|
|
if(links[0]){pick(links[0]);document.querySelector('iframe').src=links[0].getAttribute('href');}
|
|
</script></body></html>`,
|
|
);
|
|
console.log(`Wrote ${count} previews to ${out}/ (open ${out}/index.html)`);
|