mirror of
https://github.com/LightAir/turbo-rss.git
synced 2026-02-04 12:06:20 +00:00
added functionality to add custom elements
This commit is contained in:
16
lib/rss.js
16
lib/rss.js
@@ -10,6 +10,14 @@ function ifTruePush(bool, array, data) {
|
||||
}
|
||||
}
|
||||
|
||||
function ifTruePushArray(bool, array, dataArray) {
|
||||
if(!bool) return;
|
||||
|
||||
dataArray.forEach(function(item) {
|
||||
ifTruePush(item, array, item);
|
||||
});
|
||||
}
|
||||
|
||||
function generateXML (data){
|
||||
|
||||
var channel = [];
|
||||
@@ -40,6 +48,8 @@ function generateXML (data){
|
||||
});
|
||||
}
|
||||
|
||||
ifTruePushArray(data.custom, channel, data.custom);
|
||||
|
||||
data.items.forEach(function(item) {
|
||||
var item_values = [
|
||||
{ title: { _cdata: item.title } }
|
||||
@@ -84,6 +94,8 @@ function generateXML (data){
|
||||
}
|
||||
}
|
||||
|
||||
ifTruePushArray(item.custom, item_values, item.custom);
|
||||
|
||||
channel.push({ item: item_values });
|
||||
|
||||
});
|
||||
@@ -130,6 +142,7 @@ function RSS (options, items) {
|
||||
this.ttl = options.ttl;
|
||||
//option to return feed as GeoRSS is set automatically if feed.lat/long is used
|
||||
this.geoRSS = options.geoRSS || false;
|
||||
this.custom = options.custom || [];
|
||||
this.items = items || [];
|
||||
|
||||
this.item = function (options) {
|
||||
@@ -144,7 +157,8 @@ function RSS (options, items) {
|
||||
date: options.date,
|
||||
lat: options.lat,
|
||||
long: options.long,
|
||||
enclosure: options.enclosure || false
|
||||
enclosure: options.enclosure || false,
|
||||
custom: options.custom || []
|
||||
};
|
||||
|
||||
this.items.push(item);
|
||||
|
||||
Reference in New Issue
Block a user