mirror of
https://github.com/LightAir/turbo-rss.git
synced 2026-02-04 12:06:20 +00:00
Added GeoRSS support
Supports basic GeoRSS with latitude/longitude fields.
This commit is contained in:
28
lib/rss.js
Normal file → Executable file
28
lib/rss.js
Normal file → Executable file
@@ -23,6 +23,8 @@ function RSS (options, items) {
|
|||||||
this.managingEditor = options.managingEditor;
|
this.managingEditor = options.managingEditor;
|
||||||
this.webMaster = options.webMaster;
|
this.webMaster = options.webMaster;
|
||||||
this.ttl = options.ttl;
|
this.ttl = options.ttl;
|
||||||
|
//option to return feed as GeoRSS
|
||||||
|
this.georss = options.georss || false;
|
||||||
this.items = items || [];
|
this.items = items || [];
|
||||||
|
|
||||||
this.item = function (options) {
|
this.item = function (options) {
|
||||||
@@ -35,6 +37,8 @@ function RSS (options, items) {
|
|||||||
categories: options.categories || [],
|
categories: options.categories || [],
|
||||||
author: options.author,
|
author: options.author,
|
||||||
date: options.date,
|
date: options.date,
|
||||||
|
lat: options.lat,
|
||||||
|
lng: options.lng,
|
||||||
enclosure: options.enclosure || false
|
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.author || data.author, item_values, { 'dc:creator': { _cdata: item.author || data.author } });
|
||||||
ifTruePush(item.date, item_values, { pubDate: new Date(item.date).toGMTString() });
|
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 && item.enclosure.url ) {
|
||||||
if( item.enclosure.file ) {
|
if( item.enclosure.file ) {
|
||||||
item_values.push({
|
item_values.push({
|
||||||
@@ -129,14 +139,22 @@ function generateXML (data){
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return { rss: [
|
//set up the attributes for the RSS feed.
|
||||||
{ _attr: {
|
var _attr = {
|
||||||
'xmlns:dc': 'http://purl.org/dc/elements/1.1/',
|
'xmlns:dc': 'http://purl.org/dc/elements/1.1/',
|
||||||
'xmlns:content': 'http://purl.org/rss/1.0/modules/content/',
|
'xmlns:content': 'http://purl.org/rss/1.0/modules/content/',
|
||||||
'xmlns:atom': 'http://www.w3.org/2005/Atom',
|
'xmlns:atom': 'http://www.w3.org/2005/Atom',
|
||||||
version: '2.0'
|
'version': '2.0'
|
||||||
} },
|
};
|
||||||
{ channel: channel }
|
|
||||||
|
//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': _attr },
|
||||||
|
{ 'channel': channel }
|
||||||
] };
|
] };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
language: 'en',
|
language: 'en',
|
||||||
categories: ['Category 1','Category 2','Category 3'],
|
categories: ['Category 1','Category 2','Category 3'],
|
||||||
pubDate: 'May 20, 2012 04:00:00 GMT',
|
pubDate: 'May 20, 2012 04:00:00 GMT',
|
||||||
|
//georss: true, //set this flag if you wish for the feed to be returned in GeoRSS. A lat/lng field will be expected for each item.
|
||||||
ttl: '60'
|
ttl: '60'
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -43,7 +44,9 @@
|
|||||||
guid: '1123', // optional - defaults to url
|
guid: '1123', // optional - defaults to url
|
||||||
categories: ['Category 1','Category 2','Category 3','Category 4'], // optional - array of item categories
|
categories: ['Category 1','Category 2','Category 3','Category 4'], // optional - array of item categories
|
||||||
author: 'Guest Author', // optional - defaults to feed author property
|
author: 'Guest Author', // optional - defaults to feed author property
|
||||||
date: 'May 27, 2012' // any format that js Date can parse.
|
date: 'May 27, 2012', // any format that js Date can parse.
|
||||||
|
// lat: 33.417974, //latitude field. Provide if georss is true in the feed setup.
|
||||||
|
// lng: -111.933231, //longitude field. Provide if georss is true in the feed setup.
|
||||||
enclosure : {url:'...', file:'path-to-file'} // optional
|
enclosure : {url:'...', file:'path-to-file'} // optional
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -66,6 +69,7 @@
|
|||||||
* _categories_ <array> Optional. One or more categories this feed belongs to.
|
* _categories_ <array> Optional. One or more categories this feed belongs to.
|
||||||
* _pubDate_ <Date object or date string> Optional. The publication date for content in the feed
|
* _pubDate_ <Date object or date string> Optional. The publication date for content in the feed
|
||||||
* _ttl_ <int> Optional. Number of minutes feed can be cached before refreshing from source.
|
* _ttl_ <int> Optional. Number of minutes feed can be cached before refreshing from source.
|
||||||
|
* _georss_ <boolean> Optional. Whether to make the feed a GeoRSS feed.
|
||||||
|
|
||||||
### Item Options
|
### Item Options
|
||||||
|
|
||||||
@@ -86,6 +90,8 @@ an have any number of items. Ten to tenty is usually good.
|
|||||||
* _date_ <Date object or date string> The date and time of when the item was created. Feed
|
* _date_ <Date object or date string> The date and time of when the item was created. Feed
|
||||||
readers use this to determine the sort order. Some readers will also use it to determine
|
readers use this to determine the sort order. Some readers will also use it to determine
|
||||||
if the content should be presented as unread.
|
if the content should be presented as unread.
|
||||||
|
* _lat_ <number> The latitude coordinate of the item. This will only be recognized if this is a GeoRSS feed.
|
||||||
|
* _lng_ <number> The longitude coordinate of the item. This will only be recognized if this is a GeoRSS feed.
|
||||||
|
|
||||||
### Methods
|
### Methods
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user