Added GeoRSS support

Supports basic GeoRSS with latitude/longitude fields.
This commit is contained in:
Fred Morstatter
2013-08-21 11:11:54 -07:00
parent cf0a4545ff
commit c4da87a023
2 changed files with 32 additions and 8 deletions

32
lib/rss.js Normal file → Executable file
View File

@@ -23,6 +23,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;
this.items = items || [];
this.item = function (options) {
@@ -35,6 +37,8 @@ function RSS (options, items) {
categories: options.categories || [],
author: options.author,
date: options.date,
lat: options.lat,
lng: options.lng,
enclosure: options.enclosure || false
};
@@ -101,6 +105,12 @@ 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});
}
if( item.enclosure && item.enclosure.url ) {
if( item.enclosure.file ) {
item_values.push({
@@ -129,14 +139,22 @@ function generateXML (data){
});
//set up the attributes for the RSS feed.
var _attr = {
'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'
};
//only add namespace if GeoRSS is true
if(data.georss){
_attr['xmlns:geo'] = 'http://www.w3.org/2003/01/geo/wgs84_pos#';
}
return { rss: [
{ _attr: {
'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'
} },
{ channel: channel }
{ '_attr': _attr },
{ 'channel': channel }
] };
}