Skip to content
Browse files

Fix issue #32 - parse RSS item:author. Enhance RSS authorish elements…

… with parsed properties via addressparser.
  • Loading branch information...
1 parent dad6eea commit b8259682fbe745938e7ad352e2f380e32ac3513b @danmactough committed Oct 25, 2012
Showing with 57 additions and 28 deletions.
  1. +21 −4 main.js
  2. +35 −24 package.json
  3. +1 −0 test/feeds/rss2sample.xml
View
25 main.js
@@ -11,6 +11,7 @@
*/
var sax = require('sax')
, request = require('request')
+ , addressparser = require('addressparser')
, fs = require('fs')
, util = require('util')
, EventEmitter = require('events').EventEmitter
@@ -608,10 +609,18 @@ FeedParser.prototype.handleMeta = function handleMeta (node, type, options) {
case('managingeditor'):
case('webmaster'):
case('author'):
- if (meta.author === null || name == 'managingeditor')
- meta.author = utils.get(el);
- if (name == 'author')
+ var author = {};
+ if (name == 'author') {
meta.author = utils.get(el.name) || utils.get(el.email) || utils.get(el.uri);
+ }
+ else if (utils.get(el)) {
+ author = addressparser(utils.get(el))[0];
+ el['name'] = author.name;
+ el['email'] = author.address;
+ if (meta.author === null || name == 'managingeditor') {
+ meta.author = author.name || author.address;
+ }
+ }
break;
case('language'):
meta.language = utils.get(el);
@@ -855,7 +864,15 @@ FeedParser.prototype.handleItem = function handleItem (node, type, options){
item.guid = utils.get(el);
break;
case('author'):
- item.author = utils.get(el.name) || utils.get(el.email) || utils.get(el.uri);
+ var author = {};
+ if (utils.get(el)) { // RSS
+ author = addressparser(utils.get(el))[0];
+ el['name'] = author.name;
+ el['email'] = author.address;
+ item.author = author.name || author.address;
+ } else {
+ item.author = utils.get(el.name) || utils.get(el.email) || utils.get(el.uri);
+ }
break;
case('dc:creator'):
item.author = utils.get(el);
View
59 package.json
@@ -1,26 +1,37 @@
-{ "name" : "feedparser"
-, "author" : "Dan MacTough <danmactough@gmail.com>"
-, "description" : "Robust RSS Atom and RDF feed parsing using sax js"
-, "version": "0.10.4"
-, "keywords" : ["rss", "feed", "atom", "rdf", "xml", "syndication"]
-, "homepage" : "http://github.com/danmactough/node-feedparser"
-, "repository" :
- { "type" : "git"
- , "url" : "git://github.com/danmactough/node-feedparser.git"
- }
-, "bugs" :
- { "url" : "http://github.com/danmactough/node-feedparser/issues"}
-, "main" : "./main.js"
-, "engines" :
- { "node" : ">= 0.4.0" }
-, "dependencies" :
- { "sax" : "0.4.x"
- , "request" : "2.9.x"
- }
-, "devDependencies":
- { "mocha" : "1.x"
- }
-, "scripts":
- { "test" : "./node_modules/mocha/bin/mocha --reporter spec"
+{
+ "name": "feedparser",
+ "author": "Dan MacTough <danmactough@gmail.com>",
+ "description": "Robust RSS Atom and RDF feed parsing using sax js",
+ "version": "0.10.4",
+ "keywords": [
+ "rss",
+ "feed",
+ "atom",
+ "rdf",
+ "xml",
+ "syndication"
+ ],
+ "homepage": "http://github.com/danmactough/node-feedparser",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/danmactough/node-feedparser.git"
+ },
+ "bugs": {
+ "url": "http://github.com/danmactough/node-feedparser/issues"
+ },
+ "main": "./main.js",
+ "engines": {
+ "node": ">= 0.4.0"
+ },
+ "dependencies": {
+ "sax": "0.4.x",
+ "request": "2.9.x",
+ "addressparser": "~0.1.3"
+ },
+ "devDependencies": {
+ "mocha": "1.x"
+ },
+ "scripts": {
+ "test": "./node_modules/mocha/bin/mocha --reporter spec"
}
}
View
1 test/feeds/rss2sample.xml
@@ -13,6 +13,7 @@
<webMaster>webmaster@example.com</webMaster>
<item>
<title>Star City</title>
+ <author>writer@example.com (Writer)</author>
<link>http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp</link>
<description>How do Americans get ready to work with Russians aboard the International Space Station? They take a crash course in culture, language and protocol at Russia's &lt;a href="http://howe.iki.rssi.ru/GCTC/gctc_e.htm"&gt;Star City&lt;/a&gt;.</description>
<pubDate>Tue, 03 Jun 2003 09:39:21 GMT</pubDate>

0 comments on commit b825968

Please sign in to comment.
Something went wrong with that request. Please try again.