Permalink
Browse files

Improve detection of website link in atom feeds. Fixes issue #7. Vers…

…ion bump.
  • Loading branch information...
danmactough committed Jan 27, 2012
1 parent 00d91f9 commit 7a4fc468f77c3ab007e14d432fe6f1af4307b58b
Showing with 56 additions and 36 deletions.
  1. +54 −34 lib/feedparser.js
  2. +2 −2 package.json
View
@@ -299,26 +299,36 @@ FeedParser.prototype.handleCloseTag = function (el, scope){
if ( self.stack[0][linkEl] ) {
if ( self.stack[0][linkEl].length ) {
self.stack[0][linkEl].forEach(function(link){
- if (link['@'] && link['@']['rel'] && link['@']['href'])
- switch(link['@']['rel']){
- case('alternate'):
+ if (link['@'] && link['@']['href']) {
+ if (link['@']['rel']) {
+ switch(link['@']['rel']){
+ case('alternate'):
+ self.meta.link = link['@']['href'];
+ break;
+ case('self'):
+ self.meta.xmlUrl = link['@']['href'];
+ break;
+ };
+ } else {
self.meta.link = link['@']['href'];
+ }
+ }
+ });
+ } else {
+ if (self.stack[0][linkEl]['@'] && self.stack[0][linkEl]['@']['href']) {
+ if (self.stack[0][linkEl]['@']['rel']) {
+ switch(self.stack[0][linkEl]['@']['rel']){
+ case('alternate'):
+ self.meta.link = self.stack[0][linkEl]['@']['href'];
break;
case('self'):
- self.meta.xmlUrl = link['@']['href'];
+ self.meta.xmlUrl = self.stack[0][linkEl]['@']['href'];
break;
- };
- });
- } else {
- if (self.stack[0][linkEl]['@'] && self.stack[0][linkEl]['@']['rel'] && self.stack[0][linkEl]['@']['href'])
- switch(self.stack[0][linkEl]['@']['rel']){
- case('alternate'):
- self.meta.link = self.stack[0][linkEl]['@']['href'];
- break;
- case('self'):
- self.meta.xmlUrl = self.stack[0][linkEl]['@']['href'];
- break;
- };
+ };
+ } else {
+ self.meta.link = self.stack[0][linkEl]['@']['href']
+ }
+ }
}
}
});
@@ -418,10 +428,10 @@ FeedParser.prototype.handleCloseTag = function (el, scope){
if ( n.link ) {
if ( n.link.length ) {
n.link.forEach(function(link){
- if(link['@'] && getValue(link['@'], 'rel') == 'alternate')
+ if(link['@'] && (getValue(link['@'], 'rel') == 'alternate' || getValue(link['@'], 'rel') == null))
item.link = getValue(link['@'], 'href');
});
- } else if (n.link['@'] && getValue(n.link['@'], 'rel') == 'alternate') {
+ } else if (n.link['@'] && (getValue(n.link['@'], 'rel') == 'alternate' || getValue(n.link['@'], 'rel') == null)) {
item.link = getValue(n.link['@'], 'href');
}
}
@@ -475,26 +485,36 @@ FeedParser.prototype.handleCloseTag = function (el, scope){
if ( n[linkEl] ) {
if ( n[linkEl].length ) {
n[linkEl].forEach(function(link){
- if (link['@'] && link['@']['rel'] && link['@']['href'])
- switch(link['@']['rel']){
- case('alternate'):
+ if (link['@'] && link['@']['href']) {
+ if (link['@']['rel']) {
+ switch(link['@']['rel']){
+ case('alternate'):
+ self.meta.link = link['@']['href'];
+ break;
+ case('self'):
+ self.meta.xmlUrl = link['@']['href'];
+ break;
+ };
+ } else {
self.meta.link = link['@']['href'];
- break;
- case('self'):
- self.meta.xmlUrl = link['@']['href'];
- break;
- };
+ }
+ }
});
} else {
- if (n[linkEl]['@'] && n[linkEl]['@']['rel'] && n[linkEl]['@']['href'])
- switch(n[linkEl]['@']['rel']){
- case('alternate'):
+ if (n[linkEl]['@'] && n[linkEl]['@']['href']) {
+ if (n[linkEl]['@']['rel']) {
+ switch(n[linkEl]['@']['rel']){
+ case('alternate'):
+ self.meta.link = n[linkEl]['@']['href'];
+ break;
+ case('self'):
+ self.meta.xmlUrl = n[linkEl]['@']['href'];
+ break;
+ };
+ } else {
self.meta.link = n[linkEl]['@']['href'];
- break;
- case('self'):
- self.meta.xmlUrl = n[linkEl]['@']['href'];
- break;
- };
+ }
+ }
}
}
});
View
@@ -2,7 +2,7 @@
"name": "feedparser",
"author": "Dan MacTough <danmactough@gmail.com>",
"description": "Robust RSS, Atom, and RDF feed parsing using sax js",
- "version": "0.4.5",
+ "version": "0.4.6",
"repository": {
"type": "git",
"url": "git://github.com/danmactough/node-feedparser.git"
@@ -14,7 +14,7 @@
},
"dependencies": {
"sax": "0.3.x",
- "request": "2.2.x"
+ "request": "2.9.x"
},
"devDependencies": {}
}

0 comments on commit 7a4fc46

Please sign in to comment.