RSS feed for top, best views & feed url bug fix

This commit is contained in:
Delgermurun 2014-11-17 21:14:56 +08:00
parent 77d21ea139
commit d89687b25e
2 changed files with 32 additions and 7 deletions

View file

@ -8,7 +8,29 @@ Meteor.startup(function () {
where: 'server',
path: '/feed.xml',
action: function() {
this.response.write(servePostRSS());
this.response.write(servePostRSS('new'));
this.response.end();
}
});
// Top Post RSS
this.route('feed', {
where: 'server',
path: 'rss/posts/top.xml',
action: function() {
this.response.write(servePostRSS('top'));
this.response.end();
}
});
// Best Post RSS
this.route('feed', {
where: 'server',
path: 'rss/posts/best.xml',
action: function() {
this.response.write(servePostRSS('best'));
this.response.end();
}
});

View file

@ -1,19 +1,22 @@
var RSS = Npm.require('rss');
var getMeta = function() {
var getMeta = function(url) {
return {
title: getSetting('title'),
description: getSetting('tagline'),
feed_url: Meteor.absoluteUrl()+'feed.xml',
feed_url: Meteor.absoluteUrl()+url,
site_url: Meteor.absoluteUrl(),
image_url: Meteor.absoluteUrl()+'img/favicon.png',
};
};
servePostRSS = function() {
var feed = new RSS(getMeta());
servePostRSS = function(view) {
var feed = new RSS(getMeta('feed.xml'));
Posts.find(getPostsParameters({}).find, {sort: {postedAt: -1}, limit: 20}).forEach(function(post) {
var params = getPostsParameters({view: view, limit: 20});
delete params['options']['sort']['sticky'];
Posts.find(params.find, params.options).forEach(function(post) {
var description = !!post.body ? post.body+'</br></br>' : '';
feed.item({
title: post.title,
@ -29,7 +32,7 @@ servePostRSS = function() {
};
serveCommentRSS = function() {
var feed = new RSS(getMeta());
var feed = new RSS(getMeta('rss/comments.xml'));
Comments.find({isDeleted: {$ne: true}}, {sort: {postedAt: -1}, limit: 20}).forEach(function(comment) {
post = Posts.findOne(comment.postId);