v4: weekly digests and monthly recaps go out by email, every email is written once as Markdown in the app's one catalog, and a review of the last two commits removes what they stated twice — users get a weekly digest (what happened to them, what the people and playlists they follow posted, the week's top dumps, the community) and a monthly recap (the month's top dumps and the community), both on by default, in their own style and scheme. digest-service sends what is due every quarter of an hour from digest_schedule (migration 0020), which holds each user's rolling 7- or 30-day period; existing users' first periods are spread over the coming week or month, a digest more than a period late covers the last full one, an empty one isn't sent, and an address like admin@localhost is skipped. Each digest carries a one-click unsubscribe (List-Unsubscribe and List-Unsubscribe-Post, POST /api/users/unsubscribe) and a link to the new /unsubscribe page, which asks before turning that cadence off, since mail scanners open every link; the token (lib/jwt) names the user and the cadence and never expires. The welcome email now says the digests are on. The emails' words moved out of a hand-written api/mail/strings.ts into the Lingui catalogs the interface uses: lingui extracts api/mail/ too, the catalogs moved to a top-level locales/ that both halves read, compile emits ES modules the server imports (api/mail/i18n.ts), messages take ICU plurals, and the labels the settings tab, the unsubscribe page and the emails share are one message each (their French had already drifted apart). Each template writes its email once as Markdown, which is the plain-text part, and EmailKit.render draws its blocks in the style (a lone link is a button, a list item starting with an image a thumbnail row, a numbered list a ranking, --- the footer), so no string is declared for an HTML and a text version; user text is escaped for Markdown, which the welcome body didn't do for usernames, whose _ read as emphasis. paint() set colors before a border-top shorthand that reset them, so every divider was black. The review also gave one home to what was written twice: the locale list (shared/locale.ts, read by lingui.config, the client, the server and its catalog loader), the base style and default scheme (shared/theme.ts), an email's look (lookOf, which digest-service, welcome and reset share), whether email is on (EMAIL_ENABLED, read by email-service and index.html), a setting's column and its default in the digests' SQL (SETTINGS_COLUMNS, DEFAULT_SETTINGS), the unsubscribe token (made once, not parsed back from a URL), AuthProvider's compare-and-store, ThemeProvider's twin style and scheme code (useThemeChoice), the test JWT encoder, and duplicate digest messages. The email palettes stay a flattened copy of the themes' tokens, now under a test that caught Times' secondary and link colors drifting. The Dockerfile copies api/mail and locales so the build extracts the emails' messages and the server finds its catalogs, and deno.json maps @lingui/core for the runtime image. 236 backend tests (new: digest building, sending, catch-up, scheduling and unsubscribing; the Markdown renderer; French from the catalog; palettes against themes; the stagger migration; unsubscribe tokens) and 661 frontend tests (new: the unsubscribe page) pass, and tsc, eslint, doc:lint, deno check, deno lint and deno fmt are clean.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,7 +7,8 @@
|
||||
* @module
|
||||
*/
|
||||
|
||||
import { isStyleName, type StyleName } from "../shared/theme.ts";
|
||||
import { BASE_STYLE, isStyleName, type StyleName } from "../shared/theme.ts";
|
||||
import { isLocale, type Locale, SOURCE_LOCALE } from "../shared/locale.ts";
|
||||
|
||||
/** The port the server listens on (`GERBEUR_PORT`, default 8000). */
|
||||
export const PORT: number = Number(Deno.env.get("GERBEUR_PORT")) || 8000;
|
||||
@@ -18,6 +19,12 @@ export const PORT: number = Number(Deno.env.get("GERBEUR_PORT")) || 8000;
|
||||
*/
|
||||
export const SMTPS_URL: string = Deno.env.get("GERBEUR_SMTPS_URL")?.trim() ||
|
||||
"";
|
||||
/**
|
||||
* Whether the instance sends email, which is whether {@link SMTPS_URL} is
|
||||
* set. `email-service.ts` opens its transport by it, and index.html tells the
|
||||
* client, whose settings show the digest switches disabled without it.
|
||||
*/
|
||||
export const EMAIL_ENABLED: boolean = SMTPS_URL.length > 0;
|
||||
/**
|
||||
* The `From` address of every email (`GERBEUR_FROM_EMAIL`), as an address or
|
||||
* as `Name <address>`. `email-service.ts` refuses to load without it when
|
||||
@@ -33,24 +40,25 @@ export const FROM_EMAIL: string = Deno.env.get("GERBEUR_FROM_EMAIL")?.trim() ||
|
||||
*/
|
||||
export const WELCOME_EMAIL_BODY: string | null =
|
||||
Deno.env.get("GERBEUR_WELCOME_EMAIL_BODY")?.trim() || null;
|
||||
/** A language the emails are written in. */
|
||||
export type EmailLocale = "en" | "fr";
|
||||
/**
|
||||
* The language of every email (`GERBEUR_EMAIL_LOCALE`). The interface picks
|
||||
* each visitor's language in their browser, which the server never learns, so
|
||||
* the emails take the instance's. Any value but `"fr"` means `"en"`.
|
||||
* the emails take the instance's. A value that isn't a locale means the
|
||||
* source one, English.
|
||||
*/
|
||||
export const EMAIL_LOCALE: EmailLocale =
|
||||
Deno.env.get("GERBEUR_EMAIL_LOCALE")?.trim() === "fr" ? "fr" : "en";
|
||||
export const EMAIL_LOCALE: Locale = (() => {
|
||||
const locale = Deno.env.get("GERBEUR_EMAIL_LOCALE")?.trim();
|
||||
return isLocale(locale) ? locale : SOURCE_LOCALE;
|
||||
})();
|
||||
/**
|
||||
* The instance's style (`GERBEUR_DEFAULT_STYLE`). The site shows it until a
|
||||
* visitor or their account picks one, through index.html, and the emails that
|
||||
* aren't a user's own (the welcome and the password reset) are drawn in it. A
|
||||
* value that isn't a style means "smooth".
|
||||
* value that isn't a style means {@link BASE_STYLE}.
|
||||
*/
|
||||
export const DEFAULT_STYLE: StyleName = (() => {
|
||||
const style = Deno.env.get("GERBEUR_DEFAULT_STYLE")?.trim();
|
||||
return isStyleName(style) ? style : "smooth";
|
||||
return isStyleName(style) ? style : BASE_STYLE;
|
||||
})();
|
||||
/**
|
||||
* The key lib/jwt.ts signs and verifies tokens with (`GERBEUR_JWT_SECRET`).
|
||||
|
||||
Reference in New Issue
Block a user