diff --git a/CLAUDE.md b/CLAUDE.md
index 24281e0..3e95d37 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -34,6 +34,7 @@ In dev, Vite proxies `/api` to the target set in `vite.config.ts`, so the API mu
- Uploaded media: `UPLOADS_DIR=/var/lib/ngu/uploads`, served by nginx at `/uploads/`. Setup and the nginx block are in `docs/media-uploads.md`.
- Page HTML goes through the API, which fills in each page's title, description, preview image and structured data (`server/src/pageMeta.js`), and serves `/sitemap.xml`. It reads `SITE_CONFIG` (site.json) and `SITE_INDEX` (the built index.html), with Panel → Site settings (the `site_settings` table) laid over site.json, and serves `/robots.txt` from the same merge. nginx setup: `docs/seo.md`.
- Video clips (Tools, admins and up): yt-dlp downloads our YouTube/Facebook videos into `CLIPS_DIR`, ffmpeg cuts them; one job at a time, files swept after a day (`server/src/clips.js`). Needs yt-dlp and ffmpeg on the VPS: `docs/video-clips.md`.
+- Newsletter countdown pictures: `/api/countdown/:id.png` (`server/src/routes/countdown.js`), drawn with sharp when an email is opened; it uses the VPS's fonts, so install Poppins there (eg. into `/usr/local/share/fonts`, then `fc-cache`) or it falls back to a plain sans. The social bar's icons are static files in `public/email/`.
- Word import: Blog posts → Import from Word turns a .docx into an unpublished post (headings, paragraphs, lists, tables, links); nginx needs a block for `/api/admin/import/docx` with an 11m body limit: `docs/importing.md`.
- Speed: nginx must gzip JS/CSS/JSON/SVG and speak HTTP/2; page HTML is `no-cache`; uploads get a `-640.webp` small copy made at upload and at boot: `docs/performance.md`.
- Security headers: the API sends them (Hono `secureHeaders()`, plus a CSRF check on `/api` writes); nginx sends HSTS on everything and must pass `Host` and `X-Forwarded-For` to the API: `docs/security-headers.md`.
diff --git a/docs/updating-data-in-code.md b/docs/updating-data-in-code.md
index e7e3e1d..2866be8 100644
--- a/docs/updating-data-in-code.md
+++ b/docs/updating-data-in-code.md
@@ -285,7 +285,7 @@ The numbers band's "Number Source" dropdown works the same way:
| Organization kind labels ("Region", "Group") | the Kind options in `src/lib/adminSchema/organizations.ts` (admin); `orgListHref` in `src/lib/hrefs.ts` (the public back link, "All regions") | |
| Admin account roles | `src/lib/roles.ts` (labels, notes) and `ROLES` in `server/src/auth.js` | Adding a role is also a CHECK change on `admin_users.role`. |
| Admin navigation | `src/pages/admin/adminNav.ts` | |
-| Newsletter parts and their defaults (Tools → Newsletter) | `PARTS_SPEC`, `PART_TYPES` and `STARTER` in `src/pages/admin/AdminNewsletter.tsx`; `PICK_DEFAULTS`, `DEFAULT_TITLE` and `COLOR` in `src/lib/newsletter.ts` | A draft is one JSON list of parts (`newsletters.layout`, 060), so adding a part or a setting needs no migration: a field in `PARTS_SPEC` and its drawing in `newsletter.ts`. The color choices are `PALETTE`; `COLOR` holds the defaults as hex, since an inbox has no theme tokens. `STARTER` is what a new draft starts with. |
+| Newsletter parts and their defaults (Tools → Newsletter) | `PARTS_SPEC`, `PART_TYPES` and `STARTER` in `src/pages/admin/AdminNewsletter.tsx`; `PICK_DEFAULTS`, `DEFAULT_TITLE` and `COLOR` in `src/lib/newsletter.ts` | A draft is one JSON list of parts (`newsletters.layout`, 060), so adding a part or a setting needs no migration: a field in `PARTS_SPEC` and its drawing in `newsletter.ts`. The color choices are `PALETTE`; `COLOR` holds the defaults as hex, since an inbox has no theme tokens. `STARTER` is what a new draft starts with. The social bar's icons are PNGs in `public/email/` (Gmail and Outlook don't show SVG), made from `PlatformIcon.tsx` by `node scripts/email-icons.mjs`: run it again after adding a platform. A social bar with no links shows the footer's, `SOCIAL_LINKS` in `src/data/socialLinks.ts`. The countdown picture is `server/src/routes/countdown.js`, counting to local midnight in its `TIME_ZONE` (America/Chicago). |
| The live site's address (used by QR codes) | `SITE_ORIGIN` in `src/lib/site.ts` | |
| Version shown on the admin home page | `src/lib/version.ts` | |
| Image directories (where logos and photos are looked up) | `src/lib/media.ts` | |
diff --git a/public/email/discord-ink.png b/public/email/discord-ink.png
new file mode 100644
index 0000000..c9de1eb
Binary files /dev/null and b/public/email/discord-ink.png differ
diff --git a/public/email/discord-white.png b/public/email/discord-white.png
new file mode 100644
index 0000000..834dc30
Binary files /dev/null and b/public/email/discord-white.png differ
diff --git a/public/email/facebook-ink.png b/public/email/facebook-ink.png
new file mode 100644
index 0000000..6643b9a
Binary files /dev/null and b/public/email/facebook-ink.png differ
diff --git a/public/email/facebook-white.png b/public/email/facebook-white.png
new file mode 100644
index 0000000..4c33c97
Binary files /dev/null and b/public/email/facebook-white.png differ
diff --git a/public/email/instagram-ink.png b/public/email/instagram-ink.png
new file mode 100644
index 0000000..f33c454
Binary files /dev/null and b/public/email/instagram-ink.png differ
diff --git a/public/email/instagram-white.png b/public/email/instagram-white.png
new file mode 100644
index 0000000..9460dbb
Binary files /dev/null and b/public/email/instagram-white.png differ
diff --git a/public/email/linkedin-ink.png b/public/email/linkedin-ink.png
new file mode 100644
index 0000000..d57dcb5
Binary files /dev/null and b/public/email/linkedin-ink.png differ
diff --git a/public/email/linkedin-white.png b/public/email/linkedin-white.png
new file mode 100644
index 0000000..4ba8474
Binary files /dev/null and b/public/email/linkedin-white.png differ
diff --git a/public/email/spotify-ink.png b/public/email/spotify-ink.png
new file mode 100644
index 0000000..7badd18
Binary files /dev/null and b/public/email/spotify-ink.png differ
diff --git a/public/email/spotify-white.png b/public/email/spotify-white.png
new file mode 100644
index 0000000..45b17a4
Binary files /dev/null and b/public/email/spotify-white.png differ
diff --git a/public/email/substack-ink.png b/public/email/substack-ink.png
new file mode 100644
index 0000000..865e541
Binary files /dev/null and b/public/email/substack-ink.png differ
diff --git a/public/email/substack-white.png b/public/email/substack-white.png
new file mode 100644
index 0000000..185255c
Binary files /dev/null and b/public/email/substack-white.png differ
diff --git a/public/email/tiktok-ink.png b/public/email/tiktok-ink.png
new file mode 100644
index 0000000..240e2ff
Binary files /dev/null and b/public/email/tiktok-ink.png differ
diff --git a/public/email/tiktok-white.png b/public/email/tiktok-white.png
new file mode 100644
index 0000000..5491504
Binary files /dev/null and b/public/email/tiktok-white.png differ
diff --git a/public/email/x-ink.png b/public/email/x-ink.png
new file mode 100644
index 0000000..970812a
Binary files /dev/null and b/public/email/x-ink.png differ
diff --git a/public/email/x-white.png b/public/email/x-white.png
new file mode 100644
index 0000000..2be00ac
Binary files /dev/null and b/public/email/x-white.png differ
diff --git a/public/email/youtube-ink.png b/public/email/youtube-ink.png
new file mode 100644
index 0000000..2b9a18b
Binary files /dev/null and b/public/email/youtube-ink.png differ
diff --git a/public/email/youtube-white.png b/public/email/youtube-white.png
new file mode 100644
index 0000000..dc59d9e
Binary files /dev/null and b/public/email/youtube-white.png differ
diff --git a/scripts/email-icons.mjs b/scripts/email-icons.mjs
new file mode 100644
index 0000000..20950b0
--- /dev/null
+++ b/scripts/email-icons.mjs
@@ -0,0 +1,30 @@
+/* ═══════════════════════════════════════════════════════════════
+ EMAIL ICONS: node scripts/email-icons.mjs (from the repo root)
+
+ Gmail and Outlook don't show SVG, so a newsletter's social bar
+ (src/lib/newsletter.ts) uses PNG copies of the platform icons in
+ PlatformIcon.tsx: white and ink, 48px square (shown at 24), into
+ public/email/, which the build copies as they are, so the files
+ keep their addresses in emails already sent. Run it again after
+ adding a platform or changing an icon. Uses the server's sharp.
+ ═══════════════════════════════════════════════════════════════ */
+
+import { readFileSync, writeFileSync } from "node:fs";
+import { createRequire } from "node:module";
+
+const sharp = createRequire(new URL("../server/package.json", import.meta.url))("sharp");
+const source = readFileSync(new URL("../src/components/PlatformIcon.tsx", import.meta.url), "utf8");
+
+const paths = {};
+for (const [, id, d] of source.matchAll(/^\s*(\w+):\s*'([^']+)'/gm)) paths[id] = d;
+for (const [, id, d] of source.matchAll(/^\s*(\w+):\s*\n\s*'([^']+)'/gm)) paths[id] = d;
+paths.instagram = /INSTAGRAM_PATH =\s*'([^']+)'/.exec(source)[1];
+
+const TONES = { white: "#ffffff", ink: "#001011" };
+for (const [id, d] of Object.entries(paths)) {
+ for (const [tone, fill] of Object.entries(TONES)) {
+ const svg = ``;
+ writeFileSync(new URL(`../public/email/${id}-${tone}.png`, import.meta.url), await sharp(Buffer.from(svg)).png().toBuffer());
+ }
+}
+console.log(`${Object.keys(paths).length} icons: ${Object.keys(paths).join(", ")}`);
diff --git a/server/src/index.js b/server/src/index.js
index 7cd715b..1014a53 100644
--- a/server/src/index.js
+++ b/server/src/index.js
@@ -39,6 +39,7 @@ import media from "./routes/media.js";
import clips from "./routes/clips.js";
import imports from "./routes/import.js";
import files from "./routes/files.js";
+import countdown from "./routes/countdown.js";
import { CLIPS_DIR, startClipWorker } from "./clips.js";
import { UPLOADS_DIR, writeMissingThumbs } from "./media.js";
import { logSafe, startSessionSweeper } from "./auth.js";
@@ -74,6 +75,14 @@ const app = new Hono();
// loop a synchronous write each.
app.use("/api/admin/*", logger());
+/* A newsletter's countdown picture is shown inside other sites'
+ webmail, which the same-origin resource policy set below would
+ refuse. Registered first so it runs last, after secureHeaders. */
+app.use("/api/countdown/*", async (c, next) => {
+ await next();
+ c.res.headers.set("Cross-Origin-Resource-Policy", "cross-origin");
+});
+
/* Headers for every response. Referrer kept to the origin (YouTube
embeds refuse to play without one). No HSTS here: nginx sends it on
everything, including the files it serves from disk
@@ -178,6 +187,11 @@ app.route("/api", home);
app.route("/api", directory);
app.route("/api", blog);
app.route("/api", sitePages);
+// Opened by everyone a newsletter goes to, often through one mail
+// proxy's address, so looser than the rest; each picture is kept for
+// its minute (routes/countdown.js).
+app.use("/api/countdown/*", rateLimit({ windowMs: 60_000, max: 600 }));
+app.route("/api", countdown);
// Tighter limit on the write path than anything else gets.
app.use("/api/feedback", rateLimit({ windowMs: 60_000, max: 5 }));
diff --git a/server/src/routes/countdown.js b/server/src/routes/countdown.js
new file mode 100644
index 0000000..abd0601
--- /dev/null
+++ b/server/src/routes/countdown.js
@@ -0,0 +1,119 @@
+/* ═══════════════════════════════════════════════════════════════
+ COUNTDOWN IMAGE: GET /api/countdown/:id.png
+
+ A newsletter's countdown block (src/lib/newsletter.ts) is this
+ picture: the time left until a published one-off event starts,
+ drawn when the email is opened, since an email can't run code.
+ Gmail fetches images once through its proxy and keeps them, so
+ there it shows the time of the first open; the block's fixed line
+ under the image covers that and clients that block images.
+
+ ?bg=003a45 the band's color (hex, no #)
+ ?fg=ffffff the text's color
+ ?t=... the line above the numbers (default: the event's title)
+
+ An event starts at local midnight on starts_on in TIME_ZONE (events
+ carry a date, not a time) and is over when ends_on (or starts_on)
+ is; the picture says which. A series has no one start to count
+ to, so it isn't offered.
+
+ Each picture is kept for the minute it shows, a few hundred at most,
+ so a newsletter opened by everyone at once draws it once a minute.
+ ═══════════════════════════════════════════════════════════════ */
+
+import { Hono } from "hono";
+import sharp from "sharp";
+
+// The organization's home time zone (Unity Village, Missouri).
+export const TIME_ZONE = "America/Chicago";
+const MAX_KEPT = 300;
+
+const countdown = new Hono();
+const kept = new Map(); // key → png Buffer
+
+const hex = (value, fallback) => (/^[0-9a-f]{6}$/i.test(value ?? "") ? `#${value}` : fallback);
+const xml = (value) =>
+ String(value).replace(/&/g, "&").replace(//g, ">").replace(/"/g, """);
+
+/* The instant a date's local midnight is in a time zone, as ms. */
+export function zonedMidnight(date, timeZone = TIME_ZONE) {
+ const [y, m, d] = date.split("-").map(Number);
+ const guess = Date.UTC(y, m - 1, d);
+ // How far the zone's clock is from UTC at that instant, twice so a
+ // clock change between the guess and the answer is caught.
+ const offset = (at) => {
+ const parts = Object.fromEntries(
+ new Intl.DateTimeFormat("en-US", { timeZone, hourCycle: "h23", year: "numeric", month: "numeric", day: "numeric", hour: "numeric", minute: "numeric", second: "numeric" })
+ .formatToParts(at)
+ .map((p) => [p.type, Number(p.value)]),
+ );
+ return Date.UTC(parts.year, parts.month - 1, parts.day, parts.hour, parts.minute, parts.second) - at;
+ };
+ const first = guess - offset(guess);
+ return guess - offset(first);
+}
+
+/* Days, hours and minutes left, or null once it's started. */
+export function remaining(target, now = Date.now()) {
+ const left = target - now;
+ if (left <= 0) return null;
+ const minutes = Math.floor(left / 60_000);
+ return { days: Math.floor(minutes / 1440), hours: Math.floor(minutes / 60) % 24, minutes: minutes % 60 };
+}
+
+const W = 1104; // twice the email's 552px, for sharp screens
+const H = 280;
+const FONT = "Poppins, Montserrat, Helvetica, Arial, sans-serif";
+
+function svg({ label, left, over, bg, fg }) {
+ const top = `${xml(label)}`;
+ if (!left) {
+ return ``;
+ }
+ const cells = [
+ [left.days, left.days === 1 ? "DAY" : "DAYS"],
+ [left.hours, left.hours === 1 ? "HOUR" : "HOURS"],
+ [left.minutes, left.minutes === 1 ? "MINUTE" : "MINUTES"],
+ ]
+ .map(([n, unit], i) => {
+ const x = (W / 3) * i + W / 6;
+ return `${String(n).padStart(2, "0")}
+${unit}`;
+ })
+ .join("");
+ return ``;
+}
+
+countdown.get("/countdown/:file", async (c) => {
+ const id = /^(.+)\.png$/.exec(c.req.param("file"))?.[1];
+ const event = id
+ ? c
+ .get("db")
+ .prepare(`SELECT title, starts_on, ends_on FROM events WHERE id = ? AND is_published = 1 AND is_series = 0 AND starts_on IS NOT NULL`)
+ .get(id)
+ : null;
+ if (!event) return c.json({ error: "No such event" }, 404);
+
+ const bg = hex(c.req.query("bg"), "#003a45");
+ const fg = hex(c.req.query("fg"), "#ffffff");
+ const label = (c.req.query("t") ?? "").trim().slice(0, 60) || event.title.slice(0, 60);
+ const left = remaining(zonedMidnight(event.starts_on));
+ // Over once the last day's midnight has passed.
+ const over = !left && Date.now() >= zonedMidnight(event.ends_on ?? event.starts_on) + 86_400_000;
+ const key = JSON.stringify([id, bg, fg, label, left, over]);
+
+ let png = kept.get(key);
+ if (!png) {
+ png = await sharp(Buffer.from(svg({ label, left, over, bg, fg }))).png().toBuffer();
+ if (kept.size >= MAX_KEPT) kept.delete(kept.keys().next().value);
+ kept.set(key, png);
+ }
+ return c.body(png, 200, {
+ "Content-Type": "image/png",
+ // Asked for again at every open, where the client allows it.
+ "Cache-Control": "no-cache, max-age=0, must-revalidate",
+ });
+});
+
+export default countdown;
diff --git a/src/components/Footer.tsx b/src/components/Footer.tsx
index 6f25a42..a291b87 100644
--- a/src/components/Footer.tsx
+++ b/src/components/Footer.tsx
@@ -4,12 +4,7 @@ import { useNavSections } from "../lib/navSections.ts";
import siteLogo from "../assets/logos/NGU_Logo.svg";
import PlatformIcon from "./PlatformIcon.tsx";
import { ORGANIZATION_DETAILS as Organization_Details } from "../data/organizationDetails.ts";
-
-const Social_Links = [
- { label: "Instagram", href: "https://www.instagram.com/nextgenerationunity/", platform: "instagram" },
- { label: "Facebook", href: "https://www.facebook.com/NextGenerationofUnity", platform: "facebook" },
- { label: "Discord", href: "https://discord.com/invite/AtngzpqaX5", platform: "discord" },
-];
+import { SOCIAL_LINKS } from "../data/socialLinks.ts";
// Give's destination lives in navConfig so the footer and the nav can't drift.
// Only the label differs down here.
@@ -88,7 +83,7 @@ export default function Footer() {
{/* Socials + get in touch */}