mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-23 10:53:34 +03:00
bd597db829
- This is part of the quest to separate the frontend and server & get rid of all the places where there are cross-requires - At the moment the settings cache is one big shared cache used by the frontend and server liberally - This change doesn't really solve the fundamental problems, as we still depend on events, and requires from inside frontend - However it allows us to control the misuse slightly better by getting rid of restricted requires and turning on that eslint ruleset
35 lines
1.2 KiB
JavaScript
35 lines
1.2 KiB
JavaScript
const _ = require('lodash').runInContext();
|
|
const fs = require('fs-extra');
|
|
const path = require('path');
|
|
const htmlToText = require('html-to-text');
|
|
const urlUtils = require('../../../shared/url-utils');
|
|
const settingsCache = require('../../../shared/settings-cache');
|
|
const templatesDir = path.resolve(__dirname, '..', 'mail', 'templates');
|
|
|
|
_.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
|
|
|
|
exports.generateContent = function generateContent(options) {
|
|
const defaults = {
|
|
siteUrl: urlUtils.urlFor('home', true),
|
|
siteTitle: settingsCache.get('title')
|
|
};
|
|
|
|
const data = _.defaults(defaults, options.data);
|
|
|
|
// read the proper email body template
|
|
return fs.readFile(path.join(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
|
|
const textContent = htmlToText.fromString(htmlContent);
|
|
|
|
return {
|
|
html: htmlContent,
|
|
text: textContent
|
|
};
|
|
});
|
|
};
|