From a98553ecc5d4197586691b1e8a54733e1ed4ed64 Mon Sep 17 00:00:00 2001 From: Kip Gebhardt Date: Thu, 28 May 2015 18:18:07 -0700 Subject: [PATCH] More cleanud and documentation --- README.md | 42 +++++++++++++++++++++++++++++++----------- examples/simple.js | 31 +++++++++++++++++++++++++++---- lib/RssBraider.js | 2 +- 3 files changed, 59 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 5e1ba16..61124f0 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [![Build Status](https://travis-ci.org/KQED/rss-braider.svg?branch=master)](https://travis-ci.org/KQED/rss-braider) ## Summary -Braid/aggregate one or more RSS feeds (file or url) into a single feed (RSS or JSON output). Process resulting feed through specified plugins. +Braid/aggregate one or more RSS feeds (file or url) into a single feed (RSS or JSON output). Process resulting feed through specified plugins. Automatic deduplication ## Installation ``` @@ -13,30 +13,50 @@ npm install rss-braider ## Examples ``` $ cd examples -$ node simple.js (combines 3 sources) +$ node simple.js (combines 3 sources) $ node plugins.js (combines 3 sources and runs a transformation plugin) ``` ## Code Example ```js var RssBraider = require('rss-braider'), - feed_obj = {}; + feeds = {}; -// Build feed options -feed_obj.filefeed = require("./config/feed").feed; +// Pull feeds from config files: +// feeds.simple_test_feed = require("./config/feed").feed; +// Or define in-line +feeds.simple_test_feed = { + "feed_name" : "feed", + "default_count" : 1, + "no_cdata_fields" : [], // Don't wrap these fields in CDATA tags + "meta" : { + "title": "NPR Braided Feed", + "description": "This is a test of two NPR" + }, + "sources" : [ + { + "name" : "NPR Headlines", + "count" : 2, + "feed_url" : "http://www.npr.org/rss/rss.php?id=1001", + }, + { + "name" : "NPR Sports", + "count" : 2, + "feed_url" : "http://www.npr.org/rss/rss.php?id=1055" + } + ] +}; var braider_options = { - feeds : feed_obj, + feeds : feeds, indent : " ", date_sort_order : "desc" // Newest first }; var rss_braider = RssBraider.createClient(braider_options); -// braid 'filefeed' sources together and output in RSS format -rss_braider.processFeed('filefeed', 'rss', function(err, data){ +// Output braided feed as rss. use 'json' for JSON output. +rss_braider.processFeed('simple_test_feed', 'rss', function(err, data){ if (err) { return console.log(err); } console.log(data); }); -``` - - +``` \ No newline at end of file diff --git a/examples/simple.js b/examples/simple.js index 9ecf3e9..5d3101c 100644 --- a/examples/simple.js +++ b/examples/simple.js @@ -1,15 +1,38 @@ var RssBraider = require('../index'), - feed_obj = {}; + feeds = {}; -feed_obj.filefeed = require("./config/feed").feed; +// Pull feeds from config files: +// feeds.simple_test_feed = require("./config/feed").feed; +// Or define in-line +feeds.simple_test_feed = { + "feed_name" : "feed", + "default_count" : 1, + "no_cdata_fields" : [], // Don't wrap these fields in CDATA tags + "meta" : { + "title": "NPR Braided Feed", + "description": "This is a test of two NPR" + }, + "sources" : [ + { + "name" : "NPR Headlines", + "count" : 2, + "feed_url" : "http://www.npr.org/rss/rss.php?id=1001", + }, + { + "name" : "NPR Sports", + "count" : 2, + "feed_url" : "http://www.npr.org/rss/rss.php?id=1055" + } + ] +}; var braider_options = { - feeds : feed_obj, + feeds : feeds, indent : " ", date_sort_order : "desc" // Newest first }; var rss_braider = RssBraider.createClient(braider_options); -rss_braider.processFeed('filefeed', 'rss', function(err, data){ +rss_braider.processFeed('simple_test_feed', 'rss', function(err, data){ if (err) { return console.log(err); } diff --git a/lib/RssBraider.js b/lib/RssBraider.js index 5e3a213..2937669 100644 --- a/lib/RssBraider.js +++ b/lib/RssBraider.js @@ -42,7 +42,6 @@ RssBraider.prototype.loadPlugins = function () { // logger.info("plugin registered:", plugin_name); }); }); - }; RssBraider.prototype.feedExists = function (feed_name) { @@ -227,6 +226,7 @@ RssBraider.prototype.runPlugins = function (item, itemOptions, source, feed_name // Dedupe articles in node-rss itemOptions format // Accepts an array of fields to dedupe on, or does a basic uniq // operation on the articles array +// TODO, make this a plugin? RssBraider.prototype.dedupe = function(articles_arr, fields){ if ( !fields || fields.length < 1 ) { return _.uniq(articles_arr);