mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05: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:
parent
fb435cc115
commit
3a5c233122
3 changed files with 10 additions and 7 deletions
|
@ -15,7 +15,7 @@ class CommentsServiceEmails {
|
||||||
this.urlService = urlService;
|
this.urlService = urlService;
|
||||||
this.urlUtils = urlUtils;
|
this.urlUtils = urlUtils;
|
||||||
|
|
||||||
this.Handlebars = require('handlebars');
|
this.Handlebars = require('handlebars').create();
|
||||||
}
|
}
|
||||||
|
|
||||||
async notifyPostAuthors(comment) {
|
async notifyPostAuthors(comment) {
|
||||||
|
|
|
@ -668,7 +668,7 @@ class EmailRenderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
async renderTemplate(data) {
|
async renderTemplate(data) {
|
||||||
this.#handlebars = require('handlebars');
|
this.#handlebars = require('handlebars').create();
|
||||||
|
|
||||||
// Helpers
|
// Helpers
|
||||||
this.#handlebars.registerHelper('if', function (conditional, options) {
|
this.#handlebars.registerHelper('if', function (conditional, options) {
|
||||||
|
|
|
@ -13,8 +13,9 @@ class StaffServiceEmails {
|
||||||
this.urlUtils = urlUtils;
|
this.urlUtils = urlUtils;
|
||||||
this.labs = labs;
|
this.labs = labs;
|
||||||
|
|
||||||
this.Handlebars = require('handlebars');
|
this.Handlebars = require('handlebars').create();
|
||||||
this.registerPartials();
|
this.registerPartials();
|
||||||
|
this.registerHelpers();
|
||||||
}
|
}
|
||||||
|
|
||||||
async notifyFreeMemberSignup({
|
async notifyFreeMemberSignup({
|
||||||
|
@ -478,10 +479,7 @@ class StaffServiceEmails {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async renderHTML(templateName, data) {
|
registerHelpers() {
|
||||||
const htmlTemplateSource = await fs.readFile(path.join(__dirname, './email-templates/', `${templateName}.hbs`), 'utf8');
|
|
||||||
const htmlTemplate = this.Handlebars.compile(Buffer.from(htmlTemplateSource).toString());
|
|
||||||
|
|
||||||
this.Handlebars.registerHelper('eq', function (arg, value, options) {
|
this.Handlebars.registerHelper('eq', function (arg, value, options) {
|
||||||
if (arg === value) {
|
if (arg === value) {
|
||||||
return options.fn(this);
|
return options.fn(this);
|
||||||
|
@ -496,6 +494,11 @@ class StaffServiceEmails {
|
||||||
}
|
}
|
||||||
return array.slice(0,limit);
|
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 = {};
|
let sharedData = {};
|
||||||
if (data.recipient) {
|
if (data.recipient) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue