refactor email templates into .tpls (#12)
Reviewed-on: #12 Reviewed-by: xtul <mpiasecki720@protonmail.com> Co-authored-by: vickydotbat <vickydotbat@tutamail.com> Co-committed-by: vickydotbat <vickydotbat@tutamail.com>
This commit was merged in pull request #12.
This commit is contained in:
@@ -3,20 +3,23 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const dir = path.join(__dirname, '..', 'email');
|
const dir = path.join(__dirname, '..', 'templates', 'emails');
|
||||||
const files = fs.readdirSync(dir).filter((f) => f.endsWith('.html'));
|
const files = fs.readdirSync(dir).filter((f) => f.endsWith('.tpl'));
|
||||||
|
|
||||||
const failures = [];
|
const failures = [];
|
||||||
|
if (!files.length) {
|
||||||
|
failures.push('templates/emails: no email templates found');
|
||||||
|
}
|
||||||
for (const f of files) {
|
for (const f of files) {
|
||||||
const src = fs.readFileSync(path.join(dir, f), 'utf8');
|
const src = fs.readFileSync(path.join(dir, f), 'utf8');
|
||||||
const trimmed = src.trim();
|
const trimmed = src.trim();
|
||||||
const checks = [
|
const checks = [
|
||||||
[
|
[
|
||||||
trimmed.startsWith('<!-- IMPORT emails/partials/header.html -->'),
|
trimmed.startsWith('<!-- IMPORT emails/partials/header.tpl -->'),
|
||||||
'header IMPORT must be first',
|
'header IMPORT must be first',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
trimmed.endsWith('<!-- IMPORT emails/partials/footer.html -->'),
|
trimmed.endsWith('<!-- IMPORT emails/partials/footer.tpl -->'),
|
||||||
'footer IMPORT must be last',
|
'footer IMPORT must be last',
|
||||||
],
|
],
|
||||||
[/<!-- preheader -->/, 'missing preheader marker'],
|
[/<!-- preheader -->/, 'missing preheader marker'],
|
||||||
|
|||||||
@@ -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
|
# 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
|
- **Discovery.** NodeBB looks for email templates under a theme/plugin's
|
||||||
templates directory. Core ships them in `src/views/emails/*.tpl`; a theme
|
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
|
overrides one by shipping a file of the same name. The `templates/emails/` directory
|
||||||
here is built into NodeBB's `emails/` view namespace, so `email/reset.html`
|
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
|
overrides the core `reset` template. Run `./nodebb build` after editing so
|
||||||
the changes are compiled into `build/`.
|
the changes are compiled into `build/`.
|
||||||
- **Template engine.** [Benchpress](https://github.com/benchpressjs/benchpressjs),
|
- **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.
|
live in NodeBB's language files, not here.
|
||||||
- **Send path.** `Emailer.send(template, uid, params)` →
|
- **Send path.** `Emailer.send(template, uid, params)` →
|
||||||
`sendToEmail` → `renderAndTranslate('emails/<name>', params)`. `<name>` is
|
`sendToEmail` → `renderAndTranslate('emails/<name>', params)`. `<name>` 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`,
|
- **Default params** available in every template: `url`, `site_title`,
|
||||||
`logo.{src,width,height}`, `uid`, `username`, `displayname`, `rtl`, plus
|
`logo.{src,width,height}`, `uid`, `username`, `displayname`, `rtl`, plus
|
||||||
`showUnsubscribe` / `unsubUrl` for digest- and notification-type mails.
|
`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 |
|
| File | NodeBB event | Notable params |
|
||||||
|------|--------------|----------------|
|
|------|--------------|----------------|
|
||||||
| `welcome.html` | New registration needing email confirmation | confirmation link |
|
| `welcome.tpl` | New registration needing email confirmation | confirmation link |
|
||||||
| `verify-email.html` | User adds/changes an email and must confirm it | confirmation link |
|
| `verify-email.tpl` | User adds/changes an email and must confirm it | confirmation link |
|
||||||
| `reset.html` | User requests a password reset | `{reset_link}` |
|
| `reset.tpl` | User requests a password reset | `{reset_link}` |
|
||||||
| `reset_notify.html` | Confirmation that the password was changed | — |
|
| `reset_notify.tpl` | Confirmation that the password was changed | — |
|
||||||
| `registration_accepted.html` | Admin approves a queued registration | — |
|
| `registration_accepted.tpl` | Admin approves a queued registration | — |
|
||||||
| `banned.html` | User is banned | ban reason / expiry |
|
| `banned.tpl` | User is banned | ban reason / expiry |
|
||||||
| `invitation.html` | A user is invited to the forum | invite link |
|
| `invitation.tpl` | A user is invited to the forum | invite link |
|
||||||
| `notification.html` | Per-event notification (reply, mention, etc.); also post-queue items | `showUnsubscribe`, `unsubUrl` |
|
| `notification.tpl` | Per-event notification (reply, mention, etc.); also post-queue items | `showUnsubscribe`, `unsubUrl` |
|
||||||
| `digest.html` | Scheduled activity digest (daily/weekly/monthly) | unread topics, `showUnsubscribe` |
|
| `digest.tpl` | Scheduled activity digest (daily/weekly/monthly) | unread topics, `showUnsubscribe` |
|
||||||
| `test.html` | "Send test email" button in the ACP | — |
|
| `test.tpl` | "Send test email" button in the ACP | — |
|
||||||
|
|
||||||
## Partials
|
## Partials
|
||||||
|
|
||||||
`partials/` holds fragments imported by the templates above. Every
|
`partials/` holds fragments imported by the templates above. Every
|
||||||
non-partial template starts with `<!-- IMPORT emails/partials/header.html -->`
|
non-partial template starts with `<!-- IMPORT emails/partials/header.tpl -->`
|
||||||
and ends with `<!-- IMPORT emails/partials/footer.html -->`.
|
and ends with `<!-- IMPORT emails/partials/footer.tpl -->`.
|
||||||
|
|
||||||
- `header.html` — shared email head/header markup.
|
- `header.tpl` — shared email head/header markup.
|
||||||
- `footer.html` — shared footer with the unsubscribe block
|
- `footer.tpl` — shared footer with the unsubscribe block
|
||||||
(`{{{ if showUnsubscribe }}}`).
|
(`{{{ 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.
|
topic, author, content), maintained for use by a notification branch/template.
|
||||||
|
|
||||||
## Editing notes
|
## Editing notes
|
||||||
@@ -68,7 +68,7 @@ and ends with `<!-- IMPORT emails/partials/footer.html -->`.
|
|||||||
them in the language files.
|
them in the language files.
|
||||||
- Run `node scripts/check-emails.js` after converting templates. It enforces
|
- Run `node scripts/check-emails.js` after converting templates. It enforces
|
||||||
the shared-partial structure by requiring a header import, footer import,
|
the shared-partial structure by requiring a header import, footer import,
|
||||||
and `<!-- preheader -->` marker in each `email/*.html` file.
|
and `<!-- preheader -->` marker in each `templates/emails/*.tpl` file.
|
||||||
- Rebuild (`./nodebb build`) and use the ACP test-email button to verify.
|
- Rebuild (`./nodebb build`) and use the ACP test-email button to verify.
|
||||||
|
|
||||||
## Deliverability — out of scope for these templates (ops/mail layer)
|
## Deliverability — out of scope for these templates (ops/mail layer)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<!-- IMPORT emails/partials/header.html -->
|
<!-- IMPORT emails/partials/header.tpl -->
|
||||||
<!-- preheader -->
|
<!-- preheader -->
|
||||||
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;">[[email:banned.preheader]]</div>
|
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;">[[email:banned.preheader]]</div>
|
||||||
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;"> ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌</div>
|
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;"> ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌</div>
|
||||||
@@ -38,4 +38,4 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<!-- Email Body : END -->
|
<!-- Email Body : END -->
|
||||||
<!-- IMPORT emails/partials/footer.html -->
|
<!-- IMPORT emails/partials/footer.tpl -->
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<!-- IMPORT emails/partials/header.html -->
|
<!-- IMPORT emails/partials/header.tpl -->
|
||||||
<!-- preheader -->
|
<!-- preheader -->
|
||||||
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;">[[email:digest.preheader]]</div>
|
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;">[[email:digest.preheader]]</div>
|
||||||
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;"> ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌</div>
|
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;"> ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌</div>
|
||||||
@@ -175,4 +175,4 @@
|
|||||||
<!-- 1 Column Text : END -->
|
<!-- 1 Column Text : END -->
|
||||||
</table>
|
</table>
|
||||||
<!-- Email Body : END -->
|
<!-- Email Body : END -->
|
||||||
<!-- IMPORT emails/partials/footer.html -->
|
<!-- IMPORT emails/partials/footer.tpl -->
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<!-- IMPORT emails/partials/header.html -->
|
<!-- IMPORT emails/partials/header.tpl -->
|
||||||
<!-- preheader -->
|
<!-- preheader -->
|
||||||
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;">[[email:invitation.preheader]]</div>
|
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;">[[email:invitation.preheader]]</div>
|
||||||
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;"> ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌</div>
|
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;"> ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌</div>
|
||||||
@@ -42,4 +42,4 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<!-- Email Body : END -->
|
<!-- Email Body : END -->
|
||||||
<!-- IMPORT emails/partials/footer.html -->
|
<!-- IMPORT emails/partials/footer.tpl -->
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<!-- IMPORT emails/partials/header.html -->
|
<!-- IMPORT emails/partials/header.tpl -->
|
||||||
<!-- preheader -->
|
<!-- preheader -->
|
||||||
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;">[[email:notification.preheader]]</div>
|
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;">[[email:notification.preheader]]</div>
|
||||||
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;"> ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌</div>
|
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;"> ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌</div>
|
||||||
@@ -44,4 +44,4 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<!-- Email Body : END -->
|
<!-- Email Body : END -->
|
||||||
<!-- IMPORT emails/partials/footer.html -->
|
<!-- IMPORT emails/partials/footer.tpl -->
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
<!-- All other clients get the webfont reference; some will render the font and others will silently fail to the fallbacks. More on that here: http://stylecampaign.com/blog/2015/02/webfont-support-in-email/ -->
|
<!-- All other clients get the webfont reference; some will render the font and others will silently fail to the fallbacks. More on that here: http://stylecampaign.com/blog/2015/02/webfont-support-in-templates/emails/ -->
|
||||||
<!--[if !mso]><!-->
|
<!--[if !mso]><!-->
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Cinzel:wght@400;600&family=Jost:wght@400;600&display=swap" rel="stylesheet" />
|
<link href="https://fonts.googleapis.com/css2?family=Cinzel:wght@400;600&family=Jost:wght@400;600&display=swap" rel="stylesheet" />
|
||||||
<!--<![endif]-->
|
<!--<![endif]-->
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<!-- IMPORT emails/partials/header.html -->
|
<!-- IMPORT emails/partials/header.tpl -->
|
||||||
<!-- preheader -->
|
<!-- preheader -->
|
||||||
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;">[[email:registration_accepted.preheader]]</div>
|
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;">[[email:registration_accepted.preheader]]</div>
|
||||||
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;"> ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌</div>
|
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;"> ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌</div>
|
||||||
@@ -37,4 +37,4 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<!-- Email Body : END -->
|
<!-- Email Body : END -->
|
||||||
<!-- IMPORT emails/partials/footer.html -->
|
<!-- IMPORT emails/partials/footer.tpl -->
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<!-- IMPORT emails/partials/header.html -->
|
<!-- IMPORT emails/partials/header.tpl -->
|
||||||
<!-- preheader -->
|
<!-- preheader -->
|
||||||
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;">[[email:reset.preheader]]</div>
|
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;">[[email:reset.preheader]]</div>
|
||||||
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;"> ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌</div>
|
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;"> ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌</div>
|
||||||
@@ -42,4 +42,4 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<!-- Email Body : END -->
|
<!-- Email Body : END -->
|
||||||
<!-- IMPORT emails/partials/footer.html -->
|
<!-- IMPORT emails/partials/footer.tpl -->
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<!-- IMPORT emails/partials/header.html -->
|
<!-- IMPORT emails/partials/header.tpl -->
|
||||||
<!-- preheader -->
|
<!-- preheader -->
|
||||||
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;">[[email:reset_notify.preheader]]</div>
|
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;">[[email:reset_notify.preheader]]</div>
|
||||||
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;"> ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌</div>
|
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;"> ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌</div>
|
||||||
@@ -27,4 +27,4 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<!-- Email Body : END -->
|
<!-- Email Body : END -->
|
||||||
<!-- IMPORT emails/partials/footer.html -->
|
<!-- IMPORT emails/partials/footer.tpl -->
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<!-- IMPORT emails/partials/header.html -->
|
<!-- IMPORT emails/partials/header.tpl -->
|
||||||
<!-- preheader -->
|
<!-- preheader -->
|
||||||
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;">[[email:test.preheader]]</div>
|
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;">[[email:test.preheader]]</div>
|
||||||
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;"> ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌</div>
|
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;"> ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌</div>
|
||||||
@@ -22,4 +22,4 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<!-- Email Body : END -->
|
<!-- Email Body : END -->
|
||||||
<!-- IMPORT emails/partials/footer.html -->
|
<!-- IMPORT emails/partials/footer.tpl -->
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<!-- IMPORT emails/partials/header.html -->
|
<!-- IMPORT emails/partials/header.tpl -->
|
||||||
<!-- preheader -->
|
<!-- preheader -->
|
||||||
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;">[[email:verify-email.preheader]]</div>
|
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;">[[email:verify-email.preheader]]</div>
|
||||||
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;"> ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌</div>
|
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;"> ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌</div>
|
||||||
@@ -47,4 +47,4 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<!-- Email Body : END -->
|
<!-- Email Body : END -->
|
||||||
<!-- IMPORT emails/partials/footer.html -->
|
<!-- IMPORT emails/partials/footer.tpl -->
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<!-- IMPORT emails/partials/header.html -->
|
<!-- IMPORT emails/partials/header.tpl -->
|
||||||
<!-- preheader -->
|
<!-- preheader -->
|
||||||
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;">[[email:welcome.preheader]]</div>
|
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;">[[email:welcome.preheader]]</div>
|
||||||
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;"> ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌</div>
|
<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;"> ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌</div>
|
||||||
@@ -47,4 +47,4 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<!-- Email Body : END -->
|
<!-- Email Body : END -->
|
||||||
<!-- IMPORT emails/partials/footer.html -->
|
<!-- IMPORT emails/partials/footer.tpl -->
|
||||||
Reference in New Issue
Block a user