/** * Renders the email that greets a new account. `sendWelcomeEmail` * (`user-service.ts`) sends it after sign-up, in the instance's style and * language. It opens with the instance's `GERBEUR_WELCOME_EMAIL_BODY`, or the * built-in body, then says the digests are on, since they are by default, and * where to turn them off. * * @module */ import { FRONTEND_URL, OG_SITE_NAME, WELCOME_EMAIL_BODY } from "../config.ts"; import { i18n } from "./i18n.ts"; import { EmailKit, escMd, lookOf, mdLink, type RenderedEmail, } from "./layout.ts"; /** * Returns the welcome email of `username`. The instance's body has * `{{username}}` and `{{site_name}}` filled in; raw HTML in it passes * through, since it comes from whoever runs the instance, never from a user. */ export function renderWelcomeEmail(username: string): RenderedEmail { // A username may hold a `_`, which Markdown would read as emphasis. const body = WELCOME_EMAIL_BODY ? WELCOME_EMAIL_BODY .replaceAll("{{username}}", escMd(username)) .replaceAll("{{site_name}}", escMd(OG_SITE_NAME)) : i18n._("email.welcome.body", { site: escMd(OG_SITE_NAME), username: escMd(username), }); const markdown = [ body, mdLink( i18n._("email.welcome.button", { site: OG_SITE_NAME }), FRONTEND_URL, ), `*${escMd(i18n._("email.welcome.digests"))}*`, "---", escMd(i18n._("email.welcome.reason", { site: OG_SITE_NAME })), ].join("\n\n"); return new EmailKit(lookOf()).render({ subject: i18n._("email.welcome.subject", { site: OG_SITE_NAME }), preheader: i18n._("email.welcome.preheader"), markdown, }); }