0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00

Reworked EmailContentGenerator to async/await

refs https://github.com/TryGhost/Toolbox/issues/292

- Makes the code more readable
This commit is contained in:
Naz 2022-05-04 15:16:39 +08:00 committed by naz
parent 551bd5e511
commit 2d7bcdf80a

View file

@ -35,20 +35,19 @@ class EmailContentGenerator {
const data = _.defaults(defaults, options.data); const data = _.defaults(defaults, options.data);
// read the proper email body template // read the proper email body template
return fs.readFile(path.join(this.templatesDir, options.template + '.html'), 'utf8') const content = await fs.readFile(path.join(this.templatesDir, options.template + '.html'), 'utf8');
.then(function (content) {
// insert user-specific data into the email
const compiled = _.template(content);
const htmlContent = compiled(data);
// generate a plain-text version of the same email // insert user-specific data into the email
const textContent = htmlToText.fromString(htmlContent); const compiled = _.template(content);
const htmlContent = compiled(data);
return { // generate a plain-text version of the same email
html: htmlContent, const textContent = htmlToText.fromString(htmlContent);
text: textContent
}; return {
}); html: htmlContent,
text: textContent
};
} }
} }