Skip to content

Commit efbc783

Browse files
author
Ubuntu
committed
release
1 parent 229b41f commit efbc783

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

dist/rss-parser.js

+18-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! rss-parser 2.2.1 */
1+
/*! rss-parser 2.2.2 */
22

33
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.RSSParser = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
44
var Entities = require("entities");
@@ -26,6 +26,17 @@ var getSnippet = function(str) {
2626
return Entities.decode(stripHtml(str)).trim();
2727
}
2828

29+
var getContent = function(content) {
30+
if (typeof content._ === 'string') {
31+
return content._;
32+
} else if (typeof content === 'object') {
33+
var builder = new XML2JS.Builder({headless: true, explicitRoot: true, rootName: 'div', renderOpts: {pretty: false}});
34+
return builder.buildObject(content);
35+
} else {
36+
return content;
37+
}
38+
}
39+
2940
var parseAtomFeed = function(xmlObj, callback) {
3041
var feed = xmlObj.feed;
3142
var json = {feed: {entries: []}};
@@ -41,12 +52,12 @@ var parseAtomFeed = function(xmlObj, callback) {
4152
var entries = feed.entry;
4253
(entries || []).forEach(function (entry) {
4354
var item = {};
44-
item.title = entry.title[0];
45-
item.link = entry.link[0].$.href;
46-
item.pubDate = new Date(entry.updated[0]).toISOString();
47-
item.author = entry.author[0].name[0];
55+
if (entry.title) item.title = entry.title[0];
56+
if (entry.link) item.link = entry.link[0].$.href;
57+
if (entry.updated) item.pubDate = new Date(entry.updated[0]).toISOString();
58+
if (entry.author) item.author = entry.author[0].name[0];
4859
if (entry.content) {
49-
item.content = entry.content[0]._;
60+
item.content = getContent(entry.content[0]);
5061
item.contentSnippet = getSnippet(item.content)
5162
}
5263
if (entry.id) {
@@ -75,11 +86,7 @@ var parseRSS2 = function(xmlObj, callback) {
7586
if (item[f]) entry[f] = item[f][0];
7687
})
7788
if (item.description) {
78-
entry.content = item.description[0];
79-
if (typeof entry.content === 'object') {
80-
var builder = new XML2JS.Builder({headless: true});
81-
entry.content = builder.buildObject(entry.content);
82-
}
89+
entry.content = getContent(item.description[0]);
8390
entry.contentSnippet = getSnippet(entry.content);
8491
}
8592
if (item.guid) {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rss-parser",
3-
"version": "2.2.1",
3+
"version": "2.2.2",
44
"main": "index.js",
55
"scripts": {
66
"test": "mocha"

0 commit comments

Comments
 (0)