@@ -23,6 +23,17 @@ var getSnippet = function(str) {
23
23
return Entities . decode ( stripHtml ( str ) ) . trim ( ) ;
24
24
}
25
25
26
+ var getContent = function ( content ) {
27
+ if ( typeof content . _ === 'string' ) {
28
+ return content . _ ;
29
+ } else if ( typeof content === 'object' ) {
30
+ var builder = new XML2JS . Builder ( { headless : true , explicitRoot : true , rootName : 'div' , renderOpts : { pretty : false } } ) ;
31
+ return builder . buildObject ( content ) ;
32
+ } else {
33
+ return content ;
34
+ }
35
+ }
36
+
26
37
var parseAtomFeed = function ( xmlObj , callback ) {
27
38
var feed = xmlObj . feed ;
28
39
var json = { feed : { entries : [ ] } } ;
@@ -38,12 +49,12 @@ var parseAtomFeed = function(xmlObj, callback) {
38
49
var entries = feed . entry ;
39
50
( entries || [ ] ) . forEach ( function ( entry ) {
40
51
var item = { } ;
41
- item . title = entry . title [ 0 ] ;
42
- item . link = entry . link [ 0 ] . $ . href ;
43
- item . pubDate = new Date ( entry . updated [ 0 ] ) . toISOString ( ) ;
44
- item . author = entry . author [ 0 ] . name [ 0 ] ;
52
+ if ( entry . title ) item . title = entry . title [ 0 ] ;
53
+ if ( entry . link ) item . link = entry . link [ 0 ] . $ . href ;
54
+ if ( entry . updated ) item . pubDate = new Date ( entry . updated [ 0 ] ) . toISOString ( ) ;
55
+ if ( entry . author ) item . author = entry . author [ 0 ] . name [ 0 ] ;
45
56
if ( entry . content ) {
46
- item . content = entry . content [ 0 ] . _ ;
57
+ item . content = getContent ( entry . content [ 0 ] ) ;
47
58
item . contentSnippet = getSnippet ( item . content )
48
59
}
49
60
if ( entry . id ) {
@@ -72,11 +83,7 @@ var parseRSS2 = function(xmlObj, callback) {
72
83
if ( item [ f ] ) entry [ f ] = item [ f ] [ 0 ] ;
73
84
} )
74
85
if ( item . description ) {
75
- entry . content = item . description [ 0 ] ;
76
- if ( typeof entry . content === 'object' ) {
77
- var builder = new XML2JS . Builder ( { headless : true } ) ;
78
- entry . content = builder . buildObject ( entry . content ) ;
79
- }
86
+ entry . content = getContent ( item . description [ 0 ] ) ;
80
87
entry . contentSnippet = getSnippet ( entry . content ) ;
81
88
}
82
89
if ( item . guid ) {
0 commit comments