RSS-26 - changing plugin return of null to -1 for filtering out of an item.

This commit is contained in:
Kip Gebhardt 2015-06-11 18:35:52 -07:00
parent a12a8e4675
commit dbbcba5d1a
9 changed files with 19 additions and 33 deletions

View File

@ -4,9 +4,6 @@
// <![CDATA[<p>Stewart let the news slip during a taping of his show today.]]>
// </content:encoded>
module.exports = function (item, itemOptions, source) {
if (!item || !itemOptions) {
return;
}
if (item["content:encoded"] && item["content:encoded"]["#"]){
var content_encoded = item["content:encoded"]["#"];
itemOptions.custom_elements.push(

View File

@ -14,10 +14,6 @@
// <itunes:subtitle>KQED Public Media for Northern CA</itunes:subtitle>
module.exports = function (item, itemOptions, source) {
if (!item || !itemOptions) {
return;
}
var pass_through_arr = ['itunes:summary', 'itunes:author', 'itunes:explicit', ];
pass_through_arr.forEach(function(element){
if (item[element] && item[element]['#']) {

View File

@ -6,10 +6,6 @@
// 'media:thumbnail'
var _ = require('lodash');
module.exports = function (item, itemOptions, source) {
if (!item || !itemOptions) {
return;
}
var thumbnail;
if (item['media:thumbnail'] && item['media:thumbnail']['#']) {
thumbnail = {

View File

@ -1,8 +1,4 @@
module.exports = function (item, itemOptions, source) {
if (!item || !itemOptions) {
return;
}
if (itemOptions.title) {
itemOptions.title = itemOptions.title.toUpperCase();
}

View File

@ -3,6 +3,6 @@ module.exports = function (item, itemOptions, source) {
return;
}
// This plugin removes all items by returning null instead of the processed itemOptions
return null;
// This plugin removes all items by returning -1 instead of the processed itemOptions
return -1;
};

View File

@ -1,8 +1,5 @@
// define kqed source
module.exports = function (item, itemOptions, source) {
if (!item || !itemOptions || !source) {
return;
}
// Look for kqed namespace elements in source and add as custom elements for item
// Ex:
// <kqed:fullname>The California Report</kqed:fullname>

View File

@ -1,8 +1,4 @@
module.exports = function (item, itemOptions, source) {
if (!item || !itemOptions) {
return;
}
// This plugin does no processing
// It's just a template

View File

@ -1,7 +1,4 @@
module.exports = function (item, itemOptions, source) {
if (!item || !itemOptions) {
return;
}
// wfw
if (item["wfw:commentrss"] && item["wfw:commentrss"]["#"]){
itemOptions.custom_elements.push({ "wfw:commentRss": item["wfw:commentrss"]["#"]});

View File

@ -206,32 +206,43 @@ RssBraider.prototype.processItem = function (item, source, feed_name) {
// Run the plugins specified by the "plugins" section of the
// feed .js file to build out any custom elements or
// do transforms/filters
itemOptions = self.runPlugins(item, itemOptions, source, feed_name);
var filteredItemOptions = self.runPlugins(item, itemOptions, source, feed_name);
return itemOptions;
return filteredItemOptions;
};
RssBraider.prototype.runPlugins = function (item, itemOptions, source, feed_name) {
var self = this,
feed = self.feeds[feed_name] || {},
plugins_list = feed.plugins || [],
ret_val;
ret_val,
filteredItemOptions;
// Process the item through the desired feed plugins
// plugins_list.forEach(function(plugin_name){
for (var i = 0; i < plugins_list.length; i++) {
var plugin_name = plugins_list[i];
if (self.plugins[plugin_name]) {
itemOptions = self.plugins[plugin_name](item, itemOptions, source);
filteredItemOptions = self.plugins[plugin_name](item, itemOptions, source);
} else {
self.logger.error("A plugin named '" + plugin_name + "' hasn't been registered");
}
// If itemOptions comes back null, skip this item as one of the plugins decided to toss it
if (itemOptions === null) {
// A plugin returning -1 means skip this item
if (filteredItemOptions === -1) {
var short_title = item.title.substring(0,25);
self.logger.debug("Plugin '" + plugin_name + "' filtered item from feed '" + feed.meta.title + "'", item.guid);
itemOptions = null;
break;
}
// Check that the plugin didn't just return null or undef, which would be bad.
if (!filteredItemOptions) {
self.logger.debug("Plugin '" + plugin_name + "' failed to return itemOptions for feed:'" + feed.meta.title + "'", item.guid);
filteredItemOptions = itemOptions; // Reset
}
// Prepare for next plugin.
itemOptions = filteredItemOptions;
}
return itemOptions;
};