Newsletter: social bar and event countdown parts, full-width builder
- Social bar: a colored band of the site's platform icons, linked;
no links added shows the footer's (src/data/socialLinks.ts, shared)
- Icons are white and ink PNGs in public/email/, made from
PlatformIcon.tsx by scripts/email-icons.mjs (no SVG in Gmail/Outlook)
- Event countdown: a picture drawn by /api/countdown/<id>.png when the
email is opened (days, hours, minutes to local midnight in
America/Chicago; then happening now; then over), with a fixed line
under it as of copying
- The builder takes the whole window (useWideAdminPage('full'))
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a943ecd3a3
commit
00170ca912
29 changed files with 322 additions and 27 deletions
|
|
@ -39,6 +39,8 @@ import { SITE_NAME, SITE_ORIGIN, siteUrl } from '../../lib/site.ts'
|
|||
import { seriesLabel } from '../../lib/eventSeries.ts'
|
||||
import { useWideAdminPage } from '../../lib/adminWidth.tsx'
|
||||
import { PALETTE } from '../../lib/color.ts'
|
||||
import { PLATFORMS } from '../../lib/platforms.ts'
|
||||
import { SOCIAL_LINKS } from '../../data/socialLinks.ts'
|
||||
import {
|
||||
DEFAULT_TITLE,
|
||||
newsletterHtml,
|
||||
|
|
@ -73,6 +75,8 @@ const PART_TYPES: Array<[string, string, string]> = [
|
|||
['title', 'Title', "The email's heading."],
|
||||
['picks', 'Picked items', 'Upcoming events, published blog posts or front page cards, each as a card with a button.'],
|
||||
['footer', 'Footer', 'The closing lines. No unsubscribe link needed: Mailchimp adds its own.'],
|
||||
['social', 'Social bar', "A colored band of the site's social icons, each linked."],
|
||||
['countdown', 'Event countdown', "The time left until an event, as a picture the site draws each time the email is opened, with a line under it for when pictures don't load. Gmail may keep the time of the first open."],
|
||||
...(BLOCK_TYPES.filter(([type]) => EMAIL_BLOCKS.includes(type)) as Array<[string, string, string]>),
|
||||
]
|
||||
const partLabel = (type: string) => PART_TYPES.find(([value]) => value === type)?.[1] ?? type
|
||||
|
|
@ -133,7 +137,17 @@ const PARTS_SPEC = {
|
|||
when: { path: 'type', value: 'header' },
|
||||
help: "A PNG or JPEG: Gmail and Outlook don't show SVG. Default: none, the words alone",
|
||||
},
|
||||
colorField('color', 'Band color', 'Teal, darkest', 'None: no band', ['header']),
|
||||
colorField('color', 'Band color', 'Teal, darkest', 'None: no band', ['header', 'social', 'countdown']),
|
||||
{
|
||||
path: 'event',
|
||||
label: 'Event',
|
||||
widget: 'select',
|
||||
optionsFrom: 'countdownEvents',
|
||||
required: true,
|
||||
when: { path: 'type', value: 'countdown' },
|
||||
help: 'Upcoming events with a date; a series has no one start to count to',
|
||||
},
|
||||
{ path: 'text', label: 'Words above', when: { path: 'type', value: 'countdown' }, help: "Default: the event's title" },
|
||||
{ path: 'text', label: 'Title', full: true, when: { path: 'type', value: 'title' }, help: `Default: ${DEFAULT_TITLE(SITE_NAME)}` },
|
||||
{
|
||||
path: 'source',
|
||||
|
|
@ -173,6 +187,19 @@ const PARTS_SPEC = {
|
|||
],
|
||||
children: [
|
||||
...(blocksChild.children ?? []),
|
||||
{
|
||||
key: 'socials',
|
||||
label: 'Links',
|
||||
addLabel: 'Add link',
|
||||
note: `None added: the site's own (${SOCIAL_LINKS.map((link) => link.label).join(', ')}).`,
|
||||
when: { path: 'type', value: 'social' },
|
||||
title: (row: { platform?: string; url?: string }) => PLATFORMS.find((p) => p.id === row.platform)?.label ?? 'New link',
|
||||
blank: { platform: '', url: '' },
|
||||
fields: [
|
||||
{ path: 'platform', label: 'Platform', widget: 'select', options: PLATFORMS.map((p) => [p.id, p.label]), required: true },
|
||||
{ path: 'url', label: 'Link', required: true, help: 'eg. https://www.instagram.com/nextgenerationunity/' },
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'picked',
|
||||
label: 'Picked',
|
||||
|
|
@ -218,7 +245,7 @@ const picksOf = (parts: NewsletterPart[], source: PickSource) =>
|
|||
.flatMap((part) => (part.picked ?? []).map((pick) => pick.ref).filter((ref): ref is string => Boolean(ref)))
|
||||
|
||||
export default function AdminNewsletter() {
|
||||
useWideAdminPage()
|
||||
useWideAdminPage('full')
|
||||
const navigate = useNavigate()
|
||||
const { user } = useAuth()
|
||||
const [parts, setParts] = useState<NewsletterPart[]>(STARTER)
|
||||
|
|
@ -375,6 +402,9 @@ export default function AdminNewsletter() {
|
|||
const href = featuredHref(card)
|
||||
return href ? [{ id: href, label: card.title ?? href }] : []
|
||||
}),
|
||||
countdownEvents: events
|
||||
.filter((event) => !event.is_series && event.starts_on)
|
||||
.map((event) => ({ id: event.id, label: [event.title, event.date_label].filter(Boolean).join(', ') })),
|
||||
}),
|
||||
[events, posts, cards],
|
||||
)
|
||||
|
|
@ -387,12 +417,18 @@ export default function AdminNewsletter() {
|
|||
const item = pick.ref ? lookup[sourceOf(part)].get(pick.ref) : undefined
|
||||
return item ? [{ ...item, cta: part.cta?.trim() || item.cta }] : []
|
||||
}),
|
||||
eventFor: (id: string) => {
|
||||
const event = events.find((row) => row.id === id && !row.is_series && row.starts_on)
|
||||
return event ? { title: event.title, starts_on: event.starts_on, href: siteUrl(eventHref(event.id)) } : null
|
||||
},
|
||||
now: Date.now(),
|
||||
defaultSocials: SOCIAL_LINKS.map((link) => ({ platform: link.platform, url: link.href })),
|
||||
origin: SITE_ORIGIN,
|
||||
siteName: SITE_NAME,
|
||||
absolute: absoluteFor,
|
||||
}
|
||||
return { content, html: newsletterHtml(content), text: newsletterText(content) }
|
||||
}, [parts, lookup])
|
||||
}, [parts, lookup, events])
|
||||
|
||||
/* An unpublished blog post from what's built: the blocks, then each
|
||||
picks section as a heading and link cards. The header, title and
|
||||
|
|
@ -420,7 +456,7 @@ export default function AdminNewsletter() {
|
|||
]
|
||||
}
|
||||
if (!EMAIL_BLOCKS.includes(part.type)) return []
|
||||
const { align: _align, color: _color, size: _size, space: _space, ...block } = part
|
||||
const { align: _align, color: _color, size: _size, space: _space, socials: _socials, event: _event, ...block } = part
|
||||
return [block]
|
||||
})
|
||||
const excerpt = parts.find((part) => part.type === 'paragraph' && part.text?.trim())?.text?.trim() ?? null
|
||||
|
|
@ -507,7 +543,8 @@ export default function AdminNewsletter() {
|
|||
)}
|
||||
</div>
|
||||
|
||||
<div className="mt-6 grid gap-8 lg:grid-cols-[minmax(0,30rem)_minmax(0,1fr)]">
|
||||
{/* The editor takes what the preview (the email's 600px and its margin) leaves. */}
|
||||
<div className="mt-6 grid gap-8 lg:grid-cols-[minmax(0,1fr)_minmax(0,42rem)]">
|
||||
<section className="border-l-4 border-brand bg-raised p-5 shadow-sm">
|
||||
<Repeater spec={PARTS_SPEC} rows={parts} options={pickOptions} errors={{}} errorPrefix="parts." className="" onChange={setParts} />
|
||||
<p className="mt-3 text-xs" style={{ color: MUTED }}>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue