Ghost/core/server/mail/utils.js
Katharina Irrgang 16f5d1fdaf 🎨 add urlFor('admin') and increase usage of urlFor helper (#7935)
refs #7488

- to be able to refactor the url configuration in ghost, we need to go step by step making this possible
- reduce the usage of forceAdminSSL
- add a urlFor('admin') helper, which returns the admin url + path e.g. http://my-blog.com/blog/ghost
- increase usage of urlFor helper
- do not expose getBaseUrl, use urlFor('home') (home === blog)
2017-02-02 18:51:35 +00:00

41 lines
1.2 KiB
JavaScript

var _ = require('lodash').runInContext(),
fs = require('fs'),
Promise = require('bluebird'),
path = require('path'),
htmlToText = require('html-to-text'),
utils = require('../utils'),
templatesDir = path.resolve(__dirname, '..', 'mail', 'templates');
_.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
exports.generateContent = function generateContent(options) {
var defaults,
data;
defaults = {
siteUrl: utils.url.urlFor('home', true)
};
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
};
});
};