mailship/script/render-preview.mjs

49 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

2026-08-26 21:57:26 +00:00
import {readFileSync, writeFileSync} from 'fs'
import {fileURLToPath} from 'url'
import {dirname, join} from 'path'
import Mustache from 'mustache'
import mjml2html from 'mjml'
const __dirname = dirname(fileURLToPath(import.meta.url))
const templatePath = join(__dirname, '..', 'src', 'emails', 'digest.mjml')
const sample = {
name: 'alice',
brandName: 'Flotilla',
brandAccent: '#7161FF',
brandLogo: 'https://app.flotilla.social/logo.png',
UserName: 'Alice',
Duration: '24 hours',
Total: 12,
TopProfiles: 'bob, carol',
HasLatest: true,
Latest: [
2026-08-26 21:57:26 +00:00
{
Link: 'https://app.flotilla.social/nevent1qqs...',
Timestamp: 'Aug 25, 2026 at 9:00 AM',
Icon: 'https://i.pravatar.cc/150?img=32',
Name: 'carol',
Content: '<p>Does anyone know how relay-based groups work?</p>',
RelayUrl: 'relay.damus.io',
2026-08-26 21:57:26 +00:00
},
{
Link: 'https://app.flotilla.social/spaces/nos.lol/community?at=1700000000',
Timestamp: 'Aug 25, 2026 at 10:00 AM',
Icon: 'https://i.pravatar.cc/150?img=68',
Name: 'bob',
Content:
'<p>Excited to share our new community space on Flotilla! <a href="https://flotilla.social">Check it out</a>.</p>',
RelayUrl: 'nos.lol',
2026-08-26 21:57:26 +00:00
},
],
unsubscribeUrl: 'https://app.flotilla.social/unsubscribe?token=abc123',
2026-08-27 19:23:18 +00:00
settingsUrl: 'https://app.flotilla.social/settings/alerts',
2026-08-26 21:57:26 +00:00
}
const source = readFileSync(templatePath, 'utf8')
const {html} = mjml2html(Mustache.render(source, sample))
const outPath = join(__dirname, '..', 'digest-preview.html')
writeFileSync(outPath, html)
console.log(`Rendered preview written to ${outPath}`)