added GeoRSS support thanks to @fredzilla. Fixes #15.

This commit is contained in:
Dylan Greene
2013-09-14 16:29:34 -04:00
parent 05b63b7ece
commit a73e525251
4 changed files with 77 additions and 44 deletions

View File

@@ -24,8 +24,8 @@ function RSS (options, items) {
this.managingEditor = options.managingEditor;
this.webMaster = options.webMaster;
this.ttl = options.ttl;
//option to return feed as GeoRSS
this.georss = options.georss || false;
//option to return feed as GeoRSS is set automatically if feed.lat/long is used
this.geoRSS = options.geoRSS || false;
this.items = items || [];
this.item = function (options) {
@@ -39,7 +39,7 @@ function RSS (options, items) {
author: options.author,
date: options.date,
lat: options.lat,
lng: options.lng,
long: options.long,
enclosure: options.enclosure || false
};
@@ -61,7 +61,6 @@ function ifTruePush(bool, array, data) {
}
function generateXML (data){
// todo: xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
var channel = [];
channel.push({ title: { _cdata: data.title } });
@@ -105,11 +104,10 @@ function generateXML (data){
ifTruePush(item.author || data.author, item_values, { 'dc:creator': { _cdata: item.author || data.author } });
ifTruePush(item.date, item_values, { pubDate: new Date(item.date).toGMTString() });
//Add lat and long if GeoRSS is true.
if(data.georss){
ifTruePush(item.lat, item_values, {'geo:lat': item.lat});
ifTruePush(item.lng, item_values, {'geo:long': item.lng});
}
//Set GeoRSS to true if lat and long are set
data.geoRSS = data.geoRSS || (item.lat && item.long);
ifTruePush(item.lat, item_values, {'geo:lat': item.lat});
ifTruePush(item.long, item_values, {'geo:long': item.long});
if( item.enclosure && item.enclosure.url ) {
if( item.enclosure.file ) {
@@ -144,18 +142,20 @@ function generateXML (data){
'xmlns:dc': 'http://purl.org/dc/elements/1.1/',
'xmlns:content': 'http://purl.org/rss/1.0/modules/content/',
'xmlns:atom': 'http://www.w3.org/2005/Atom',
'version': '2.0'
version: '2.0'
};
//only add namespace if GeoRSS is true
if(data.georss){
if(data.geoRSS){
_attr['xmlns:geo'] = 'http://www.w3.org/2003/01/geo/wgs84_pos#';
}
return { rss: [
{ '_attr': _attr },
{ 'channel': channel }
] };
return {
rss: [
{ _attr: _attr },
{ channel: channel }
]
};
}
module.exports = RSS;