feedparser
Advanced tools
Comparing version 2.2.6 to 2.2.7
@@ -15,3 +15,25 @@ #!/usr/bin/env node | ||
process.stdin.pipe(new FeedParser()) | ||
var argv = require('mri')(process.argv.slice(2), { | ||
alias: { | ||
u: 'feedurl', | ||
g: 'group', | ||
j: 'json' | ||
}, | ||
boolean: [ | ||
'normalize', | ||
'addmeta', | ||
'resume_sax_error', | ||
'json' | ||
], | ||
default: { | ||
normalize: true, | ||
addmeta: true, | ||
resume_saxerror: true, | ||
json: !usingConsole | ||
} | ||
}); | ||
var items = []; | ||
process.stdin.pipe(new FeedParser(argv)) | ||
.on('error', console.error) | ||
@@ -21,9 +43,24 @@ .on('readable', function() { | ||
while (item = stream.read()) { | ||
if (usingConsole) { | ||
console.log(util.inspect(item, null, 10, true)); | ||
if (argv.group) { | ||
items.push(item); | ||
} | ||
else { | ||
console.log(JSON.stringify(item)); | ||
if (argv.json) { | ||
console.log(JSON.stringify(item)); | ||
} | ||
else { | ||
console.log(util.inspect(item, null, 10, true)); | ||
} | ||
} | ||
} | ||
}) | ||
.on('end', function () { | ||
if (argv.group) { | ||
if (argv.json) { | ||
console.log(JSON.stringify(items)); | ||
} | ||
else { | ||
console.log(util.inspect(items, null, 10, true)); | ||
} | ||
} | ||
}); |
2.2.7 / 2017-12-11 | ||
================== | ||
* Enhance cli to take feedparser options as cli parameters | ||
* Improve relative url resolution in RSS feeds | ||
* Add issue template | ||
* Add link to Dave Winer's demo to README | ||
2.2.6 / 2017-12-10 | ||
@@ -3,0 +11,0 @@ ================== |
@@ -245,3 +245,11 @@ /********************************************************************** | ||
if (baseurl && (node['#local'] === 'logo' || node['#local'] === 'icon') && node['#type'] === 'atom') { | ||
var mayHaveResolvableUrl = ( | ||
( | ||
(node['#local'] === 'logo' || node['#local'] === 'icon') && node['#type'] === 'atom' | ||
) || | ||
( | ||
node['#local'] === 'link' // include rss:link, even though it should _never_ be a relative URL | ||
) | ||
); | ||
if (baseurl && mayHaveResolvableUrl) { | ||
// Apply xml:base to these elements as they appear | ||
@@ -458,6 +466,9 @@ // rather than leaving it to the ultimate parser | ||
meta.xmlurl = meta.xmlUrl = link['@']['href']; | ||
if (this.xmlbase && this.xmlbase.length === 0) { | ||
this.xmlbase.unshift({ '#name': 'xml', '#': meta.xmlurl}); | ||
if (_.isAbsoluteUrl(meta.xmlurl) && this.xmlbase && this.xmlbase.length === 0) { | ||
this.xmlbase.unshift({ '#name': 'xml', '#': meta.xmlurl }); | ||
this.stack[0] = _.reresolve(this.stack[0], meta.xmlurl); | ||
} | ||
else if (this.xmlbase && this.xmlbase.length > 0) { | ||
meta.xmlurl = meta.xmlUrl = _.resolve(_.get(this.xmlbase[0], '#'), meta.xmlurl); | ||
} | ||
} | ||
@@ -474,6 +485,9 @@ else if (link['@']['rel'] == 'hub' && !(meta.cloud.href || meta.cloud.domain)) { | ||
} | ||
if (meta.link && this.xmlbase && this.xmlbase.length === 0) { | ||
if (_.isAbsoluteUrl(meta.link) && this.xmlbase && this.xmlbase.length === 0) { | ||
this.xmlbase.unshift({ '#name': 'xml', '#': meta.link}); | ||
this.stack[0] = _.reresolve(this.stack[0], meta.link); | ||
} | ||
else if (this.xmlbase && this.xmlbase.length > 0) { | ||
meta.link = _.resolve(_.get(this.xmlbase[0], '#'), meta.link); | ||
} | ||
}, this); | ||
@@ -488,6 +502,9 @@ } else { | ||
meta.xmlurl = meta.xmlUrl = el['@']['href']; | ||
if (this.xmlbase && this.xmlbase.length === 0) { | ||
if (_.isAbsoluteUrl(meta.xmlurl) && this.xmlbase && this.xmlbase.length === 0) { | ||
this.xmlbase.unshift({ '#name': 'xml', '#': meta.xmlurl}); | ||
this.stack[0] = _.reresolve(this.stack[0], meta.xmlurl); | ||
} | ||
else if (this.xmlbase && this.xmlbase.length > 0) { | ||
meta.xmlurl = meta.xmlUrl = _.resolve(_.get(this.xmlbase[0], '#'), meta.xmlurl); | ||
} | ||
} | ||
@@ -504,6 +521,9 @@ else if (el['@']['rel'] == 'hub' && !(meta.cloud.href || meta.cloud.domain)) { | ||
} | ||
if (meta.link && this.xmlbase && this.xmlbase.length === 0) { | ||
if (_.isAbsoluteUrl(meta.link) && this.xmlbase && this.xmlbase.length === 0) { | ||
this.xmlbase.unshift({ '#name': 'xml', '#': meta.link}); | ||
this.stack[0] = _.reresolve(this.stack[0], meta.link); | ||
} | ||
else if (this.xmlbase && this.xmlbase.length > 0) { | ||
meta.link = _.resolve(_.get(this.xmlbase[0], '#'), meta.link); | ||
} | ||
} | ||
@@ -892,6 +912,9 @@ break; | ||
this.meta.xmlurl = this.meta.xmlUrl = item.source['url']; | ||
if (this.xmlbase && this.xmlbase.length === 0) { | ||
if (_.isAbsoluteUrl(item.source['url']) && this.xmlbase && this.xmlbase.length === 0) { | ||
this.xmlbase.unshift({ '#name': 'xml', '#': item.source['url']}); | ||
this.stack[0] = _.reresolve(this.stack[0], item.source['url']); | ||
} | ||
else if (this.xmlbase && this.xmlbase.length > 0) { | ||
this.meta.xmlurl = this.meta.xmlUrl = item.source['url'] = _.resolve(_.get(this.xmlbase[0], '#'), item.source['url']); | ||
} | ||
} | ||
@@ -898,0 +921,0 @@ break; |
@@ -58,6 +58,8 @@ var URL = require('url') | ||
/* | ||
* Expose require('url').resolve | ||
* Expose require('url').resolve, safely returning if either parameter | ||
* isn't provided | ||
* @private | ||
*/ | ||
function resolve (baseUrl, pathUrl) { | ||
if (!baseUrl || !pathUrl) return pathUrl; | ||
return URL.resolve(baseUrl, pathUrl); | ||
@@ -68,2 +70,14 @@ } | ||
/* | ||
* Check whether a given uri is an absolute URL | ||
* @param {String} uri | ||
* @private | ||
*/ | ||
function isAbsoluteUrl (uri) { | ||
if (!uri || typeof uri !== 'string') return false; | ||
var parts = URL.parse(uri); | ||
return Boolean(parts.host); | ||
} | ||
exports.isAbsoluteUrl = isAbsoluteUrl; | ||
/* | ||
* Check whether a given namespace URI matches the given default | ||
@@ -119,3 +133,3 @@ * | ||
if (level[el].constructor.name === 'Object') { | ||
if (el == 'logo' || el == 'icon') { | ||
if (el == 'logo' || el == 'icon' || el == 'link') { | ||
if ('#' in level[el]) { | ||
@@ -131,3 +145,4 @@ level[el]['#'] = URL.resolve(baseurl, level[el]['#']); | ||
} | ||
} else if ('@' in level[el]) { | ||
} | ||
if ('@' in level[el]) { | ||
var attrs = Object.keys(level[el]['@']); | ||
@@ -134,0 +149,0 @@ attrs.forEach(function (name) { |
@@ -8,3 +8,3 @@ { | ||
}, | ||
"version": "2.2.6", | ||
"version": "2.2.7", | ||
"keywords": [ | ||
@@ -45,2 +45,3 @@ "rss", | ||
"lodash.uniq": "^4.5.0", | ||
"mri": "^1.1.0", | ||
"readable-stream": "^2.2.2", | ||
@@ -47,0 +48,0 @@ "sax": "^1.2.4" |
@@ -72,2 +72,4 @@ # Feedparser - Robust RSS, Atom, and RDF feed parsing in Node.js | ||
You can also check out this nice [working demo](https://github.com/scripting/feedParserDemo). | ||
### options | ||
@@ -74,0 +76,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
79134
1333
223
9
+ Addedmri@^1.1.0
+ Addedmri@1.2.0(transitive)