2019-11-05 08:14:54 +03:00
|
|
|
const juice = require('juice');
|
|
|
|
const template = require('./template');
|
|
|
|
const settingsCache = require('../../services/settings/cache');
|
|
|
|
const urlUtils = require('../../lib/url-utils');
|
2019-11-06 08:06:24 +03:00
|
|
|
const moment = require('moment');
|
2019-11-05 08:14:54 +03:00
|
|
|
|
|
|
|
const getSite = () => {
|
|
|
|
return Object.assign({}, settingsCache.getPublic(), {
|
|
|
|
url: urlUtils.urlFor('home', true)
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const serialize = (post) => {
|
2019-11-06 08:06:24 +03:00
|
|
|
post.published_at = post.published_at ? moment(post.published_at).format('DD MMM YYYY') : moment().format('DD MMM YYYY');
|
2019-11-06 14:03:28 +03:00
|
|
|
post.authors = post.authors && post.authors.map(author => author.name).join(',');
|
2019-11-06 14:32:11 +03:00
|
|
|
if (post.posts_meta) {
|
|
|
|
post.email_subject = post.posts_meta.email_subject;
|
|
|
|
}
|
2019-11-05 08:14:54 +03:00
|
|
|
return {
|
|
|
|
subject: post.email_subject || post.title,
|
2019-11-05 11:04:48 +03:00
|
|
|
html: juice(template({post, site: getSite()})),
|
|
|
|
plaintext: post.plaintext
|
2019-11-05 08:14:54 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
serialize: serialize
|
|
|
|
};
|