forked from gcharest/stratosphere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
link-check.js
45 lines (34 loc) · 1.13 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
40
41
42
43
44
45
#!/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"]})
var config = JSON.parse(fs.readFileSync(".markdown-link-check.json"));
config.timeout = '30s'
var opts = JSON.parse(fs.readFileSync(".markdown-link-check.json"));
files.forEach(function(file) {
var markdown = fs.readFileSync(file).toString();
let opts = Object.assign({}, config);
opts.baseUrl = path.dirname(path.resolve(file)) + '/';
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));
}
}
});
});
});