RSS-26 - WIP restructuring the way plugins work to allow skipping of items/articles that don't meet criteria

This commit is contained in:
Kip Gebhardt 2015-06-10 17:10:50 -07:00
parent 8dcca51955
commit 66e6cb2d64
6 changed files with 25 additions and 6 deletions

View File

@ -203,7 +203,7 @@ RssBraider.prototype.processItem = function (item, source, feed_name) {
// Run the plugins specified by the "plugins" section of the
// feed config file to build out any custom elements or
// do transforms
self.runPlugins(item, itemOptions, source, feed_name);
itemOptions = self.runPlugins(item, itemOptions, source, feed_name);
return itemOptions;
};
@ -211,16 +211,29 @@ RssBraider.prototype.processItem = function (item, source, feed_name) {
RssBraider.prototype.runPlugins = function (item, itemOptions, source, feed_name) {
var self = this,
feed = self.feeds[feed_name] || {},
plugins_list = feed.plugins || [];
plugins_list = feed.plugins || [],
ret_val;
// Process the item through the desired feed plugins
plugins_list.forEach(function(plugin_name){
// 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]) {
// logger.info("DEBUG runPlugins running " + plugin_name + " for item " + item.guid + " in feed: " + feed.meta.title);
self.plugins[plugin_name](item, itemOptions, source);
logger.info("DEBUG runPlugins running " + plugin_name + " for item " + item.guid + " in feed: " + feed.meta.title);
itemOptions = self.plugins[plugin_name](item, itemOptions, source);
} else {
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) {
logger.info("Plugin rejected item", plugin_name, item.guid, feed.meta.title);
break;
} else {
logger.info("Plugin completed", plugin_name, item.guid, feed.meta.title);
}
}
return itemOptions;
};
// Dedupe articles in node-rss itemOptions format

View File

@ -51,4 +51,5 @@ module.exports = function (item, itemOptions, source) {
}
}
}
return itemOptions;
};

View File

@ -17,4 +17,5 @@ module.exports = function (item, itemOptions, source) {
}
);
}
return itemOptions;
};

View File

@ -36,4 +36,5 @@ module.exports = function (item, itemOptions, source) {
{ 'kqed:feed_url': item.feed_url }
);
}
return itemOptions;
};

View File

@ -82,4 +82,6 @@ module.exports = function (item, itemOptions, source) {
}
});
}
return itemOptions;
};

View File

@ -11,4 +11,5 @@ module.exports = function (item, itemOptions, source) {
if (item["slash:comments"] && item["slash:comments"]["#"]){
itemOptions.custom_elements.push({ "slash:comments": item["slash:comments"]["#"]});
}
return itemOptions;
};