Permalink
Browse files

replaced tabs with spaces, improved NodePie#_parseContents, NodePie#g…

…etPermalink, NodePie#getDate
  • Loading branch information...
1 parent 1825596 commit 5455a4ec166fbbc2eacb2b88cd08d6a7a82b3438 @fb55 fb55 committed Sep 17, 2011
Showing with 31 additions and 48 deletions.
  1. +31 −48 lib/nodepie.js
View
@@ -108,8 +108,8 @@ NodePie.HTMLEntities = {
**/
NodePie._decodeHTMLEntities = function(text){
return text.replace(/&(.+?);/g, function(str, ent){
- return String.fromCharCode( ent[0]!='#' ? NodePie.HTMLEntities[ent] : ent[1]=='x' ? parseInt(ent.substr(2),16): parseInt(ent.substr(1)) )}
- );
+ return String.fromCharCode( ent[0]!='#' ? NodePie.HTMLEntities[ent] : ent[1]=='x' ? parseInt(ent.substr(2),16): parseInt(ent.substr(1)) )}
+ );
};
/**
@@ -242,9 +242,9 @@ NodePie.prototype._checkType = function(){
* entities
**/
NodePie.prototype._formatStr = function(str){
- if(this.options.keepHTMLEntities)
- return str;
- else return NodePie._decodeHTMLEntities(str);
+ if(this.options.keepHTMLEntities)
+ return str;
+ else return NodePie._decodeHTMLEntities(str);
};
/**
@@ -254,19 +254,14 @@ NodePie.prototype._formatStr = function(str){
* Fetches text contents from a string or feed text object
**/
NodePie.prototype._parseContents = function(str){
- if(!str);
- else if(typeof str === "string"){
+ if(typeof str === "object")
+ str = str.$t;
+
+ if(typeof str === "string"){
str = str.trim();
- return str && this._formatStr(str);
+ if(str !== "") return this._formatStr(str);
}
-
- else if(typeof str === "object"){
- if(typeof str.$t === "string"){
- str.$t = str.$t.trim();
- return str.$t && this._formatStr(str.$t);
- }
- }
-
+
return false;
};
@@ -334,7 +329,7 @@ NodePie.prototype.getEncoding = function(){
**/
NodePie.prototype.getDescription = function(){
return this._parseContents(
- this.channelElement.description || this.channelElement.subtitle ||
+ this.channelElement.description || this.channelElement.subtitle ||
this.channelElement.tagline
);
};
@@ -352,16 +347,9 @@ NodePie.prototype.getDescription = function(){
**/
NodePie.prototype.getPermalink = function(){
var link = this.channelElement.link;
-
- if(!link){
- return false;
- }
-
- if(typeof link=="string"){
- return link.trim();
- }
-
- return this.getLink();
+
+ if(typeof link === "string") return link.trim();
+ else return this.getLink();
};
/**
@@ -435,23 +423,18 @@ NodePie.prototype.getLink = function(rel, type){
* console.log(date.getFullYear))
**/
NodePie.prototype.getDate = function(){
- var dcns = this.namespaces[NodePie.NS.DC], date;
-
- date = this.channelElement.lastBuildDate || this.channelElement.updated ||
- (dcns && this.channelElement[dcns+":date"]);
+ var dcns = this.namespaces[NodePie.NS.DC];
- if(!date){
- return false;
- }
+ var date = new Date(
+ this.channelElement.lastBuildDate || this.channelElement.updated ||
+ (dcns && this.channelElement[dcns+":date"])
+ );
- date = new Date(date);
- if(!date.getFullYear()){
+ if(!date.getTime())
return false;
- }
- if(date.getTime() > Date.now()){
+ if(date.getTime() > Date.now())
return new Date();
- }
return date;
};
@@ -477,10 +460,10 @@ NodePie.prototype.getItemQuantity = function(max){
this._item_count = 0;
if(this.itemsElement){
- if(Array.isArray(this.itemsElement))
- this._item_count = this.itemsElement.length;
- else if(typeof this.itemsElement === "object")
- this._item_count = 1;
+ if(Array.isArray(this.itemsElement))
+ this._item_count = this.itemsElement.length;
+ else if(typeof this.itemsElement === "object")
+ this._item_count = 1;
}
return max && max<this._item_count ? max : this._item_count;
@@ -737,7 +720,7 @@ NodePie.Item.prototype.getDate = function(){
var dcns = this.feed.namespaces[NodePie.NS.DC];
var date = new Date(
- this.element.pubDate || this.element.published || this.element.created || this.element.issued ||
+ this.element.pubDate || this.element.published || this.element.created || this.element.issued ||
this.element.updated || this.element.modified || (dcns && this.element[dcns+":date"])
);
@@ -764,7 +747,7 @@ NodePie.Item.prototype.getDate = function(){
**/
NodePie.Item.prototype.getUpdateDate = function(){
var date = new Date(
- this.element.updated || this.element.modified
+ this.element.updated || this.element.modified
);
if(!date.getTime())
@@ -791,7 +774,7 @@ NodePie.Item.prototype.getDescription = function(){
var cns = this.feed.namespaces[NodePie.NS.CONTENT];
return this._parseContents(
- this.element.description || this.element.summary ||
+ this.element.description || this.element.summary ||
this.element.content || (cns && this.element[cns+":encoded"]) || ""
);
};
@@ -810,7 +793,7 @@ NodePie.Item.prototype.getContents = function(){
var cns = this.feed.namespaces[NodePie.NS.CONTENT];
return this._parseContents(
- this.element.content || (cns && this.element[cns+":encoded"]) ||
+ this.element.content || (cns && this.element[cns+":encoded"]) ||
this.element.description || this.element.summary || "";
);
};
@@ -849,7 +832,7 @@ NodePie.Item.prototype.getCategories = function(){
else if(typeof category === "string"){
if(category = category.trim())
- return [this._formatStr(category)];
+ return [this._formatStr(category)];
}
else if(Array.isArray(category)){

0 comments on commit 5455a4e

Please sign in to comment.