Skip to content

Instantly share code, notes, and snippets.

@lixiaoqity
Created November 4, 2020 19:31
Show Gist options
  • Save lixiaoqity/512c0170962a3a4750c465c5594c3f93 to your computer and use it in GitHub Desktop.
Save lixiaoqity/512c0170962a3a4750c465c5594c3f93 to your computer and use it in GitHub Desktop.
Add a new feature for the testLink repo.
diff --git a/README.md b/README.md
index e3f4bef..202ef50 100644
--- a/README.md
+++ b/README.md
@@ -16,13 +16,18 @@ npm install --- Install the modules.
<h2>Usage</h2>
-testLinks --- Help.
-testLinks v/version --- Check the version of tool.
-testLinks fileName --- Test the dead links in a file.
+testLinks --- Help.
+testLinks -v/--version --- Check the version of tool.
+testLinks fileName --- Test the dead links in a file.
+testLinks -s fileName --- check whether http:// urls actually work using https:// with the argument -s.
+testLinks -j/--json/\j fileName --- Test the dead links in a file and output json data.
+testLinks -i/--ignore/\i fileName --- Exclude URLs from our check based on a URL pattern file and test the dead links in a file.
+testLinks -t/--telescope/\t --- Check the links in the last 10 posts indexed by my local Telescope and Url is a local Telescope url(http://localhost:3000/posts).
+
<h2>Features</h2>
-The tool is used to find and test the status of Urls which start with http:// or https:// in a file.
+The tool is used to find and test the status of Urls which start with http:// or https:// in a file or url.
The green output and "good" mean the url which you test is safe and the status code is 200.
The red output and "bad" mean the url which you test is not safe and the status code is 400 or 404.
diff --git a/index.js b/index.js
index a62bb5b..ab935f8 100755
--- a/index.js
+++ b/index.js
@@ -3,12 +3,14 @@
const pjson = require('./package.json');
const readFile = require('./src/read-file');
const findIgnoreUrls = require('./src/find-ignore-urls');
+const readUrl = require('./src/read-url');
require('dotenv').config({ path: "./config/keys.env" });
let fileName = process.argv.slice(2);
let flag = false;
let flagj = false;
let flagError = false;
+//let flagt = false;
if (fileName.length < 1) {
console.log('Help:');
@@ -23,6 +25,9 @@ else {
console.log("name: testLinks");
console.log("version: " + pjson.version);
}
+ else if(fileName.length == 1 && (fileName[0] == "-t" || fileName[0] == "--telescope" || fileName[0] == "\t")){
+ readUrl("http://localhost:3000/posts",flagj);
+ }
else {
let ingoreUrlRegex = null;
@@ -34,6 +39,10 @@ else {
flagj = true;
fileName = fileName.slice(1);
}
+ // if ((fileName[0] == "-t" || fileName[0] == "--telescope" || fileName[0] == "\t") && fileName.length > 1) {
+ // flagt = true;
+ // fileName = fileName.slice(1);
+ // }
if ((fileName[0] == "-i" || fileName[0] == "--ignore" || fileName[0] == "\i") && fileName.length > 2) {
try {
ingoreUrlRegex = findIgnoreUrls(fileName[1])
@@ -46,6 +55,12 @@ else {
fileName = fileName.slice(2);
}
for (let i = 1; i <= fileName.length && flagError == false; i++) {
+ // if(flagt){
+ // readUrl(fileName[i-1],flagj);
+ // }
+ // else{
+ // readFile(fileName[i-1],ingoreUrlRegex,flag,flagj);
+ // }
readFile(fileName[i-1],ingoreUrlRegex,flag,flagj);
}
}
diff --git a/src/test-link.js b/src/test-link.js
index a2293b0..28c9890 100644
--- a/src/test-link.js
+++ b/src/test-link.js
@@ -30,6 +30,7 @@ const testLink = (u,j)=> {
}
}
})
+ .setMaxListeners(50)
}
module.exports = testLink;
\ No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment