forked from canada-ca/ucvdcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
link-check.js
39 lines (31 loc) · 1.03 KB
/
link-check.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env node
'use strict';
var markdownLinkCheck = require('markdown-link-check');
var fs = require("fs");
var glob = require("glob");
var path = require("path");
var chalk = require("chalk");
var files = glob.sync("**/*.md", {ignore: ["node_modules/**/*.md", "**/digital-playbook.md", "**/guide-numerique.md"]})
var opts = JSON.parse(fs.readFileSync(".markdown-link-check.json"));
files.forEach(function(file) {
var markdown = fs.readFileSync(file).toString();
opts.baseUrl = path.basename(__dirname) + "/"
markdownLinkCheck(markdown, opts, function (err, results) {
if (err) {
console.error('Error', err);
return;
}
console.log(chalk.green("Reading: " + file));
results.forEach(function (result) {
if(result.status === "dead") {
if (result.statusCode == 500) {
console.log(chalk.yellow("Server error on target: " + result.link));
}
else {
process.exitCode = 1
console.log(chalk.red("Dead: " + result.link));
}
}
});
});
});