@@ -13,8 +13,8 @@ const englishRoot = `${root}/en`
13
13
const { deprecated } = require ( '../lib/enterprise-server-releases' )
14
14
const got = require ( 'got' )
15
15
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 ]
18
18
19
19
// [start-readme]
20
20
//
62
62
async function main ( ) {
63
63
// Clear and recreate a directory for logs.
64
64
const logFile = path . join ( __dirname , '../.linkinator/full.log' )
65
- rimraf ( logFile )
66
- mkdirp ( logFile )
65
+ rimraf ( path . dirname ( logFile ) )
66
+ mkdirp ( path . dirname ( logFile ) )
67
67
68
68
// Update CLI output and append to logfile after each checked link.
69
69
checker . on ( 'link' , result => {
@@ -76,15 +76,10 @@ async function main () {
76
76
// Scan is complete! Filter the results for broken links.
77
77
const brokenLinks = result
78
78
. 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
- } )
84
79
85
80
// Links to retry individually.
86
81
const linksToRetry = brokenLinks
87
- . filter ( link => retryStatusCodes . includes ( link . status ) )
82
+ . filter ( link => ! link . status || retryStatusCodes . includes ( link . status ) )
88
83
89
84
await Promise . all ( linksToRetry
90
85
. map ( async ( link ) => {
@@ -115,12 +110,20 @@ async function main () {
115
110
116
111
function displayBrokenLinks ( brokenLinks ) {
117
112
// 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
+ )
119
122
120
123
allStatusCodes . forEach ( statusCode => {
121
124
const brokenLinksForStatus = brokenLinks . filter ( x => x . status === statusCode )
122
125
123
- console . log ( `## Status code ${ statusCode } : Found ${ brokenLinksForStatus . length } broken links` )
126
+ console . log ( `## Status ${ statusCode } : Found ${ brokenLinksForStatus . length } broken links` )
124
127
console . log ( '```' )
125
128
brokenLinksForStatus . forEach ( brokenLinkObj => {
126
129
console . log ( JSON . stringify ( brokenLinkObj , null , 2 ) )
0 commit comments