Skip to content

Commit 2187e98

Browse files
committed
move some things around
1 parent 8815d15 commit 2187e98

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

script/check-english-links.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const englishRoot = `${root}/en`
1313
const { deprecated } = require('../lib/enterprise-server-releases')
1414
const got = require('got')
1515

16-
// Links with these codes may or may not really be broken
17-
const retryStatusCodes = [429, 503, 'Undefined']
16+
// Links with these codes may or may not really be broken.
17+
const retryStatusCodes = [429, 503]
1818

1919
// [start-readme]
2020
//
@@ -62,8 +62,8 @@ main()
6262
async function main () {
6363
// Clear and recreate a directory for logs.
6464
const logFile = path.join(__dirname, '../.linkinator/full.log')
65-
rimraf(logFile)
66-
mkdirp(logFile)
65+
rimraf(path.dirname(logFile))
66+
mkdirp(path.dirname(logFile))
6767

6868
// Update CLI output and append to logfile after each checked link.
6969
checker.on('link', result => {
@@ -76,15 +76,10 @@ async function main () {
7676
// Scan is complete! Filter the results for broken links.
7777
const brokenLinks = result
7878
.filter(link => link.state === 'BROKEN')
79-
// Coerce undefined status codes into strings so we can filter and display them (otherwise they stringify as 0)
80-
.map(link => {
81-
if (!link.status) link.status = 'Undefined'
82-
return link
83-
})
8479

8580
// Links to retry individually.
8681
const linksToRetry = brokenLinks
87-
.filter(link => retryStatusCodes.includes(link.status))
82+
.filter(link => !link.status || retryStatusCodes.includes(link.status))
8883

8984
await Promise.all(linksToRetry
9085
.map(async (link) => {
@@ -115,12 +110,20 @@ async function main () {
115110

116111
function displayBrokenLinks (brokenLinks) {
117112
// Sort results by status code.
118-
const allStatusCodes = uniq(brokenLinks.map(x => x.status))
113+
const allStatusCodes = uniq(brokenLinks
114+
// Coerce undefined status codes into `Invalid` strings so we can display them.
115+
// Without this, undefined codes get JSON.stringified as `0`, which is not useful output.
116+
.map(link => {
117+
if (!link.status) link.status = 'Invalid'
118+
return link
119+
})
120+
.map(link => link.status)
121+
)
119122

120123
allStatusCodes.forEach(statusCode => {
121124
const brokenLinksForStatus = brokenLinks.filter(x => x.status === statusCode)
122125

123-
console.log(`## Status code ${statusCode}: Found ${brokenLinksForStatus.length} broken links`)
126+
console.log(`## Status ${statusCode}: Found ${brokenLinksForStatus.length} broken links`)
124127
console.log('```')
125128
brokenLinksForStatus.forEach(brokenLinkObj => {
126129
console.log(JSON.stringify(brokenLinkObj, null, 2))

0 commit comments

Comments
 (0)