mirror of
https://github.com/LightAir/turbo-rss.git
synced 2026-02-04 03:56:19 +00:00
added support for enclosure
Author: Victor Jonsson <kontakt@victorjonsson.se>
This commit is contained in:
33
lib/rss.js
33
lib/rss.js
@@ -2,7 +2,9 @@
|
||||
Documentation coming soon.
|
||||
*/
|
||||
|
||||
var XML = require('xml');
|
||||
var XML = require('xml'),
|
||||
mime = require('mime'),
|
||||
fs = require('fs');
|
||||
|
||||
function RSS (options, items) {
|
||||
options = options || {};
|
||||
@@ -24,7 +26,8 @@ function RSS (options, items) {
|
||||
guid: options.guid,
|
||||
categories: options.categories || [],
|
||||
author: options.author,
|
||||
date: options.date
|
||||
date: options.date,
|
||||
enclosure: options.enclosure || false
|
||||
};
|
||||
|
||||
this.items.push(item);
|
||||
@@ -72,7 +75,33 @@ 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() });
|
||||
|
||||
if( item.enclosure && item.enclosure.url ) {
|
||||
if( item.enclosure.file ) {
|
||||
item_values.push({
|
||||
enclosure : {
|
||||
_attr : {
|
||||
url : item.enclosure.url,
|
||||
length : fs.statSync(item.enclosure.file).size,
|
||||
type : mime.lookup(item.enclosure.file)
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
item_values.push({
|
||||
enclosure : {
|
||||
_attr : {
|
||||
url : item.enclosure.url,
|
||||
length : item.enclosure.size || 0,
|
||||
type : mime.lookup(item.enclosure.url)
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
channel.push({ item: item_values });
|
||||
|
||||
});
|
||||
|
||||
return { rss: [
|
||||
|
||||
Reference in New Issue
Block a user