2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00

🐛 Fixed staff emails eventually having invalid styles (#18363)

fixes https://github.com/TryGhost/Ghost/issues/17937

- We used a global Handlebars instance, which means it was reused across
Ghost
- Partials are different between parts of Ghost, that means the partials
were overwritten every time a normal Mailgun email was send
- All staff emails send after a normal newsletter would have invalid
styles because the partials for styles were overwritten
This commit is contained in:
Simon Backx 2023-09-26 16:25:03 +02:00 committed by GitHub
parent fb435cc115
commit 3a5c233122
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 7 deletions

View file

@ -15,7 +15,7 @@ class CommentsServiceEmails {
this.urlService = urlService;
this.urlUtils = urlUtils;
this.Handlebars = require('handlebars');
this.Handlebars = require('handlebars').create();
}
async notifyPostAuthors(comment) {

View file

@ -668,7 +668,7 @@ class EmailRenderer {
}
async renderTemplate(data) {
this.#handlebars = require('handlebars');
this.#handlebars = require('handlebars').create();
// Helpers
this.#handlebars.registerHelper('if', function (conditional, options) {

View file

@ -13,8 +13,9 @@ class StaffServiceEmails {
this.urlUtils = urlUtils;
this.labs = labs;
this.Handlebars = require('handlebars');
this.Handlebars = require('handlebars').create();
this.registerPartials();
this.registerHelpers();
}
async notifyFreeMemberSignup({
@ -478,10 +479,7 @@ class StaffServiceEmails {
});
}
async renderHTML(templateName, data) {
const htmlTemplateSource = await fs.readFile(path.join(__dirname, './email-templates/', `${templateName}.hbs`), 'utf8');
const htmlTemplate = this.Handlebars.compile(Buffer.from(htmlTemplateSource).toString());
registerHelpers() {
this.Handlebars.registerHelper('eq', function (arg, value, options) {
if (arg === value) {
return options.fn(this);
@ -496,6 +494,11 @@ class StaffServiceEmails {
}
return array.slice(0,limit);
});
}
async renderHTML(templateName, data) {
const htmlTemplateSource = await fs.readFile(path.join(__dirname, './email-templates/', `${templateName}.hbs`), 'utf8');
const htmlTemplate = this.Handlebars.compile(Buffer.from(htmlTemplateSource).toString());
let sharedData = {};
if (data.recipient) {