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 #9 from gaurav-nelson/badredlinks
Browse files Browse the repository at this point in the history
highlights wrong URLs in red
  • Loading branch information
Gaurav Nelson committed Feb 8, 2018
2 parents 504669d + 57fdfbf commit fecd82d
Showing 1 changed file with 22 additions and 25 deletions.
47 changes: 22 additions & 25 deletions asciidoc-link-check
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,42 @@ 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);
}
})
//.option('-f, --showfilenames', 'show filenames')
.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.
//opts.showFileNames = (program.showfilenames === true);

var asciidoc = ''; // collect the asciidoc data, then process it
stream.on('data', function (chunk) {
asciidoc += chunk.toString();
}).on('end', function () {
//if (program.showfilenames) {
console.log(chalk.cyan('\nFILE: ' + filenameOutput))
//}
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], result.link);
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'));
Expand Down

0 comments on commit fecd82d

Please sign in to comment.