v1.0.3: better stability & performance + no URL warning

yargs
gardenapple 4 years ago
parent 099752fa45
commit 01276e726b
No known key found for this signature in database
GPG Key ID: CAF17E9ABE789268

@ -17,12 +17,9 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const Readability = require("readability");
const JSDOM = require("jsdom").JSDOM;
const parseArgs = require("minimist");
const fs = require("fs");
const he = require("he");
const ExitCodes = {
@ -193,11 +190,24 @@ if (args.properties) {
}
}
async function read(stream) {
const chunks = [];
for await (const chunk of stream){
chunks.push(chunk);
}
return Buffer.concat(chunks).toString('utf8');
}
if (inputIsFromStdin) {
onLoadDOM(new JSDOM(fs.readFileSync(0, 'utf-8')), {
url: documentURL
if (!args["quiet"]) {
console.error("Reading...");
if (!documentURL)
console.error("Note: piping input with unknown " +
"URL. This means that relative links will " +
"be broken. Supply the --url parameter to fix.")
}
read(process.stdin).then(result => {
onLoadDOM(new JSDOM(result, { url: documentURL }));
});
} else {
if (!args["quiet"])
@ -221,8 +231,15 @@ if (inputIsFromStdin) {
promiseGetHTML.then(onLoadDOM, onLoadDOMError)
}
//Taken from https://stackoverflow.com/a/22706073/5701177
function escapeHTML(string, document){
var p = document.createElement("p");
p.appendChild(document.createTextNode(string));
return p.innerHTML;
}
function onLoadDOM(dom) {
const document = dom.window.document
const document = dom.window.document;
if (!args["quiet"])
console.error("Parsing...");
let reader = new Readability(document);
@ -235,6 +252,7 @@ function onLoadDOM(dom) {
let writeStream;
if (outputArg) {
const fs = require("fs");
writeStream = fs.createWriteStream(outputArg);
} else {
writeStream = process.stdout;
@ -256,7 +274,7 @@ function onLoadDOM(dom) {
writeStream.write(`Direction: ${article.dir}\n`);
}
if (wantedProperties.includes(Properties.htmlTitle)) {
writeStream.write(`<h1>${he.escape(article.title)}</h1>\n`);
writeStream.write(`<h1>${escapeHTML(article.title, document)}</h1>\n`);
}
if (wantedProperties.includes(Properties.htmlContent)) {
writeStream.write(article.content);

7
package-lock.json generated

@ -1,6 +1,6 @@
{
"name": "@gardenapple/readability-cli",
"version": "1.0.0",
"version": "1.0.2",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -264,11 +264,6 @@
"har-schema": "^2.0.0"
}
},
"he": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz",
"integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw=="
},
"html-encoding-sniffer": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-2.0.1.tgz",

@ -1,6 +1,6 @@
{
"name": "@gardenapple/readability-cli",
"version": "1.0.2",
"version": "1.0.3",
"description": "Firefox Reader Mode in your terminal - get useful text from a web page using Mozilla's Readability library",
"main": "index.js",
"bin": {
@ -21,7 +21,6 @@
],
"license": "GPL-3.0-only",
"dependencies": {
"he": "^1.2.0",
"jsdom": "^16.3.0",
"minimist": "^1.2.5",
"readability": "github:mozilla/readability#master"

Loading…
Cancel
Save