mirror of
https://github.com/LightAir/turbo-rss.git
synced 2026-02-04 03:56:19 +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){
|
function generateXML (data){
|
||||||
|
|
||||||
var channel = [];
|
var channel = [];
|
||||||
@@ -40,6 +48,8 @@ function generateXML (data){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ifTruePushArray(data.custom, channel, data.custom);
|
||||||
|
|
||||||
data.items.forEach(function(item) {
|
data.items.forEach(function(item) {
|
||||||
var item_values = [
|
var item_values = [
|
||||||
{ title: { _cdata: item.title } }
|
{ title: { _cdata: item.title } }
|
||||||
@@ -84,6 +94,8 @@ function generateXML (data){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ifTruePushArray(item.custom, item_values, item.custom);
|
||||||
|
|
||||||
channel.push({ item: item_values });
|
channel.push({ item: item_values });
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -130,6 +142,7 @@ function RSS (options, items) {
|
|||||||
this.ttl = options.ttl;
|
this.ttl = options.ttl;
|
||||||
//option to return feed as GeoRSS is set automatically if feed.lat/long is used
|
//option to return feed as GeoRSS is set automatically if feed.lat/long is used
|
||||||
this.geoRSS = options.geoRSS || false;
|
this.geoRSS = options.geoRSS || false;
|
||||||
|
this.custom = options.custom || [];
|
||||||
this.items = items || [];
|
this.items = items || [];
|
||||||
|
|
||||||
this.item = function (options) {
|
this.item = function (options) {
|
||||||
@@ -144,7 +157,8 @@ function RSS (options, items) {
|
|||||||
date: options.date,
|
date: options.date,
|
||||||
lat: options.lat,
|
lat: options.lat,
|
||||||
long: options.long,
|
long: options.long,
|
||||||
enclosure: options.enclosure || false
|
enclosure: options.enclosure || false,
|
||||||
|
custom: options.custom || []
|
||||||
};
|
};
|
||||||
|
|
||||||
this.items.push(item);
|
this.items.push(item);
|
||||||
|
|||||||
Reference in New Issue
Block a user