mirror of
https://gitlab.silvrtree.co.uk/martind2000/rss-braider.git
synced 2025-02-11 10:19:15 +00:00
More cleanud and documentation
This commit is contained in:
parent
216e8d5012
commit
a98553ecc5
40
README.md
40
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)
|
[![Build Status](https://travis-ci.org/KQED/rss-braider.svg?branch=master)](https://travis-ci.org/KQED/rss-braider)
|
||||||
|
|
||||||
## Summary
|
## 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
|
## Installation
|
||||||
```
|
```
|
||||||
@ -13,30 +13,50 @@ npm install rss-braider
|
|||||||
## Examples
|
## Examples
|
||||||
```
|
```
|
||||||
$ cd 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)
|
$ node plugins.js (combines 3 sources and runs a transformation plugin)
|
||||||
```
|
```
|
||||||
## Code Example
|
## Code Example
|
||||||
```js
|
```js
|
||||||
var RssBraider = require('rss-braider'),
|
var RssBraider = require('rss-braider'),
|
||||||
feed_obj = {};
|
feeds = {};
|
||||||
|
|
||||||
// Build feed options
|
// Pull feeds from config files:
|
||||||
feed_obj.filefeed = require("./config/feed").feed;
|
// 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 = {
|
var braider_options = {
|
||||||
feeds : feed_obj,
|
feeds : feeds,
|
||||||
indent : " ",
|
indent : " ",
|
||||||
date_sort_order : "desc" // Newest first
|
date_sort_order : "desc" // Newest first
|
||||||
};
|
};
|
||||||
var rss_braider = RssBraider.createClient(braider_options);
|
var rss_braider = RssBraider.createClient(braider_options);
|
||||||
|
|
||||||
// braid 'filefeed' sources together and output in RSS format
|
// Output braided feed as rss. use 'json' for JSON output.
|
||||||
rss_braider.processFeed('filefeed', 'rss', function(err, data){
|
rss_braider.processFeed('simple_test_feed', 'rss', function(err, data){
|
||||||
if (err) {
|
if (err) {
|
||||||
return console.log(err);
|
return console.log(err);
|
||||||
}
|
}
|
||||||
console.log(data);
|
console.log(data);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,15 +1,38 @@
|
|||||||
var RssBraider = require('../index'),
|
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 = {
|
var braider_options = {
|
||||||
feeds : feed_obj,
|
feeds : feeds,
|
||||||
indent : " ",
|
indent : " ",
|
||||||
date_sort_order : "desc" // Newest first
|
date_sort_order : "desc" // Newest first
|
||||||
};
|
};
|
||||||
var rss_braider = RssBraider.createClient(braider_options);
|
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) {
|
if (err) {
|
||||||
return console.log(err);
|
return console.log(err);
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,6 @@ RssBraider.prototype.loadPlugins = function () {
|
|||||||
// logger.info("plugin registered:", plugin_name);
|
// logger.info("plugin registered:", plugin_name);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
RssBraider.prototype.feedExists = function (feed_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
|
// Dedupe articles in node-rss itemOptions format
|
||||||
// Accepts an array of fields to dedupe on, or does a basic uniq
|
// Accepts an array of fields to dedupe on, or does a basic uniq
|
||||||
// operation on the articles array
|
// operation on the articles array
|
||||||
|
// TODO, make this a plugin?
|
||||||
RssBraider.prototype.dedupe = function(articles_arr, fields){
|
RssBraider.prototype.dedupe = function(articles_arr, fields){
|
||||||
if ( !fields || fields.length < 1 ) {
|
if ( !fields || fields.length < 1 ) {
|
||||||
return _.uniq(articles_arr);
|
return _.uniq(articles_arr);
|
||||||
|
Loading…
Reference in New Issue
Block a user