From 040d854c57daaecb2aa90096d44b2e05d6b31a1d Mon Sep 17 00:00:00 2001 From: Max Nowack Date: Tue, 11 Nov 2014 13:49:37 +0100 Subject: [PATCH] added functionality to add custom elements --- lib/rss.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/rss.js b/lib/rss.js index 11ca491..a8110b9 100755 --- a/lib/rss.js +++ b/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);