1
0
mirror of synced 2026-01-08 03:01:54 -05:00

Merge pull request #17475 from github/error-handling-for-link-check-script

Error handling for link checker
This commit is contained in:
Sarah Schneider
2021-01-25 17:13:30 -05:00
committed by GitHub
2 changed files with 26 additions and 5 deletions

View File

@@ -24,13 +24,22 @@ module.exports = async (req, res, next) => {
if (guideIndex > 0) {
const prevGuidePath = track.guides[guideIndex - 1]
const { href, title } = await getLinkData(prevGuidePath, req.context, { title: true, intro: false })
const result = await getLinkData(prevGuidePath, req.context, { title: true, intro: false })
if (!result) return noTrack()
const href = result.href
const title = result.title
currentLearningTrack.prevGuide = { href, title }
}
if (guideIndex < track.guides.length - 1) {
const nextGuidePath = track.guides[guideIndex + 1]
const { href, title } = await getLinkData(nextGuidePath, req.context, { title: true, intro: false })
const result = await getLinkData(nextGuidePath, req.context, { title: true, intro: false })
if (!result) return noTrack()
const href = result.href
const title = result.title
currentLearningTrack.nextGuide = { href, title }
}

View File

@@ -3,6 +3,7 @@
const linkinator = require('linkinator')
const checker = new linkinator.LinkChecker()
const { deprecated } = require('../lib/enterprise-server-releases')
const englishRoot = 'http://localhost:4002/en'
// [start-readme]
//
@@ -10,17 +11,23 @@ const { deprecated } = require('../lib/enterprise-server-releases')
// 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.
//
// If you want to run it locally, you must have a local server running. You can use `npm run link-check`.
//
// [end-readme]
const config = {
path: 'http://localhost:4002/en',
path: englishRoot,
// 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 any link that is not an internal link.
// NOTE: If we want this test to check for broken asset paths in the future,
// we can remove `en` from the path below. This will increase the runtime, but that
// may be an acceptable tradeoff. For the record: `check-external-links`, which runs
// nightly, currently does check for broken asset paths.
`^((?!${englishRoot}).)*$`,
// Skip dist files
'/dist/index.*',
// Skip deprecated Enterprise content
@@ -37,6 +44,11 @@ async function main () {
.filter(link => link.state === 'BROKEN')
.map(link => { delete link.failureDetails; return link })
if (brokenLinks.length === 1 && brokenLinks[0].url === englishRoot) {
console.log(`You must be running ${englishRoot}!\n\nTry instead: npm run link-check`)
process.exit(1)
}
// Exit successfully if no broken links!
if (!brokenLinks.length) {
console.log('All links are good!')