Skip to content

Commit 80c9442

Browse files
authored
Merge branch 'main' into shati-patel-patch-1
2 parents 0d3b045 + b6344c9 commit 80c9442

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

middleware/learning-track.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,22 @@ module.exports = async (req, res, next) => {
2424

2525
if (guideIndex > 0) {
2626
const prevGuidePath = track.guides[guideIndex - 1]
27-
const { href, title } = await getLinkData(prevGuidePath, req.context, { title: true, intro: false })
27+
const result = await getLinkData(prevGuidePath, req.context, { title: true, intro: false })
28+
if (!result) return noTrack()
29+
30+
const href = result.href
31+
const title = result.title
2832
currentLearningTrack.prevGuide = { href, title }
2933
}
3034

3135
if (guideIndex < track.guides.length - 1) {
3236
const nextGuidePath = track.guides[guideIndex + 1]
33-
const { href, title } = await getLinkData(nextGuidePath, req.context, { title: true, intro: false })
37+
const result = await getLinkData(nextGuidePath, req.context, { title: true, intro: false })
38+
if (!result) return noTrack()
39+
40+
const href = result.href
41+
const title = result.title
42+
3443
currentLearningTrack.nextGuide = { href, title }
3544
}
3645

script/check-internal-links.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,31 @@
33
const linkinator = require('linkinator')
44
const checker = new linkinator.LinkChecker()
55
const { deprecated } = require('../lib/enterprise-server-releases')
6+
const englishRoot = 'http://localhost:4002/en'
67

78
// [start-readme]
89
//
910
// This script runs in CI via GitHub Action to check all *internal* links in English content,
1011
// not including deprecated Enterprise Server content. This is different from script/check-english-links.js,
1112
// which checks *all* links in the site, both internal and external, and is much slower.
1213
//
14+
// If you want to run it locally, you must have a local server running. You can use `npm run link-check`.
15+
//
1316
// [end-readme]
1417

1518
const config = {
16-
path: 'http://localhost:4002/en',
19+
path: englishRoot,
1720
// Use concurrency = 10 to optimize for Actions
1821
// See https://github.com/JustinBeckwith/linkinator/issues/135#issuecomment-623240879
1922
concurrency: 10,
2023
recurse: true,
2124
linksToSkip: [
22-
// Skip any link that is not an internal link
23-
'^((?!http://localhost:4002/en).)*$',
25+
// Skip any link that is not an internal link.
26+
// NOTE: If we want this test to check for broken asset paths in the future,
27+
// we can remove `en` from the path below. This will increase the runtime, but that
28+
// may be an acceptable tradeoff. For the record: `check-external-links`, which runs
29+
// nightly, currently does check for broken asset paths.
30+
`^((?!${englishRoot}).)*$`,
2431
// Skip dist files
2532
'/dist/index.*',
2633
// Skip deprecated Enterprise content
@@ -37,6 +44,11 @@ async function main () {
3744
.filter(link => link.state === 'BROKEN')
3845
.map(link => { delete link.failureDetails; return link })
3946

47+
if (brokenLinks.length === 1 && brokenLinks[0].url === englishRoot) {
48+
console.log(`You must be running ${englishRoot}!\n\nTry instead: npm run link-check`)
49+
process.exit(1)
50+
}
51+
4052
// Exit successfully if no broken links!
4153
if (!brokenLinks.length) {
4254
console.log('All links are good!')

0 commit comments

Comments
 (0)