forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-internal-links.js
executable file
·52 lines (43 loc) · 1.6 KB
/
check-internal-links.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
46
47
48
49
50
51
52
#!/usr/bin/env node
const linkinator = require('linkinator')
const checker = new linkinator.LinkChecker()
const { deprecated } = require('../lib/enterprise-server-releases')
// [start-readme]
//
// This script runs in CI via GitHub Action to check all *internal* links in English content,
// not including deprecated Enterprise Server content. This is different from script/check-english-links.js,
// which checks *all* links in the site, both internal and external, and is much slower.
//
// [end-readme]
const config = {
path: 'http://localhost:4002/en',
// Use concurrency = 10 to optimize for Actions
// See https://github.com/JustinBeckwith/linkinator/issues/135#issuecomment-623240879
concurrency: 10,
recurse: true,
linksToSkip: [
// Skip any link that is not an internal link
'^((?!http://localhost:4002/en).)*$',
// Skip dist files
'/dist/index.*',
// Skip deprecated Enterprise content
`enterprise(-server@|/)(${deprecated.join('|')})/?`
]
}
main()
async function main () {
const result = (await checker.check(config)).links
const brokenLinks = result
.filter(link => link.state === 'BROKEN')
.map(link => { delete link.failureDetails; return link })
// Exit successfully if no broken links!
if (!brokenLinks.length) {
console.log('All links are good!')
process.exit(0)
}
console.log('\n==============================')
console.log(`Found ${brokenLinks.length} total broken links: ${JSON.stringify([...brokenLinks], null, 2)}`)
console.log('==============================\n')
// Exit unsuccessfully if broken links are found.
process.exit(1)
}