v4: every email is rendered by its template in api/mail/ on one layout that takes the instance's style, and sent one way — the welcome email was built and sent inside the register route and the reset link in its service, each writing Markdown, running marked, and calling a nodemailer wrapper whose cc, bcc, replyTo and send result nothing used. Now api/mail/ holds one template per email (welcome.ts, password-reset.ts) on layout.ts's EmailKit, which draws each block with inline styles in a style from styles.ts: the six site styles' palettes, copied from src/themes/, and what makes each recognisable in a mail client (Brutalist's hard border and shadow, GeoCities' ridge and rainbow rules, Times' underlined ink links, Kanagawa's colored quotes, dates and wordmark, Melange's spice bar). On the "auto" scheme the light palette is inlined and the dark one swapped in by a prefers-color-scheme block; a chosen scheme sends only its own. User-written text is escaped where it lands. strings.ts holds every email's words in English and French. GERBEUR_EMAIL_LOCALE picks the language and GERBEUR_DEFAULT_STYLE the instance's style, which the welcome and reset emails are drawn in; GERBEUR_WELCOME_EMAIL_BODY still replaces the welcome's Markdown, whose blocks now take the style too. email-service sends a rendered email with its recipient and headers, refuses to load when GERBEUR_SMTPS_URL is set without GERBEUR_FROM_EMAIL (sends used to fail one by one), and takes a test transport, through which the tests now read what was sent. The welcome send moves to user-service's sendWelcomeEmail. The style and scheme names move to shared/theme.ts, which the server now needs. README, mod.ts and .env.example describe mail/ and the new variables, and drop the "notifications, invites" email that never existed. 221 backend tests pass (new: the layout's schemes, styles and escaping, both templates, the welcome on sign-up, a reset link from the email that works), and deno check, deno lint, doc:lint, deno fmt, tsc and eslint are clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
khannurien
2026-10-04 21:11:54 +00:00
parent 5f0cf86fe6
commit f20ca83f0c
21 changed files with 1459 additions and 179 deletions

43
shared/theme.ts Normal file
View File

@@ -0,0 +1,43 @@
/**
* The site's look is a style and a color scheme, which the client applies and
* the emails render in. This module names them for both halves: the client's
* `ThemeProvider` checks a stored choice against them, and the server checks
* `GERBEUR_DEFAULT_STYLE` and picks an email's palette by them.
*
* @module
*/
/**
* Lists every site style. Each has a stylesheet under `src/themes/`, keyed on
* the root element's `data-style`, and an email style in `api/mail/styles.ts`.
*/
export const STYLE_NAMES = [
"smooth",
"brutalist",
"geocities",
"nyt",
"kanagawa",
"melange",
] as const;
/** One of the {@link STYLE_NAMES}. */
export type StyleName = typeof STYLE_NAMES[number];
/** Lists every color scheme. "auto" follows the system's. */
export const COLOR_SCHEMES = ["auto", "light", "dark"] as const;
/** One of the {@link COLOR_SCHEMES}. */
export type ColorScheme = typeof COLOR_SCHEMES[number];
/**
* Checks whether `value` is a {@link StyleName}, as a stored choice or an
* environment variable must be before it is applied.
*/
export function isStyleName(value: unknown): value is StyleName {
return typeof value === "string" &&
(STYLE_NAMES as readonly string[]).includes(value);
}
/** Checks whether `value` is a {@link ColorScheme}. */
export function isColorScheme(value: unknown): value is ColorScheme {
return typeof value === "string" &&
(COLOR_SCHEMES as readonly string[]).includes(value);
}