The current implementation of the RSS feed for We Work Meteor (blob used below is here) has an issue when actually used with an RSS reader. Every time a new document is added to a collection, the entire feed is re-published with the whole collection. The reader winds up showing duplicate posts from the last publishing effort.
The solutions I've considered are:
- Using amplify to store a the
pubDate
on the client and then using that to define the earliest post to publish in the feed. Not sure if it's even possible with feed readers. - Add a new property to the collections called
published
and set it totrue
once that particular document is published in a feed. Every time the feed is published it would only findpublished:false
documents. An example is below, but the schemas need to be updated too. - Limiting the
.find()
to just the posts after the last build date. However, that would only show one post. - Limiting the
.find()
to just posts in the last 24/48/72 hours. I don't know that it solves the issue of post duplication though.
RssFeed.publish('jobs', function(query) {
var self = this;
var pubDate = new Date();
var lastBuildDate = new Date();
var mostRecent = Jobs.findOne({}, {sort:{createdAt:-1}});
var secondMostRecent = Jobs.findOne({}, {sort:{createdAt:-1}, skip: 1});
if(mostRecent)
pubDate = mostRecent.createdAt;
if(secondMostRecent)
lastBuildDate = secondMostRecent.createdAt;
self.setValue('title', self.cdata('We Work Meteor - Recent Jobs'));
self.setValue('description', self.cdata('This is a feed of recent jobs posted to We Work Meteor.'));
self.setValue('link', Meteor.absoluteUrl());
self.setValue('lastBuildDate', lastBuildDate);
self.setValue('pubDate', pubDate);
self.setValue('ttl', 1);
Jobs.find({published:false}, {sort:{createdAt:-1}}).forEach(function(job) {
self.addItem({
title: job.title,
description: job.description,
link: Meteor.absoluteUrl('jobs/'+job._id),
guid: Meteor.absoluteUrl('jobs/'+job._id),
pubDate: job.createdAt
});
```javascript
job.update({_id:job._id}, {$set:{published:true}});
});
});
RssFeed.publish('experts', function(query) {
var self = this;
var pubDate = new Date();
var lastBuildDate = new Date();
var mostRecent = Experts.findOne({}, {sort:{createdAt:-1}});
var secondMostRecent = Experts.findOne({}, {sort:{createdAt:-1}, skip: 1});
if(mostRecent)
pubDate = mostRecent.createdAt;
if(secondMostRecent)
lastBuildDate = secondMostRecent.createdAt;
self.setValue('title', self.cdata('We Work Meteor - Recent Experts'));
self.setValue('description', self.cdata('This is a feed of recent experts listed on We Work Meteor.'));
self.setValue('link', Meteor.absoluteUrl());
self.setValue('lastBuildDate', lastBuildDate);
self.setValue('pubDate', pubDate);
self.setValue('ttl', 1);
Experts.find({published:false}, {sort:{createdAt:-1}}).forEach(function(expert) {
self.addItem({
title: expert.title,
description: expert.description,
link: Meteor.absoluteUrl('experts/'+expert._id),
guid: Meteor.absoluteUrl('experts/'+expert._id),
pubDate: expert.createdAt
});
expert.update({_id:expert._id}, {$set:{published:true}});
});
});