postsCursor.forEach((post) => { const description = !!post.body ? post.body+'</br></br>' : ''; const feedItem = { title: post.title, description: description + '<a href="' + Posts.getPageUrl(post, true) + '">Discuss</a>', author: post.author, date: post.postedAt, guid: post._id, url: (getSetting("RSSLinksPointTo", "link") === "link") ? Posts.getLink(post) : Posts.getPageUrl(post, true) }; if (post.thumbnailUrl) { const url = Utils.addHttp(post.thumbnailUrl); feedItem.custom_elements = [{"imageUrl":url}, {"content": url}]; } feed.item(feedItem); });
posts.forEach(function (post, index) { // get author of the current post var postUser = Users.findOne(post.userId); // the naked post object as stored in the database is missing a few properties, so let's add them var properties = _.extend(post, { authorName: Posts.getAuthorName(post), postLink: Posts.getLink(post, true), profileUrl: Users.getProfileUrl(postUser, true), postPageLink: Posts.getPageUrl(post, true), date: moment(post.postedAt).format("MMMM D YYYY"), authorAvatarUrl: Users.avatar.getUrl(postUser), emailShareUrl: Posts.getEmailShareUrl(post), twitterShareUrl: Posts.getTwitterShareUrl(post), facebookShareUrl: Posts.getFacebookShareUrl(post) }); // if post author's avatar returns an error, remove it from properties object try { HTTP.get(post.authorAvatarUrl); } catch (error) { post.authorAvatarUrl = false; } // trim the body and remove any HTML tags if (post.body) { properties.body = Utils.trimHTML(post.htmlBody, excerptLength); } // if post has comments if (post.commentCount > 0) { // get the two highest-scoring comments properties.popularComments = Comments.find({postId: post._id}, {sort: {score: -1}, limit: 2, transform: function (comment) { // get comment author var user = Users.findOne(comment.userId); // add properties to comment comment.body = Utils.trimHTML(comment.htmlBody, excerptLength); comment.authorProfileUrl = Users.getProfileUrl(user, true); comment.authorAvatarUrl = Users.avatar.getUrl(user); try { HTTP.get(comment.authorAvatarUrl); } catch (error) { comment.authorAvatarUrl = false; } return comment; }}).fetch(); } // if post has an URL, at the link domain as a property if(post.url) { properties.domain = Utils.getDomain(post.url); } // if post has a thumbnail, add the thumbnail URL as a property if (properties.thumbnailUrl) { properties.thumbnailUrl = Utils.addHttp(properties.thumbnailUrl); } // if post has categories, add them if (post.categories) { properties.categories = post.categories.map(categoryID => { const category = Categories.findOne(categoryID); if (category) { return { name: category.name, url: Categories.getUrl(category, true) } } }); } // console.log(properties) // generate post item HTML and add it to the postsHTML string postsHTML += VulcanEmail.getTemplate('postItem')(properties); });