mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 11:34:24 +03:00
e91e9eadac
no issue - in preparation for subscribers V2 - do not implement code in index.js - create mail utils
41 lines
1.2 KiB
JavaScript
41 lines
1.2 KiB
JavaScript
var _ = require('lodash').runInContext(),
|
|
fs = require('fs'),
|
|
Promise = require('bluebird'),
|
|
path = require('path'),
|
|
htmlToText = require('html-to-text'),
|
|
config = require('../config'),
|
|
templatesDir = path.resolve(__dirname, '..', 'mail', 'templates');
|
|
|
|
_.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
|
|
|
|
exports.generateContent = function generateContent(options) {
|
|
var defaults,
|
|
data;
|
|
|
|
defaults = {
|
|
siteUrl: config.forceAdminSSL ? (config.urlSSL || config.url) : config.url
|
|
};
|
|
|
|
data = _.defaults(defaults, options.data);
|
|
|
|
// read the proper email body template
|
|
return Promise.promisify(fs.readFile)(path.join(templatesDir, options.template + '.html'), 'utf8')
|
|
.then(function (content) {
|
|
var compiled,
|
|
htmlContent,
|
|
textContent;
|
|
|
|
// insert user-specific data into the email
|
|
compiled = _.template(content);
|
|
htmlContent = compiled(data);
|
|
|
|
// generate a plain-text version of the same email
|
|
textContent = htmlToText.fromString(htmlContent);
|
|
|
|
return {
|
|
html: htmlContent,
|
|
text: textContent
|
|
};
|
|
});
|
|
};
|