mirror of
https://gitlab.silvrtree.co.uk/martind2000/rss-braider.git
synced 2025-01-11 02:55:08 +00:00
Example code. Plugin to fix TDL issue KIP-1760
This commit is contained in:
parent
e824c0e851
commit
c48d1abc69
21
examples/config/feed.js
Normal file
21
examples/config/feed.js
Normal file
@ -0,0 +1,21 @@
|
||||
var feed = {
|
||||
"feed_name" : "test file feed",
|
||||
"default_count" : 1,
|
||||
"no_cdata_fields" : ['description'],
|
||||
"meta" : {
|
||||
"title": "Test File Feed",
|
||||
"description": "This feed comes from a file",
|
||||
// "url": "http://example.com/feed/",
|
||||
},
|
||||
'custom_namespaces' : {
|
||||
},
|
||||
"sources" : [
|
||||
{
|
||||
"name" : "file",
|
||||
"count" : 1,
|
||||
"file_path" : __dirname + "/feed_source.xml",
|
||||
},
|
||||
|
||||
]
|
||||
};
|
||||
exports.feed = feed;
|
15
examples/plugins.js
Normal file
15
examples/plugins.js
Normal file
@ -0,0 +1,15 @@
|
||||
var RssBraider = require('../index'),
|
||||
feeds = {};
|
||||
feeds.filefeed = require("./config/feed_with_plugins").feed;
|
||||
var braider_options = {
|
||||
feeds : feeds,
|
||||
indent : " "
|
||||
};
|
||||
var rss_braider = RssBraider.createClient(braider_options);
|
||||
|
||||
rss_braider.processFeed('filefeed', 'rss', function(err, data){
|
||||
if (err) {
|
||||
return console.log(err);
|
||||
}
|
||||
console.log(data);
|
||||
});
|
@ -37,13 +37,13 @@ RssBraider.prototype.loadPlugins = function () {
|
||||
});
|
||||
};
|
||||
|
||||
// RssBraider.prototype.feedExists = function (feed_name) {
|
||||
// if (this.feeds && this.feeds[feed_name]) {
|
||||
// return true;
|
||||
// } else {
|
||||
// return false;
|
||||
// }
|
||||
// };
|
||||
RssBraider.prototype.feedExists = function (feed_name) {
|
||||
if (this.feeds && this.feeds[feed_name]) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// Gather data from all feed sources, process each article/item through plugins,
|
||||
// trim down to desired count, dedupe and sort
|
||||
|
91
lib/plugins/strip_elements_from_powerpress.js
Normal file
91
lib/plugins/strip_elements_from_powerpress.js
Normal file
@ -0,0 +1,91 @@
|
||||
module.exports = function (item, itemOptions) {
|
||||
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] ],
|
||||
|
||||
// <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>
|
||||
// <itunes:author>KQED Arts</itunes:author>
|
||||
// <itunes:explicit>no</itunes:explicit>
|
||||
// <itunes:image href="http://ww2.kqed.org/arts/wp-content/uploads/sites/2/powerpress/TDL-Logo-1400x1400.jpeg"/>
|
||||
// <itunes:owner>
|
||||
// <itunes:name>KQED Arts</itunes:name>
|
||||
// <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
|
||||
|
||||
// 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]['#']) {
|
||||
var custom_element = {};
|
||||
custom_element[element] = item[element]['#'];
|
||||
itemOptions.custom_elements.push(custom_element);
|
||||
}
|
||||
});
|
||||
|
||||
// audio enclosures
|
||||
if (item.enclosures && Array.isArray(item.enclosures)){
|
||||
item.enclosures.forEach(function(enclosure){
|
||||
if (enclosure.type === 'audio/mpeg') {
|
||||
var element = {
|
||||
enclosure :{
|
||||
_attr : {
|
||||
url : enclosure.url,
|
||||
length : enclosure.length || enclosure.size || 0,
|
||||
type : enclosure.type || mime.lookup(enclosure.url)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
itemOptions.custom_elements.push(element);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
console.log(item);
|
||||
};
|
Loading…
Reference in New Issue
Block a user