From d3e8661f6b7d6bc1ee3c6658bfda280d5f07284a Mon Sep 17 00:00:00 2001 From: Andreas Schmid Date: Wed, 4 Feb 2015 16:07:27 -0500 Subject: [PATCH 1/4] option to pass a type to enclosure --- lib/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index e9fa9ce..b5fbe5f 100755 --- a/lib/index.js +++ b/lib/index.js @@ -87,7 +87,7 @@ function generateXML (data){ _attr : { url : item.enclosure.url, length : item.enclosure.size || getSize(item.enclosure.file), - type : mime.lookup(item.enclosure.file) + type : item.enclosure.type || mime.lookup(item.enclosure.file) } } }); @@ -97,7 +97,7 @@ function generateXML (data){ _attr : { url : item.enclosure.url, length : item.enclosure.size || 0, - type : mime.lookup(item.enclosure.url) + type : item.enclosure.type || mime.lookup(item.enclosure.url) } } }); From 07bb4ca86b1825d8dfe0f651bbfcae9cbfda8494 Mon Sep 17 00:00:00 2001 From: Andreas Schmid Date: Mon, 9 Feb 2015 11:51:26 -0500 Subject: [PATCH 2/4] added tests and doc for enclosure type override --- readme.md | 9 +++++ .../enclosure_mimetype_override.xml | 30 +++++++++++++++ test/index.js | 37 +++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 test/expectedOutput/enclosure_mimetype_override.xml diff --git a/readme.md b/readme.md index bafa300..2cb2efd 100644 --- a/readme.md +++ b/readme.md @@ -66,7 +66,16 @@ feed.item(itemOptions); * `lat` _optional_ **number** The latitude coordinate of the item. * `long` _optional_ **number** The longitude coordinate of the item. * `custom_elements` _optional_ **array** Put additional elements in the item (node-xml syntax) + * `enclosure` _optional_ **object** An enclosure object + ```js + /* enclosure takes url or file key for the enclosure object */ + { + 'url' : 'http://www.example.com/path/to/image', // url or path to binary, keys are url or file + 'length' : 1668, // the size of the file // optional + 'type' : 'image/jpeg' // optional, if not provided the mimetype will be guessed based on the extension of the file or url, passing type to the enclosure will override the guessed type + } + ``` ##### Feed XML ```js diff --git a/test/expectedOutput/enclosure_mimetype_override.xml b/test/expectedOutput/enclosure_mimetype_override.xml new file mode 100644 index 0000000..3fa2fab --- /dev/null +++ b/test/expectedOutput/enclosure_mimetype_override.xml @@ -0,0 +1,30 @@ + + + + <![CDATA[title]]> + + http://example.com + RSS for Node + Wed, 10 Dec 2014 19:04:57 GMT + + + + <![CDATA[item 1]]> + + http://example.com/article1 + http://example.com/article1 + + Thu, 24 May 2012 04:00:00 GMT + + + + <![CDATA[item 2]]> + + http://example.com/article1 + http://example.com/article1 + + Thu, 24 May 2012 04:00:00 GMT + + + + \ No newline at end of file diff --git a/test/index.js b/test/index.js index 36dec7a..342ac42 100644 --- a/test/index.js +++ b/test/index.js @@ -137,6 +137,43 @@ test('enclosure', function(t) { t.equal(feed.xml({indent: true}), expectedOutput.enclosures); }); +test('enclosure_mimetype_override', function(t) { + //if (typeof window) return; + + t.plan(1); + + var feed = new RSS({ + title: 'title', + description: 'description', + feed_url: 'http://example.com/rss.xml', + site_url: 'http://example.com', + author: 'Dylan Greene' + }); + + + feed.item({ + title: 'item 1', + description: 'description 1', + url: 'http://example.com/article1', + date: 'May 24, 2012 04:00:00 GMT', + enclosure : {url: '/media/some-file-without-extension', type: 'custom-video/x-flv'} + }); + + feed.item({ + title: 'item 2', + description: 'description 2', + url: 'http://example.com/article1', + date: 'May 24, 2012 04:00:00 GMT', + enclosure : { + url: '/media/image.png', + file: __dirname + '/image.png', + size: 16650, // this is optional + type: 'image/jpeg' // we set this just to prove that the override works + } + }); + + t.equal(feed.xml({indent: true}), expectedOutput.enclosure_mimetype_override); +}); test('geoRSS', function(t) { t.plan(1); From a0e24d83ab3ffa1dd1f02452d6e2fdb1c68400fb Mon Sep 17 00:00:00 2001 From: Andreas Schmid Date: Mon, 9 Feb 2015 11:56:48 -0500 Subject: [PATCH 3/4] better doc formatting --- readme.md | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index 2cb2efd..e10ca79 100644 --- a/readme.md +++ b/readme.md @@ -68,11 +68,20 @@ feed.item(itemOptions); * `custom_elements` _optional_ **array** Put additional elements in the item (node-xml syntax) * `enclosure` _optional_ **object** An enclosure object ```js - /* enclosure takes url or file key for the enclosure object */ + /* enclosure takes url or file key for the enclosure object + + url: _required_ url to file object (or file) + file: _required_ path to binary file (or url) + size: _optional_ size of the file + type: _optional_ if not provided the mimetype will be guessed + based on the extension of the file or url, + passing type to the enclosure will override the guessed type + */ + { - 'url' : 'http://www.example.com/path/to/image', // url or path to binary, keys are url or file - 'length' : 1668, // the size of the file // optional - 'type' : 'image/jpeg' // optional, if not provided the mimetype will be guessed based on the extension of the file or url, passing type to the enclosure will override the guessed type + 'url' : 'http://www.example.com/path/to/image', + 'size' : 1668, // + 'type' : 'image/jpeg' } ``` From 04c3dd32c782c83daf5a99e4e04af8534e192029 Mon Sep 17 00:00:00 2001 From: Andreas Schmid Date: Mon, 9 Feb 2015 11:59:46 -0500 Subject: [PATCH 4/4] updated usage.md with latest updates --- templates/readme/usage.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/templates/readme/usage.md b/templates/readme/usage.md index fe0528e..c2a9304 100644 --- a/templates/readme/usage.md +++ b/templates/readme/usage.md @@ -55,7 +55,25 @@ feed.item(itemOptions); * `lat` _optional_ **number** The latitude coordinate of the item. * `long` _optional_ **number** The longitude coordinate of the item. * `custom_elements` _optional_ **array** Put additional elements in the item (node-xml syntax) + * `enclosure` _optional_ **object** An enclosure object + ```js + /* enclosure takes url or file key for the enclosure object + url: _required_ url to file object (or file) + file: _required_ path to binary file (or url) + size: _optional_ size of the file + type: _optional_ if not provided the mimetype will be guessed + based on the extension of the file or url, + passing type to the enclosure will override the guessed type + */ + + { + 'url' : 'http://www.example.com/path/to/image', + 'size' : 1668, // + 'type' : 'image/jpeg' + } + + ``` #### Feed XML ```js