mirror of
https://gitlab.silvrtree.co.uk/martind2000/rss-braider.git
synced 2025-02-10 18:59:17 +00:00
RSS-26: moving example code around. Updates to README
This commit is contained in:
parent
85bdaf619a
commit
7aeed75a4e
31
README.md
31
README.md
@ -16,7 +16,7 @@ $ cd examples
|
||||
$ node simple.js (combines 3 sources)
|
||||
$ node plugins.js (combines 3 sources and runs a transformation plugin)
|
||||
```
|
||||
## Code Example
|
||||
### Code Example
|
||||
```js
|
||||
var RssBraider = require('rss-braider'),
|
||||
feeds = {};
|
||||
@ -48,10 +48,14 @@ feeds.simple_test_feed = {
|
||||
var braider_options = {
|
||||
feeds : feeds,
|
||||
indent : " ",
|
||||
date_sort_order : "desc" // Newest first
|
||||
date_sort_order : "desc", // Newest first
|
||||
log_level : "debug"
|
||||
};
|
||||
var rss_braider = RssBraider.createClient(braider_options);
|
||||
|
||||
// Override logging level (debug, info, warn, err, off)
|
||||
rss_braider.logger.level('off');
|
||||
|
||||
// Output braided feed as rss. use 'json' for JSON output.
|
||||
rss_braider.processFeed('simple_test_feed', 'rss', function(err, data){
|
||||
if (err) {
|
||||
@ -59,4 +63,25 @@ rss_braider.processFeed('simple_test_feed', 'rss', function(err, data){
|
||||
}
|
||||
console.log(data);
|
||||
});
|
||||
```
|
||||
```
|
||||
## Plugins
|
||||
Plugins provide custom manipulation and filtering of RSS items/articles. See `lib/example_plugins` for examples. A plugin operates by modifying the itemOptions object or by returning `null` which will exclude the `item` (article) from the resulting feed.
|
||||
|
||||
### Plugin Example
|
||||
This plugin will capitalize the article title for all articles
|
||||
```js
|
||||
module.exports = function (item, itemOptions, source) {
|
||||
if (!item || !itemOptions) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (itemOptions.title) {
|
||||
itemOptions.title = itemOptions.title.toUpperCase();
|
||||
}
|
||||
|
||||
return itemOptions;
|
||||
};
|
||||
```
|
||||
|
||||
|
||||
|
@ -2,7 +2,7 @@ var feed = {
|
||||
"feed_name" : "feed with plugins",
|
||||
"default_count" : 1,
|
||||
"no_cdata_fields" : [],
|
||||
"plugins" : ['content_encoded'],
|
||||
"plugins" : ['capitalize_title', 'plugin_template'],
|
||||
"meta" : {
|
||||
"title": "NPR Braided Feed",
|
||||
"description": "This is a test of two NPR sources from file. Plugins are applied."
|
||||
|
@ -1,18 +0,0 @@
|
||||
var RssBraider = require('../index'),
|
||||
feed_obj = {};
|
||||
|
||||
feed_obj.filefeed = require("./config/feed_with_plugins").feed;
|
||||
|
||||
var braider_options = {
|
||||
feeds : feed_obj,
|
||||
indent : " ",
|
||||
plugins_directories : [__dirname + "/plugins/"]
|
||||
};
|
||||
var rss_braider = RssBraider.createClient(braider_options);
|
||||
|
||||
rss_braider.processFeed('filefeed', 'rss', function(err, data){
|
||||
if (err) {
|
||||
return console.log(err);
|
||||
}
|
||||
console.log(data);
|
||||
});
|
@ -1,27 +1,5 @@
|
||||
module.exports = function (item, itemOptions, source) {
|
||||
if (!item || !itemOptions) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 'itunes:summary':
|
||||
// { '@': {},
|
||||
// '#': 'Let KQED Arts help you find the best things to see, do, and explore in San Francisco, Oakland, San Jose, and the surrounding areas.' },
|
||||
// 'itunes:author': { '@': {}, '#': 'KQED Arts' },
|
||||
// 'itunes:explicit': { '@': {}, '#': 'no' },
|
||||
// 'itunes:image': { '@': [Object] },
|
||||
// 'itunes:owner': { '@': {}, 'itunes:name': [Object], 'itunes:email': [Object] },
|
||||
// 'rss:managingeditor':
|
||||
// { '@': {},
|
||||
// '#': 'ondemand@kqed.org (KQED Arts)',
|
||||
// name: 'KQED Arts',
|
||||
// email: 'ondemand@kqed.org' },
|
||||
// 'rss:copyright':
|
||||
// { '@': {},
|
||||
// '#': 'Copyright © 2015 KQED Inc. All Rights Reserved.' },
|
||||
// 'itunes:subtitle': { '@': {}, '#': 'KQED Public Media for Northern CA' },
|
||||
// 'rss:image': { '@': {}, title: [Object], url: [Object], link: [Object] },
|
||||
// 'itunes:category': [ [Object], [Object], [Object] ],
|
||||
|
||||
// Pass through itunes content...
|
||||
//
|
||||
// <itunes:summary>
|
||||
// Let KQED Arts help you find the best things to see, do, and explore in San Francisco, Oakland, San Jose, and the surrounding areas.
|
||||
// </itunes:summary>
|
||||
@ -33,28 +11,13 @@ module.exports = function (item, itemOptions, source) {
|
||||
// <itunes:email>ondemand@kqed.org</itunes:email>
|
||||
// </itunes:owner>
|
||||
// <managingEditor>ondemand@kqed.org (KQED Arts)</managingEditor>
|
||||
// <copyright>Copyright © 2015 KQED Inc. All Rights Reserved.</copyright>
|
||||
// <itunes:subtitle>KQED Public Media for Northern CA</itunes:subtitle>
|
||||
|
||||
// *link
|
||||
// *comments
|
||||
// pubDate
|
||||
// *dc:creator
|
||||
// *category
|
||||
// guid
|
||||
// description
|
||||
// *content:encoded
|
||||
// *wfw:commentRss
|
||||
// *slash:comments
|
||||
// enclosure
|
||||
// itunes:subtitle
|
||||
// itunes:summary
|
||||
// itunes:author
|
||||
// itunes:explicit
|
||||
// *media:content (multiple)
|
||||
// *media:thumbnail
|
||||
module.exports = function (item, itemOptions, source) {
|
||||
if (!item || !itemOptions) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Pass through itunes content
|
||||
var pass_through_arr = ['itunes:summary', 'itunes:author', 'itunes:explicit', ];
|
||||
pass_through_arr.forEach(function(element){
|
||||
if (item[element] && item[element]['#']) {
|
@ -1,21 +0,0 @@
|
||||
// Put the description into content:encoded block
|
||||
// Ex:
|
||||
// <content:encoded>
|
||||
// <![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(
|
||||
{ "content:encoded":
|
||||
{
|
||||
_cdata: content_encoded
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
return itemOptions;
|
||||
};
|
@ -28,10 +28,14 @@ feeds.simple_test_feed = {
|
||||
var braider_options = {
|
||||
feeds : feeds,
|
||||
indent : " ",
|
||||
date_sort_order : "desc" // Newest first
|
||||
date_sort_order : "desc", // Newest first
|
||||
log_level : 'debug'
|
||||
};
|
||||
var rss_braider = RssBraider.createClient(braider_options);
|
||||
|
||||
// Set logging level (debug, info, warn, err, off)
|
||||
rss_braider.logger.level('off');
|
||||
|
||||
rss_braider.processFeed('simple_test_feed', 'rss', function(err, data){
|
||||
if (err) {
|
||||
return console.log(err);
|
||||
|
@ -9,8 +9,16 @@ var FeedParser = require('feedparser'),
|
||||
|
||||
var logger;
|
||||
var RssBraider = function (options) {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
this.feeds = options.feeds || null;
|
||||
this.logger = options.logger || bunyan.createLogger({name: 'rss-braider'});
|
||||
|
||||
if (options.log_level) {
|
||||
this.logger.level(options.log_level);
|
||||
}
|
||||
|
||||
this.indent = options.indent || " ";
|
||||
this.dedupe_fields = options.dedupe_fields || []; // The fields to use to identify duplicate articles
|
||||
this.date_sort_order = options.date_sort_order || "desc";
|
||||
@ -117,8 +125,6 @@ RssBraider.prototype.processFeed = function(feed_name, format, callback)
|
||||
var article = self.processItem(item, source, feed_name);
|
||||
if (article) {
|
||||
source_articles.push(article);
|
||||
} else {
|
||||
self.logger.debug("Empty article found in " + feed_name, item.title);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -1,21 +0,0 @@
|
||||
// Put the description into content:encoded block
|
||||
// Ex:
|
||||
// <content:encoded>
|
||||
// <![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(
|
||||
{ "content:encoded":
|
||||
{
|
||||
_cdata: content_encoded
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
return itemOptions;
|
||||
};
|
@ -1,9 +0,0 @@
|
||||
module.exports = function (item, itemOptions, source) {
|
||||
if (!item || !itemOptions) {
|
||||
return;
|
||||
}
|
||||
|
||||
// This plugin removes all items by returning null instead of the processed
|
||||
// itemOptions
|
||||
return null;
|
||||
};
|
@ -2,7 +2,7 @@ var feed = {
|
||||
"feed_name" : "test file feed",
|
||||
"default_count" : 1,
|
||||
"no_cdata_fields" : ['description'],
|
||||
"plugins" : ['kqed', 'content_encoded', 'wfw_slash_comments', 'add_media_thumbnail'],
|
||||
"plugins" : ['kqed', 'add_content_encoded_block', 'wfw_slash_comments', 'add_media_thumbnail'],
|
||||
"meta" : {
|
||||
"title": "Test File Feed",
|
||||
"description": "This feed comes from a file",
|
||||
|
@ -1,6 +1,6 @@
|
||||
var feed = {
|
||||
"feed_name" : "no_elements",
|
||||
"plugins" : ['filter_all_articles'], // No articles make it through
|
||||
"plugins" : ['filter_out_all_articles'], // No articles make it through
|
||||
"meta" : {
|
||||
"title" : "A Feed with no elements",
|
||||
"description" : "This feed will have no elements as a result of the filter_all_articles plugin. Used for unit tests.",
|
||||
|
@ -2,7 +2,7 @@ var feed = {
|
||||
"feed_name" : "test file feed",
|
||||
"default_count" : 1,
|
||||
"no_cdata_fields" : ['description'],
|
||||
"plugins" : ['kqed', 'content_encoded', 'wfw_slash_comments', 'add_media_thumbnail'],
|
||||
"plugins" : ['kqed', 'add_content_encoded_block', 'wfw_slash_comments', 'add_media_thumbnail'],
|
||||
"meta" : {
|
||||
"title": "Test File Feed",
|
||||
"description": "This feed comes from a file",
|
||||
|
@ -2,7 +2,7 @@ var feed = {
|
||||
"feed_name" : "test file feed",
|
||||
"default_count" : 1,
|
||||
"no_cdata_fields" : ['description'],
|
||||
"plugins" : ['kqed', 'content_encoded', 'wfw_slash_comments', 'add_media_thumbnail'],
|
||||
"plugins" : ['kqed', 'add_content_encoded_block', 'wfw_slash_comments', 'add_media_thumbnail'],
|
||||
"meta" : {
|
||||
"title": "Test File Feed",
|
||||
"description": "This feed comes from a file",
|
||||
|
@ -35,7 +35,7 @@ test('generate feed and process through plugins', function(t) {
|
||||
feeds : feeds,
|
||||
indent : " ",
|
||||
date_sort_order : "desc",
|
||||
plugins_directories : [__dirname + '/../lib/example_plugins/']
|
||||
plugins_directories : [__dirname + '/../examples/plugins/']
|
||||
};
|
||||
var rss_braider = RssBraider.createClient(braider_options);
|
||||
|
||||
@ -56,7 +56,7 @@ test('de-duplicate feed', function(t) {
|
||||
feeds : feeds,
|
||||
indent : " ",
|
||||
dedupe_fields : ["title", "guid"],
|
||||
plugins_directories : [__dirname + '/../lib/example_plugins/']
|
||||
plugins_directories : [__dirname + '/../examples/plugins/']
|
||||
};
|
||||
var rss_braider = RssBraider.createClient(braider_options);
|
||||
|
||||
@ -77,7 +77,7 @@ test('sort feed articles by date descending', function(t) {
|
||||
feeds : feeds,
|
||||
indent : " ",
|
||||
date_sort_order : "desc",
|
||||
plugins_directories : [__dirname + '/../lib/example_plugins/']
|
||||
plugins_directories : [__dirname + '/../examples/plugins/']
|
||||
};
|
||||
var rss_braider = RssBraider.createClient(braider_options);
|
||||
|
||||
@ -98,7 +98,7 @@ test('sort feed articles by date ascending', function(t) {
|
||||
feeds : feeds,
|
||||
indent : " ",
|
||||
date_sort_order : "asc",
|
||||
plugins_directories : [__dirname + '/../lib/example_plugins/']
|
||||
plugins_directories : [__dirname + '/../examples/plugins/']
|
||||
};
|
||||
var rss_braider = RssBraider.createClient(braider_options);
|
||||
|
||||
@ -119,7 +119,7 @@ test('filter all articles out using plugin', function(t) {
|
||||
feeds : feeds,
|
||||
indent : " ",
|
||||
date_sort_order : "asc",
|
||||
plugins_directories : [__dirname + '/../lib/example_plugins/']
|
||||
plugins_directories : [__dirname + '/../examples/plugins/']
|
||||
};
|
||||
var rss_braider = RssBraider.createClient(braider_options);
|
||||
rss_braider.logger.level('info');
|
||||
|
Loading…
Reference in New Issue
Block a user