diff --git a/examples/plugins/add_content_encoded_block.js b/examples/plugins/add_content_encoded_block.js index 4f3e1f8..f864f49 100644 --- a/examples/plugins/add_content_encoded_block.js +++ b/examples/plugins/add_content_encoded_block.js @@ -4,9 +4,6 @@ // Stewart let the news slip during a taping of his show today.]]> // 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( diff --git a/examples/plugins/add_itunes_elements.js b/examples/plugins/add_itunes_elements.js index aedeb9b..e91db79 100644 --- a/examples/plugins/add_itunes_elements.js +++ b/examples/plugins/add_itunes_elements.js @@ -14,10 +14,6 @@ // KQED Public Media for Northern CA 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]['#']) { diff --git a/examples/plugins/add_media_thumbnail.js b/examples/plugins/add_media_thumbnail.js index c1291a5..3fe2184 100644 --- a/examples/plugins/add_media_thumbnail.js +++ b/examples/plugins/add_media_thumbnail.js @@ -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 = { diff --git a/examples/plugins/capitalize_title.js b/examples/plugins/capitalize_title.js index 35c8fa5..3801a48 100644 --- a/examples/plugins/capitalize_title.js +++ b/examples/plugins/capitalize_title.js @@ -1,8 +1,4 @@ module.exports = function (item, itemOptions, source) { - if (!item || !itemOptions) { - return; - } - if (itemOptions.title) { itemOptions.title = itemOptions.title.toUpperCase(); } diff --git a/examples/plugins/filter_out_all_articles.js b/examples/plugins/filter_out_all_articles.js index 14d0759..82b7da4 100644 --- a/examples/plugins/filter_out_all_articles.js +++ b/examples/plugins/filter_out_all_articles.js @@ -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; }; \ No newline at end of file diff --git a/examples/plugins/kqed.js b/examples/plugins/kqed.js index 8c0d5b8..5271e39 100644 --- a/examples/plugins/kqed.js +++ b/examples/plugins/kqed.js @@ -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: // The California Report diff --git a/examples/plugins/plugin_template.js b/examples/plugins/plugin_template.js index daef882..cb30b43 100644 --- a/examples/plugins/plugin_template.js +++ b/examples/plugins/plugin_template.js @@ -1,8 +1,4 @@ module.exports = function (item, itemOptions, source) { - if (!item || !itemOptions) { - return; - } - // This plugin does no processing // It's just a template diff --git a/examples/plugins/wfw_slash_comments.js b/examples/plugins/wfw_slash_comments.js index 46ca6fc..9eef2cf 100644 --- a/examples/plugins/wfw_slash_comments.js +++ b/examples/plugins/wfw_slash_comments.js @@ -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"]["#"]}); diff --git a/lib/RssBraider.js b/lib/RssBraider.js index 93fcd48..2359231 100644 --- a/lib/RssBraider.js +++ b/lib/RssBraider.js @@ -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; };