22
33const linkinator = require ( 'linkinator' )
44const checker = new linkinator . LinkChecker ( )
5- const { deprecated } = require ( '../lib/enterprise-server-releases' )
5+ const { deprecated, latest } = require ( '../lib/enterprise-server-releases' )
66const englishRoot = 'http://localhost:4002/en'
7+ const allowedVersions = [ 'dotcom' , 'enterprise-server' , 'github-ae' ]
78
89// [start-readme]
910//
10- // This script runs in CI via GitHub Action to check all *internal* links in English content,
11- // not including deprecated Enterprise Server content. This is different from script/check-english-links.js,
12- // which checks *all* links in the site, both internal and external, and is much slower.
11+ // This script runs in CI via GitHub Action to check all *internal* links in English content for a
12+ // given version, not including deprecated Enterprise Server content. This is different from
13+ // script/check-english-links.js, which checks *all* links in the site, both internal and external,
14+ // and is much slower.
1315//
1416// If you want to run it locally, you must have a local server running. You can use `npm run link-check`.
1517//
@@ -35,10 +37,30 @@ const config = {
3537 ]
3638}
3739
40+ // Customize config for specific versions
41+ if ( process . env . DOCS_VERSION === 'dotcom' ) {
42+ // If Dotcom, skip Enterprise Server and GitHub AE links
43+ config . linksToSkip . push ( '^.*/enterprise-server@.*$' , '^.*/enterprise/.*$' , '^.*/github-ae@latest.*$' )
44+ } else if ( process . env . DOCS_VERSION === 'enterprise-server' ) {
45+ // If Enterprise Server, skip links that are not Enterprise Server links
46+ config . path = `${ englishRoot } /enterprise-server@${ latest } `
47+ config . linksToSkip . push ( '^((?!enterprise-server@).)*$' )
48+ } else if ( process . env . DOCS_VERSION === 'github-ae' ) {
49+ // If GitHub AE, skip links that are not GitHub AE links
50+ config . path = `${ englishRoot } /github-ae@latest`
51+ config . linksToSkip . push ( '^((?!github-ae@latest).)*$' )
52+ }
53+
3854main ( )
3955
4056async function main ( ) {
57+ process . env . DOCS_VERSION && allowedVersions . includes ( process . env . DOCS_VERSION )
58+ ? console . log ( `Checking internal links for version ${ process . env . DOCS_VERSION } !\n` )
59+ : console . log ( 'Checking internal links for all versions!\n' )
60+
61+ console . time ( 'check' )
4162 const result = ( await checker . check ( config ) ) . links
63+ console . timeEnd ( 'check' )
4264
4365 const brokenLinks = result
4466 . filter ( link => link . state === 'BROKEN' )
0 commit comments