mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-30 06:12:03 +03:00
020acb643e
refs https://github.com/TryGhost/Team/issues/993 reqs https://github.com/TryGhost/Admin/pull/2080 - removed labs flag - removed labs flag usage in conditionals - moved labs email template changes into main template
42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
const postEmailSerializer = require('./post-email-serializer');
|
|
|
|
class EmailPreview {
|
|
/**
|
|
* @constructor
|
|
* @param {Object} options
|
|
* @param {String} options.apiVersion
|
|
*/
|
|
constructor({apiVersion}) {
|
|
this.apiVersion = apiVersion;
|
|
}
|
|
|
|
/**
|
|
* @param {Object} post - Post model object instance
|
|
* @param {String} memberSegment - member segment filter
|
|
* @returns {Promise<Object>}
|
|
*/
|
|
async generateEmailContent(post, memberSegment) {
|
|
let emailContent = await postEmailSerializer.serialize(post, {
|
|
isBrowserPreview: true,
|
|
apiVersion: this.apiVersion
|
|
});
|
|
|
|
if (memberSegment) {
|
|
emailContent = postEmailSerializer.renderEmailForSegment(emailContent, memberSegment);
|
|
}
|
|
|
|
const replacements = postEmailSerializer.parseReplacements(emailContent);
|
|
|
|
replacements.forEach((replacement) => {
|
|
emailContent[replacement.format] = emailContent[replacement.format].replace(
|
|
replacement.match,
|
|
replacement.fallback || ''
|
|
);
|
|
});
|
|
|
|
return emailContent;
|
|
}
|
|
}
|
|
|
|
module.exports = EmailPreview;
|