Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated link detection logic

  • Loading branch information...
commit 6ac68adca79596aad7cd9824688453d2cceb601a 1 parent bf1b952
@andris9 authored
Showing with 29 additions and 9 deletions.
  1. +22 −3 lib/nodepie.js
  2. +1 −1  package.json
  3. +6 −5 test/test.js
View
25 lib/nodepie.js
@@ -1,6 +1,7 @@
var xmlparser = require('xml2json'),
fetch = require('fetch'),
- Iconv = require("iconv").Iconv;
+ Iconv = require("iconv").Iconv,
+ urllib = require("url");
module.exports = NodePie;
@@ -452,7 +453,7 @@ NodePie.prototype.getLink = function(rel, type){
rel = rel || "alternate";
type = type || "text/html";
- var link = (atom10ns && this.channelElement[atom10ns+":link"]) || this.channelElement.link;
+ var link = (atom10ns && [].concat(this.channelElement[atom10ns+":link"] || []).concat(this.channelElement.link)) || this.channelElement.link;
if(!link);
@@ -473,6 +474,10 @@ NodePie.prototype.getLink = function(rel, type){
return link.href;
}
+ if(rel == "alternate" && type == "text/html" && link && link.href && !link.rel && !link.type){
+ return link.href;
+ }
+
return false;
};
@@ -677,6 +682,10 @@ NodePie.Item.prototype.getLink = function(rel, type){
return link[i].href;
}
+ if(rel == "alternate" && type == "text/html" && link && link.href && !link.rel && !link.type){
+ return link.href;
+ }
+
return false;
};
@@ -691,7 +700,17 @@ NodePie.Item.prototype.getLink = function(rel, type){
* permalink = item.getPermalink();
**/
NodePie.Item.prototype.getPermalink = function(){
- return this.getLink();
+ var permalink = this.getLink(),
+ feedLink;
+ if(!permalink){
+ return permalink;
+ }
+
+ if((feedLink = this.feed.getPermalink())){
+ return urllib.resolve(feedLink, permalink);
+ }else{
+ return permalink;
+ }
};
/**
View
2  package.json
@@ -1,7 +1,7 @@
{
"name": "nodepie",
"description": "RSS/Atom parser for Node.JS",
- "version": "0.5.5",
+ "version": "0.6.0",
"author" : "Andris Reinman",
"maintainers":[
{
View
11 test/test.js
@@ -15,11 +15,12 @@ request(feed_url, function(error, xml){
console.log("\n" + np.getTitle());
console.log(new Array((np.getTitle() || "").length + 1).join("="));
- console.log(np.getDescription(),"\n");
- console.log(np.getPermalink());
- console.log("Source encoding: " + np.getEncoding());
- console.log("Updated", np.getDate());
- console.log("Image", np.getImage());
+ console.log(np.getDescription());
+ console.log("Permalink:", np.getPermalink());
+ console.log("Hub:", np.getHub());
+ console.log("Source encoding:", np.getEncoding());
+ console.log("Updated:", np.getDate());
+ console.log("Image:", np.getImage());
for(var i=0, len = np.getItemQuantity(3); i<len; i++){
item = np.getItem(i);
Please sign in to comment.
Something went wrong with that request. Please try again.