From 21008cdf3fe75db4460d616f6de7d8c02ec448e4 Mon Sep 17 00:00:00 2001 From: vickydotbat Date: Sat, 27 Jun 2026 09:47:43 +0000 Subject: [PATCH] refactor email templates into .tpls (#12) Reviewed-on: https://git.westgate.pw/ShadowsOverWestgate/sow-nodebb-theme/pulls/12 Reviewed-by: xtul Co-authored-by: vickydotbat Co-committed-by: vickydotbat --- scripts/check-emails.js | 11 +++-- {email => templates/emails}/README.md | 40 +++++++++---------- .../emails/banned.tpl | 4 +- .../emails/digest.tpl | 4 +- .../emails/invitation.tpl | 4 +- .../emails/notification.tpl | 4 +- .../emails/partials/footer.tpl | 0 .../emails/partials/header.tpl | 2 +- .../emails/partials/post-queue-body.tpl | 0 .../emails/registration_accepted.tpl | 4 +- .../reset.html => templates/emails/reset.tpl | 4 +- .../emails/reset_notify.tpl | 4 +- email/test.html => templates/emails/test.tpl | 4 +- .../emails/verify-email.tpl | 4 +- .../emails/welcome.tpl | 4 +- 15 files changed, 48 insertions(+), 45 deletions(-) rename {email => templates/emails}/README.md (70%) rename email/banned.html => templates/emails/banned.tpl (96%) rename email/digest.html => templates/emails/digest.tpl (99%) rename email/invitation.html => templates/emails/invitation.tpl (96%) rename email/notification.html => templates/emails/notification.tpl (96%) rename email/partials/footer.html => templates/emails/partials/footer.tpl (100%) rename email/partials/header.html => templates/emails/partials/header.tpl (99%) rename email/partials/post-queue-body.html => templates/emails/partials/post-queue-body.tpl (100%) rename email/registration_accepted.html => templates/emails/registration_accepted.tpl (96%) rename email/reset.html => templates/emails/reset.tpl (96%) rename email/reset_notify.html => templates/emails/reset_notify.tpl (95%) rename email/test.html => templates/emails/test.tpl (94%) rename email/verify-email.html => templates/emails/verify-email.tpl (97%) rename email/welcome.html => templates/emails/welcome.tpl (97%) diff --git a/scripts/check-emails.js b/scripts/check-emails.js index 5b6c589..8a38efe 100644 --- a/scripts/check-emails.js +++ b/scripts/check-emails.js @@ -3,20 +3,23 @@ const fs = require('fs'); const path = require('path'); -const dir = path.join(__dirname, '..', 'email'); -const files = fs.readdirSync(dir).filter((f) => f.endsWith('.html')); +const dir = path.join(__dirname, '..', 'templates', 'emails'); +const files = fs.readdirSync(dir).filter((f) => f.endsWith('.tpl')); const failures = []; +if (!files.length) { + failures.push('templates/emails: no email templates found'); +} for (const f of files) { const src = fs.readFileSync(path.join(dir, f), 'utf8'); const trimmed = src.trim(); const checks = [ [ - trimmed.startsWith(''), + trimmed.startsWith(''), 'header IMPORT must be first', ], [ - trimmed.endsWith(''), + trimmed.endsWith(''), 'footer IMPORT must be last', ], [//, 'missing preheader marker'], diff --git a/email/README.md b/templates/emails/README.md similarity index 70% rename from email/README.md rename to templates/emails/README.md index ae3f6f4..1470a50 100644 --- a/email/README.md +++ b/templates/emails/README.md @@ -1,4 +1,4 @@ -# Build note: the email templates import `emails/partials/header.html` and `emails/partials/footer.html` through NodeBB's `emails/` view namespace. +# Build note: the email templates import `emails/partials/header.tpl` and `emails/partials/footer.tpl` through NodeBB's `emails/` view namespace. # Email templates @@ -9,8 +9,8 @@ them to users on various events (password reset, digest, ban, etc.). - **Discovery.** NodeBB looks for email templates under a theme/plugin's templates directory. Core ships them in `src/views/emails/*.tpl`; a theme - overrides one by shipping a file of the same name. The `email/` directory - here is built into NodeBB's `emails/` view namespace, so `email/reset.html` + overrides one by shipping a file of the same name. The `templates/emails/` directory + here is built into NodeBB's `emails/` view namespace, so `templates/emails/reset.tpl` overrides the core `reset` template. Run `./nodebb build` after editing so the changes are compiled into `build/`. - **Template engine.** [Benchpress](https://github.com/benchpressjs/benchpressjs), @@ -23,7 +23,7 @@ them to users on various events (password reset, digest, ban, etc.). live in NodeBB's language files, not here. - **Send path.** `Emailer.send(template, uid, params)` → `sendToEmail` → `renderAndTranslate('emails/', params)`. `` is - the filename without extension (`reset.html` → template name `reset`). + the filename without extension (`reset.tpl` → template name `reset`). - **Default params** available in every template: `url`, `site_title`, `logo.{src,width,height}`, `uid`, `username`, `displayname`, `rtl`, plus `showUnsubscribe` / `unsubUrl` for digest- and notification-type mails. @@ -33,27 +33,27 @@ them to users on various events (password reset, digest, ban, etc.). | File | NodeBB event | Notable params | |------|--------------|----------------| -| `welcome.html` | New registration needing email confirmation | confirmation link | -| `verify-email.html` | User adds/changes an email and must confirm it | confirmation link | -| `reset.html` | User requests a password reset | `{reset_link}` | -| `reset_notify.html` | Confirmation that the password was changed | — | -| `registration_accepted.html` | Admin approves a queued registration | — | -| `banned.html` | User is banned | ban reason / expiry | -| `invitation.html` | A user is invited to the forum | invite link | -| `notification.html` | Per-event notification (reply, mention, etc.); also post-queue items | `showUnsubscribe`, `unsubUrl` | -| `digest.html` | Scheduled activity digest (daily/weekly/monthly) | unread topics, `showUnsubscribe` | -| `test.html` | "Send test email" button in the ACP | — | +| `welcome.tpl` | New registration needing email confirmation | confirmation link | +| `verify-email.tpl` | User adds/changes an email and must confirm it | confirmation link | +| `reset.tpl` | User requests a password reset | `{reset_link}` | +| `reset_notify.tpl` | Confirmation that the password was changed | — | +| `registration_accepted.tpl` | Admin approves a queued registration | — | +| `banned.tpl` | User is banned | ban reason / expiry | +| `invitation.tpl` | A user is invited to the forum | invite link | +| `notification.tpl` | Per-event notification (reply, mention, etc.); also post-queue items | `showUnsubscribe`, `unsubUrl` | +| `digest.tpl` | Scheduled activity digest (daily/weekly/monthly) | unread topics, `showUnsubscribe` | +| `test.tpl` | "Send test email" button in the ACP | — | ## Partials `partials/` holds fragments imported by the templates above. Every -non-partial template starts with `` -and ends with ``. +non-partial template starts with `` +and ends with ``. -- `header.html` — shared email head/header markup. -- `footer.html` — shared footer with the unsubscribe block +- `header.tpl` — shared email head/header markup. +- `footer.tpl` — shared footer with the unsubscribe block (`{{{ if showUnsubscribe }}}`). -- `post-queue-body.html` — queued-post notification body fragment (category, +- `post-queue-body.tpl` — queued-post notification body fragment (category, topic, author, content), maintained for use by a notification branch/template. ## Editing notes @@ -68,7 +68,7 @@ and ends with ``. them in the language files. - Run `node scripts/check-emails.js` after converting templates. It enforces the shared-partial structure by requiring a header import, footer import, - and `` marker in each `email/*.html` file. + and `` marker in each `templates/emails/*.tpl` file. - Rebuild (`./nodebb build`) and use the ACP test-email button to verify. ## Deliverability — out of scope for these templates (ops/mail layer) diff --git a/email/banned.html b/templates/emails/banned.tpl similarity index 96% rename from email/banned.html rename to templates/emails/banned.tpl index aa55f27..1fa7555 100644 --- a/email/banned.html +++ b/templates/emails/banned.tpl @@ -1,4 +1,4 @@ - +
[[email:banned.preheader]]
 ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌
@@ -38,4 +38,4 @@ - + diff --git a/email/digest.html b/templates/emails/digest.tpl similarity index 99% rename from email/digest.html rename to templates/emails/digest.tpl index ddbd262..b9c1a64 100644 --- a/email/digest.html +++ b/templates/emails/digest.tpl @@ -1,4 +1,4 @@ - +
[[email:digest.preheader]]
 ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌
@@ -175,4 +175,4 @@ - + diff --git a/email/invitation.html b/templates/emails/invitation.tpl similarity index 96% rename from email/invitation.html rename to templates/emails/invitation.tpl index 1ed3be0..ce2252c 100644 --- a/email/invitation.html +++ b/templates/emails/invitation.tpl @@ -1,4 +1,4 @@ - +
[[email:invitation.preheader]]
 ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌
@@ -42,4 +42,4 @@ - + diff --git a/email/notification.html b/templates/emails/notification.tpl similarity index 96% rename from email/notification.html rename to templates/emails/notification.tpl index a9324e5..ea85b3a 100644 --- a/email/notification.html +++ b/templates/emails/notification.tpl @@ -1,4 +1,4 @@ - +
[[email:notification.preheader]]
 ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌
@@ -44,4 +44,4 @@ - + diff --git a/email/partials/footer.html b/templates/emails/partials/footer.tpl similarity index 100% rename from email/partials/footer.html rename to templates/emails/partials/footer.tpl diff --git a/email/partials/header.html b/templates/emails/partials/header.tpl similarity index 99% rename from email/partials/header.html rename to templates/emails/partials/header.tpl index 812e6bb..6c05009 100644 --- a/email/partials/header.html +++ b/templates/emails/partials/header.tpl @@ -26,7 +26,7 @@ } - + diff --git a/email/partials/post-queue-body.html b/templates/emails/partials/post-queue-body.tpl similarity index 100% rename from email/partials/post-queue-body.html rename to templates/emails/partials/post-queue-body.tpl diff --git a/email/registration_accepted.html b/templates/emails/registration_accepted.tpl similarity index 96% rename from email/registration_accepted.html rename to templates/emails/registration_accepted.tpl index c21cd5a..2a08a92 100644 --- a/email/registration_accepted.html +++ b/templates/emails/registration_accepted.tpl @@ -1,4 +1,4 @@ - +
[[email:registration_accepted.preheader]]
 ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌
@@ -37,4 +37,4 @@ - + diff --git a/email/reset.html b/templates/emails/reset.tpl similarity index 96% rename from email/reset.html rename to templates/emails/reset.tpl index 04c3244..57742a5 100644 --- a/email/reset.html +++ b/templates/emails/reset.tpl @@ -1,4 +1,4 @@ - +
[[email:reset.preheader]]
 ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌
@@ -42,4 +42,4 @@ - + diff --git a/email/reset_notify.html b/templates/emails/reset_notify.tpl similarity index 95% rename from email/reset_notify.html rename to templates/emails/reset_notify.tpl index 29e09fe..97eea40 100644 --- a/email/reset_notify.html +++ b/templates/emails/reset_notify.tpl @@ -1,4 +1,4 @@ - +
[[email:reset_notify.preheader]]
 ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌
@@ -27,4 +27,4 @@ - + diff --git a/email/test.html b/templates/emails/test.tpl similarity index 94% rename from email/test.html rename to templates/emails/test.tpl index 34ac544..0e6094d 100644 --- a/email/test.html +++ b/templates/emails/test.tpl @@ -1,4 +1,4 @@ - +
[[email:test.preheader]]
 ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌
@@ -22,4 +22,4 @@ - + diff --git a/email/verify-email.html b/templates/emails/verify-email.tpl similarity index 97% rename from email/verify-email.html rename to templates/emails/verify-email.tpl index a587ebf..831f570 100644 --- a/email/verify-email.html +++ b/templates/emails/verify-email.tpl @@ -1,4 +1,4 @@ - +
[[email:verify-email.preheader]]
 ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌
@@ -47,4 +47,4 @@ - + diff --git a/email/welcome.html b/templates/emails/welcome.tpl similarity index 97% rename from email/welcome.html rename to templates/emails/welcome.tpl index 4c468ac..d3aefbe 100644 --- a/email/welcome.html +++ b/templates/emails/welcome.tpl @@ -1,4 +1,4 @@ - +
[[email:welcome.preheader]]
 ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌
@@ -47,4 +47,4 @@ - +