apostrophe-rss
Advanced tools
Comparing version 0.5.4 to 0.5.5
85
index.js
@@ -35,54 +35,53 @@ var feedparser = require('feedparser'); | ||
apos.itemTypes.rss = { | ||
widget: true, | ||
label: 'RSS Feed', | ||
css: 'rss', | ||
icon: 'rss', | ||
sanitize: function(item) { | ||
if (!item.feed.match(/^https?\:\/\//)) { | ||
item.feed = 'http://' + item.feed; | ||
} | ||
item.limit = parseInt(item.limit, 10); | ||
}, | ||
render: function(data) { | ||
return apos.partial('rss', data, __dirname + '/views'); | ||
}, | ||
self.widget = true; | ||
self.label = options.label || 'RSS Feed'; | ||
self.css = options.css || 'rss'; | ||
self.icon = options.icon || 'rss'; | ||
self.sanitize = function(item) { | ||
if (!item.feed.match(/^https?\:\/\//)) { | ||
item.feed = 'http://' + item.feed; | ||
} | ||
item.limit = parseInt(item.limit, 10); | ||
}; | ||
self.renderWidget = function(data) { | ||
return self.render('rss', data); | ||
}; | ||
self.load = function(req, item, callback) { | ||
// Asynchronously load the actual RSS feed | ||
// The properties you add should start with an _ to denote that | ||
// they shouldn't become data attributes or get stored back to MongoDB | ||
item._entries = []; | ||
load: function(req, item, callback) { | ||
item._entries = []; | ||
var now = new Date(); | ||
// Take all properties into account, not just the feed, so the cache | ||
// doesn't prevent us from seeing a change in the limit property right away | ||
var key = JSON.stringify({ feed: item.feed, limit: item.limit }); | ||
if (cache.hasOwnProperty(key) && ((cache[key].when + lifetime) > now.getTime())) { | ||
item._entries = cache[key].data; | ||
return callback(); | ||
} | ||
var now = new Date(); | ||
// Take all properties into account, not just the feed, so the cache | ||
// doesn't prevent us from seeing a change in the limit property right away | ||
var key = JSON.stringify({ feed: item.feed, limit: item.limit }); | ||
if (cache.hasOwnProperty(key) && ((cache[key].when + lifetime) > now.getTime())) { | ||
item._entries = cache[key].data; | ||
return callback(); | ||
} | ||
feedparser.parseUrl(item.feed).on('complete', function(meta, articles) { | ||
articles = articles.slice(0, item.limit); | ||
feedparser.parseUrl(item.feed).on('complete', function(meta, articles) { | ||
articles = articles.slice(0, item.limit); | ||
// map is native in node | ||
item._entries = articles.map(function(article) { | ||
return { | ||
title: article.title, | ||
body: article.description, | ||
date: article.pubDate | ||
}; | ||
}); | ||
// Cache for fast access later | ||
cache[key] = { when: now.getTime(), data: item._entries }; | ||
return callback(); | ||
}).on('error', function(error) { | ||
item._failed = true; | ||
return callback(); | ||
// map is native in node | ||
item._entries = articles.map(function(article) { | ||
return { | ||
title: article.title, | ||
body: article.description, | ||
date: article.pubDate | ||
}; | ||
}); | ||
} | ||
// Cache for fast access later | ||
cache[key] = { when: now.getTime(), data: item._entries }; | ||
return callback(); | ||
}).on('error', function(error) { | ||
item._failed = true; | ||
return callback(); | ||
}); | ||
}; | ||
apos.addWidgetType('rss', self); | ||
return setImmediate(function() { return callback(null); }); | ||
} |
{ | ||
"name": "apostrophe-rss", | ||
"version": "0.5.4", | ||
"version": "0.5.5", | ||
"description": "Adds an RSS feed widget to the Apostrophe content management system", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7679
107