mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-23 22:11:09 +03:00
Reworked EmailContentGenerator to async/await
refs https://github.com/TryGhost/Toolbox/issues/292 - Makes the code more readable
This commit is contained in:
parent
0c2cc2af8a
commit
ca693f79f8
@ -35,20 +35,19 @@ class EmailContentGenerator {
|
||||
const data = _.defaults(defaults, options.data);
|
||||
|
||||
// read the proper email body template
|
||||
return 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);
|
||||
const content = await fs.readFile(path.join(this.templatesDir, options.template + '.html'), 'utf8');
|
||||
|
||||
// generate a plain-text version of the same email
|
||||
const textContent = htmlToText.fromString(htmlContent);
|
||||
// insert user-specific data into the email
|
||||
const compiled = _.template(content);
|
||||
const htmlContent = compiled(data);
|
||||
|
||||
return {
|
||||
html: htmlContent,
|
||||
text: textContent
|
||||
};
|
||||
});
|
||||
// generate a plain-text version of the same email
|
||||
const textContent = htmlToText.fromString(htmlContent);
|
||||
|
||||
return {
|
||||
html: htmlContent,
|
||||
text: textContent
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user