2016-08-08 11:18:21 +09:00
|
|
|
import Telescope from 'meteor/nova:lib';
|
2016-06-23 12:17:39 +09:00
|
|
|
import Posts from "meteor/nova:posts";
|
|
|
|
import Comments from "meteor/nova:comments";
|
|
|
|
|
2016-07-05 16:55:11 +09:00
|
|
|
const RSS = Npm.require('rss');
|
2015-04-22 07:50:11 +09:00
|
|
|
|
2016-07-05 16:55:11 +09:00
|
|
|
Posts.views.rss = Posts.views.new; // default to "new" view for RSS feed
|
|
|
|
|
|
|
|
const getMeta = function (url) {
|
2016-04-09 10:45:27 +09:00
|
|
|
var siteUrl = Telescope.settings.get('siteUrl', Meteor.absoluteUrl());
|
2015-04-22 07:50:11 +09:00
|
|
|
return {
|
2016-04-09 10:45:27 +09:00
|
|
|
title: Telescope.settings.get('title'),
|
|
|
|
description: Telescope.settings.get('tagline'),
|
2015-04-22 07:50:11 +09:00
|
|
|
feed_url: siteUrl+url,
|
|
|
|
site_url: siteUrl,
|
2015-07-18 11:44:53 +09:00
|
|
|
image_url: siteUrl+'img/favicon.png'
|
2015-04-22 07:50:11 +09:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-07-05 16:55:11 +09:00
|
|
|
const servePostRSS = function (terms, url) {
|
2015-04-22 07:50:11 +09:00
|
|
|
var feed = new RSS(getMeta(url));
|
|
|
|
|
2016-04-09 10:45:27 +09:00
|
|
|
var parameters = Posts.parameters.get(terms);
|
|
|
|
delete parameters['options']['sort']['sticky'];
|
2015-04-22 07:50:11 +09:00
|
|
|
|
2016-04-09 10:45:27 +09:00
|
|
|
const postsCursor = Posts.find(parameters.selector, parameters.options);
|
|
|
|
|
|
|
|
postsCursor.forEach(function(post) {
|
2015-07-18 11:44:53 +09:00
|
|
|
|
2015-04-22 07:50:11 +09:00
|
|
|
var description = !!post.body ? post.body+'</br></br>' : '';
|
2015-07-18 12:12:55 +09:00
|
|
|
var feedItem = {
|
|
|
|
title: post.title,
|
|
|
|
description: description + '<a href="' + post.getPageUrl(true) + '">Discuss</a>',
|
|
|
|
author: post.author,
|
|
|
|
date: post.postedAt,
|
|
|
|
guid: post._id,
|
2016-04-09 10:45:27 +09:00
|
|
|
url: (Telescope.settings.get("RSSLinksPointTo", "link") === "link") ? Posts.getLink(post) : Posts.getPageUrl(post, true)
|
2015-07-18 11:44:53 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
if (post.thumbnailUrl) {
|
2015-07-27 15:15:38 +09:00
|
|
|
var url = Telescope.utils.addHttp(post.thumbnailUrl);
|
|
|
|
feedItem.custom_elements = [{"imageUrl":url}, {"content": url}];
|
2015-07-18 11:44:53 +09:00
|
|
|
}
|
|
|
|
|
2015-07-18 12:12:55 +09:00
|
|
|
feed.item(feedItem);
|
2015-04-22 07:50:11 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
return feed.xml();
|
|
|
|
};
|
|
|
|
|
2016-07-05 16:55:11 +09:00
|
|
|
const serveCommentRSS = function (terms, url) {
|
2015-09-18 16:27:59 +09:00
|
|
|
var feed = new RSS(getMeta(url));
|
2015-04-22 07:50:11 +09: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="'+Telescope.utils.getPostCommentUrl(post._id, comment._id)+'">Discuss</a>',
|
|
|
|
author: comment.author,
|
|
|
|
date: comment.postedAt,
|
2015-06-19 11:52:57 +09:00
|
|
|
url: comment.getPageUrl(true),
|
2015-04-22 07:50:11 +09:00
|
|
|
guid: comment._id
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return feed.xml();
|
|
|
|
};
|
2016-07-05 16:55:11 +09:00
|
|
|
|
|
|
|
export {servePostRSS, serveCommentRSS};
|