mailship/script/render-preview.mjs
Agent b7592044c0
All checks were successful
CI / checks (pull_request) Successful in 39s
digest email: replace reply/reaction counts with relay URL
- Replace `{{Replies}}`/`{{Reactions}}` stat items in digest.mjml with
  a single `{{RelayUrl}}` item showing the posting relay domain
- src/digest.ts: add `RelayUrl` to template variables, derive from
  existing `relayByEventId` map; strip unused `spec`, `getParentId`,
  `repliesByParentId`, and `context` destructure
- test/digest-reply-stats.test.ts: update assertion to check
  `parentEntry.RelayUrl` instead of `Replies`/`Reactions`
- script/render-preview.mjs: update sample data to use `RelayUrl`
2026-09-22 10:04:35 -04:00

48 lines
1.6 KiB
JavaScript

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: [
{
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',
},
{
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',
},
],
unsubscribeUrl: 'https://app.flotilla.social/unsubscribe?token=abc123',
settingsUrl: 'https://app.flotilla.social/settings/alerts',
}
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}`)