Vulcan/packages/telescope-digest/lib/server/build_campaign.js

40 lines
1.2 KiB
JavaScript
Raw Normal View History

2014-08-02 11:00:28 +09:00
buildCampaign = function (postsCount) {
// Every x days, find the top y posts that haven't yet been part of a digest,
// build a template around them, and pass the whole thing on to sender function.
var params = getParameters({
view: 'campaign',
limit: postsCount
});
var campaignPosts = Posts.find(params.find, params.options).fetch();
// iterate through posts and pass each of them through a handlebars template
var postsHTML = _.map(campaignPosts, function(post){
// the naked post object as stored in the database is missing a few properties, so let's add them
var properties = _.extend(post, {
authorName: getAuthorName(post),
userAvatar: getAvatarUrl(Meteor.users.findOne(post.userId)),
cleanHeadline:encodeURIComponent(post.title),
cleanURL:encodeURIComponent(post.url),
outgoingUrl: getOutgoingUrl(post.url)
});
if(post.url)
properties.domain = getDomain(post.url)
2014-08-02 16:11:54 +09:00
var template = Handlebars.templates[getTemplate('emailPostItem')](properties);
2014-08-02 11:00:28 +09:00
return template;
}).join('');
2014-08-02 16:11:54 +09:00
var emailHTML = buildEmailTemplate(postsHTML)
// console.log(emailHTML)
return emailHTML
2014-08-02 11:00:28 +09:00
}
Meteor.methods({
testBuildCampaign: function (postsCount) {
buildCampaign(postsCount);
}
})