From 8296635976c1589582398929d21aff6c08d3266e Mon Sep 17 00:00:00 2001 From: "git@aroneiermann.de" Date: Wed, 16 Sep 2015 16:16:17 +0200 Subject: [PATCH 1/5] Print article.content instead of article.html. Return negativ exit code on error. --- src/cli.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cli.js b/src/cli.js index fc05a00..aa10321 100755 --- a/src/cli.js +++ b/src/cli.js @@ -15,10 +15,15 @@ if(argv.h){ return; } -var callback = function(err, article){ - if(err) +var callback = function(err, article, meta){ + if(err){ console.error(err); - process.stdout.write(article.html); + process.exit(-1); + } + if(!article.content){ + process.exit(-2); + } + process.stdout.write(article.content); } if(typeof argv.url === 'string'){ From 87c76bcf7d15983c07686988bef44fc291f637b6 Mon Sep 17 00:00:00 2001 From: "git@aroneiermann.de" Date: Wed, 16 Sep 2015 16:23:08 +0200 Subject: [PATCH 2/5] Print article.title as h1. --- src/cli.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cli.js b/src/cli.js index aa10321..5000c45 100755 --- a/src/cli.js +++ b/src/cli.js @@ -23,6 +23,7 @@ var callback = function(err, article, meta){ if(!article.content){ process.exit(-2); } + process.stdout.write("

" + article.title + "

"); process.stdout.write(article.content); } From 5ac1eff5ca23eafa5e121bf41f0b7ed691f52ed1 Mon Sep 17 00:00:00 2001 From: "git@aroneiermann.de" Date: Wed, 16 Sep 2015 19:43:21 +0200 Subject: [PATCH 3/5] Initializing variable. Removes starting "undefined" from html. --- src/cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli.js b/src/cli.js index 5000c45..1347fa3 100755 --- a/src/cli.js +++ b/src/cli.js @@ -30,7 +30,7 @@ var callback = function(err, article, meta){ if(typeof argv.url === 'string'){ read(argv.url, callback); } else { - var html; + var html = ""; process.stdin.on("data", function(chunk){ html += chunk; }); From 460a6e97c56b926dac65898ced10edd97ad5c915 Mon Sep 17 00:00:00 2001 From: Aron Eiermann Date: Sun, 20 Sep 2015 19:24:52 +0200 Subject: [PATCH 4/5] Add a h1 when the articleContent doesn't contain a h1. --- src/readability.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/readability.js b/src/readability.js index 4096250..63cf001 100644 --- a/src/readability.js +++ b/src/readability.js @@ -27,7 +27,7 @@ function Readability(window, options) { }; this.__defineGetter__('content', function() { - return this.getContent(true); + return this.getContent(this, true); }); this.__defineGetter__('title', function() { return this.getTitle(true); @@ -48,7 +48,7 @@ Readability.prototype.close = function() { this._document = null; }; -Readability.prototype.getContent = function(notDeprecated) { +Readability.prototype.getContent = function(Readability, notDeprecated) { if (!notDeprecated) { console.warn('The method `getContent()` is deprecated, using `content` property instead.'); } @@ -65,6 +65,13 @@ Readability.prototype.getContent = function(notDeprecated) { } } + // Add a h1 tag with the title when the articleContent doesn't contain a h1. + if(articleContent.getElementsByTagName("h1").length === 0){ + var h1 = this._document.createElement("h1"); + h1.innerHTML = Readability.title; + articleContent.insertBefore(h1, articleContent.childNodes[0]); + } + return this.cache['article-content'] = articleContent.innerHTML; }; From e795f59e7a41d869f624cd3139fe3be2d2f6b52e Mon Sep 17 00:00:00 2001 From: Aron Eiermann Date: Sun, 20 Sep 2015 19:27:03 +0200 Subject: [PATCH 5/5] Revert "Print article.title as h1." This reverts commit 87c76bcf7d15983c07686988bef44fc291f637b6. --- src/cli.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cli.js b/src/cli.js index 1347fa3..a8b0bce 100755 --- a/src/cli.js +++ b/src/cli.js @@ -23,7 +23,6 @@ var callback = function(err, article, meta){ if(!article.content){ process.exit(-2); } - process.stdout.write("

" + article.title + "

"); process.stdout.write(article.content); }