Skip to content
This repository has been archived by the owner on May 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #15 from gerbil/patch-1
Browse files Browse the repository at this point in the history
Google analytics removed
  • Loading branch information
gaurav-nelson committed Nov 8, 2018
2 parents a4f2ad7 + 9421b29 commit a42750a
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 90 deletions.
84 changes: 38 additions & 46 deletions asciidoc-link-check
Original file line number Diff line number Diff line change
Expand Up @@ -9,66 +9,58 @@ var program = require('commander');
var request = require('request');
var url = require('url');
var path = require('path');
const uuidv4 = require('uuid/v4');
var thisuuid = uuidv4();

request({
uri: "https://www.google-analytics.com/collect",
method: "POST",
form: {"v": "1", "t": "event", "tid": "UA-106891751-2", "cid": thisuuid, "ec":"linkcheck", "ea":"main" }
});

var statusLabels = {
alive: chalk.green('✓'),
dead: chalk.red('✖')
alive: chalk.green('✓'),
dead: chalk.red('✖')
};

var error = false;
var opts = {};
var filenameOutput = "";
var stream = process.stdin; // read from stdin unless a filename is given
program.option('-p, --progress', 'show progress bar').arguments('[filenameOrUrl]').action(function (filenameOrUrl) {
filenameOutput = filenameOrUrl;
if (/https?:/.test(filenameOrUrl)) {
stream = request.get(filenameOrUrl);
try { // extract baseUrl from supplied URL
var parsed = url.parse(filenameOrUrl);
delete parsed.search;
delete parsed.hash;
if (parsed.pathname.lastIndexOf('/') !== -1) {
parsed.pathname = parsed.pathname.substr(0, parsed.pathname.lastIndexOf('/') + 1);
}
opts.baseUrl = url.format(parsed);
} catch (err) { /* ignore error */ }
} else {
opts.baseUrl = 'file://' + path.dirname(path.resolve(filenameOrUrl));
stream = fs.createReadStream(filenameOrUrl);
}
})
.parse(process.argv);
filenameOutput = filenameOrUrl;
if (/https?:/.test(filenameOrUrl)) {
stream = request.get(filenameOrUrl);
try { // extract baseUrl from supplied URL
var parsed = url.parse(filenameOrUrl);
delete parsed.search;
delete parsed.hash;
if (parsed.pathname.lastIndexOf('/') !== -1) {
parsed.pathname = parsed.pathname.substr(0, parsed.pathname.lastIndexOf('/') + 1);
}
opts.baseUrl = url.format(parsed);
} catch (err) { /* ignore error */ }
} else {
opts.baseUrl = 'file://' + path.dirname(path.resolve(filenameOrUrl));
stream = fs.createReadStream(filenameOrUrl);
}
})
.parse(process.argv);

opts.showProgressBar = (program.progress === true); // force true or undefined to be true or false.

var asciidoc = ''; // collect the asciidoc data, then process it
stream.on('data', function (chunk) {
asciidoc += chunk.toString();
asciidoc += chunk.toString();
}).on('end', function () {
console.log(chalk.cyan('\nFILE: ' + filenameOutput))
asciidocLinkCheck(asciidoc, opts, function (err, results) {
console.log(chalk.cyan('\nFILE: ' + filenameOutput))
asciidocLinkCheck(asciidoc, opts, function (err, results) {

if (results.length === 0) {
console.log(chalk.yellow('No hyperlinks found!\n'))
}
results.forEach(function (result) {
if (result.status === 'dead') {
error = true;
console.log('[%s] %s', statusLabels[result.status], chalk.red(result.link));
} else
console.log('[%s] %s', statusLabels[result.status], result.link);
});
if (error) {
console.error(chalk.red('ERROR: dead links found!\n'));
process.exit(1);
}
});
if (results.length === 0) {
console.log(chalk.yellow('No hyperlinks found!\n'))
}
results.forEach(function (result) {
if (result.status === 'dead') {
error = true;
console.log('[%s] %s', statusLabels[result.status], chalk.red(result.link));
} else
console.log('[%s] %s', statusLabels[result.status], result.link);
});
if (error) {
console.error(chalk.red('ERROR: dead links found!\n'));
process.exit(1);
}
});
});
87 changes: 43 additions & 44 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,44 @@
{
"name": "asciidoc-link-check",
"version": "1.0.10",
"description": "Checks if all hyperlinks in an asciidoc file are alive(or dead).",
"bin": {
"asciidoc-link-check": "asciidoc-link-check"
},
"main": "index.js",
"scripts": {
"pretest": "jshint index.js asciidoc-link-check"
},
"repository": {
"type": "git",
"url": "git://github.com/gaurav-nelson/asciidoc-link-check.git"
},
"keywords": [
"asciidoc",
"adoc",
"link",
"hyperlink",
"href",
"check",
"checker"
],
"author": "Gaurav Nelson",
"license": "MIT",
"bugs": {
"url": "https://github.com/gaurav-nelson/asciidoc-link-check/issues"
},
"homepage": "https://github.com/gaurav-nelson/asciidoc-link-check#readme",
"dependencies": {
"asciidoc-link-extractor": ">=1.0.2",
"async": ">=2.6.1",
"chalk": ">=2.4.1",
"commander": ">=2.16.0",
"link-check": ">=4.4.4",
"lodash": ">=4.17.10",
"progress": ">=2.0.0",
"request": ">=2.87.0",
"uuid": ">=3.3.2"
},
"devDependencies": {
"jshint": "^2.9.5"
}
}
"name": "asciidoc-link-check",
"version": "1.0.10",
"description": "Checks if all hyperlinks in an asciidoc file are alive(or dead).",
"bin": {
"asciidoc-link-check": "asciidoc-link-check"
},
"main": "index.js",
"scripts": {
"pretest": "jshint index.js asciidoc-link-check"
},
"repository": {
"type": "git",
"url": "git://github.com/gaurav-nelson/asciidoc-link-check.git"
},
"keywords": [
"asciidoc",
"adoc",
"link",
"hyperlink",
"href",
"check",
"checker"
],
"author": "Gaurav Nelson",
"license": "MIT",
"bugs": {
"url": "https://github.com/gaurav-nelson/asciidoc-link-check/issues"
},
"homepage": "https://github.com/gaurav-nelson/asciidoc-link-check#readme",
"dependencies": {
"asciidoc-link-extractor": ">=1.0.2",
"async": ">=2.6.1",
"chalk": ">=2.4.1",
"commander": ">=2.19.0",
"link-check": ">=4.4.4",
"lodash": ">=4.17.11",
"progress": ">=2.0.1",
"request": "^2.88.0"
},
"devDependencies": {
"jshint": "^2.9.5"
}
}

0 comments on commit a42750a

Please sign in to comment.