Vulcan/packages/telescope-rss/lib/server/rss.js

52 lines
1.4 KiB
JavaScript
Raw Normal View History

2014-08-28 13:39:30 +09:00
var RSS = Npm.require('rss');
var getMeta = function(url) {
var siteUrl = getSetting('siteUrl', Meteor.absoluteUrl());
2014-09-24 17:51:21 +08:00
return {
title: getSetting('title'),
description: getSetting('tagline'),
feed_url: siteUrl+url,
site_url: siteUrl,
image_url: siteUrl+'img/favicon.png',
2014-09-24 17:51:21 +08:00
};
};
2014-11-18 09:45:33 +08:00
servePostRSS = function(view, url) {
var feed = new RSS(getMeta(url));
2014-09-24 17:51:21 +08:00
var params = getPostsParameters({view: view, limit: 20});
delete params['options']['sort']['sticky'];
Posts.find(params.find, params.options).forEach(function(post) {
2014-08-27 09:25:05 +09:00
var description = !!post.body ? post.body+'</br></br>' : '';
feed.item({
2014-05-16 09:19:35 +09:00
title: post.title,
2014-08-27 09:25:05 +09:00
description: description+'<a href="'+getPostUrl(post._id)+'">Discuss</a>',
author: post.author,
date: post.postedAt,
url: getPostLink(post),
guid: post._id
});
});
2014-09-24 17:51:21 +08:00
return feed.xml();
};
serveCommentRSS = function() {
var feed = new RSS(getMeta(Router.routes['rss_comments'].path()));
2014-09-24 17:51:21 +08:00
Comments.find({isDeleted: {$ne: true}}, {sort: {postedAt: -1}, limit: 20}).forEach(function(comment) {
post = Posts.findOne(comment.postId);
feed.item({
title: 'Comment on '+post.title,
description: comment.body+'</br></br>'+'<a href="'+getPostCommentUrl(post._id, comment._id)+'">Discuss</a>',
author: comment.author,
date: comment.postedAt,
url: getCommentUrl(comment._id),
guid: comment._id
});
});
return feed.xml();
};