Skip to content

Commit a147879

Browse files
authored
Only interested in current version's guides (github#22535)
1 parent dca7e56 commit a147879

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

middleware/learning-track.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,22 @@ export default async function learningTrack(req, res, next) {
3232

3333
const currentLearningTrack = { trackName, trackProduct }
3434
const guidePath = getPathWithoutLanguage(getPathWithoutVersion(req.pagePath))
35-
let guideIndex = track.guides.findIndex((path) => path === guidePath)
35+
36+
// The raw track.guides will return all guide paths, need to use getLinkData
37+
// so we only get guides available in the current version
38+
const trackGuides = await getLinkData(track.guides, req.context)
39+
40+
const trackGuidePaths = trackGuides.map((guide) => {
41+
return getPathWithoutLanguage(getPathWithoutVersion(guide.href))
42+
})
43+
44+
let guideIndex = trackGuidePaths.findIndex((path) => path === guidePath)
3645

3746
// The learning track path may use Liquid version conditionals, handle the
3847
// case where the requested path is a learning track path but won't match
3948
// because of a Liquid conditional.
4049
if (guideIndex < 0) {
41-
guideIndex = await indexOfLearningTrackGuide(track.guides, guidePath, req.context)
50+
guideIndex = await indexOfLearningTrackGuide(trackGuidePaths, guidePath, req.context)
4251
}
4352

4453
// Also check if the learning track path is now a redirect to the requested
@@ -48,14 +57,14 @@ export default async function learningTrack(req, res, next) {
4857
for (const redirect of req.context.page.redirect_from) {
4958
if (guideIndex >= 0) break
5059

51-
guideIndex = await indexOfLearningTrackGuide(track.guides, redirect, req.context)
60+
guideIndex = await indexOfLearningTrackGuide(trackGuidePaths, redirect, req.context)
5261
}
5362
}
5463

5564
if (guideIndex < 0) return noTrack()
5665

5766
if (guideIndex > 0) {
58-
const prevGuidePath = track.guides[guideIndex - 1]
67+
const prevGuidePath = trackGuidePaths[guideIndex - 1]
5968
const result = await getLinkData(prevGuidePath, req.context, { title: true, intro: false })
6069
if (!result) return noTrack()
6170

@@ -64,8 +73,8 @@ export default async function learningTrack(req, res, next) {
6473
currentLearningTrack.prevGuide = { href, title }
6574
}
6675

67-
if (guideIndex < track.guides.length - 1) {
68-
const nextGuidePath = track.guides[guideIndex + 1]
76+
if (guideIndex < trackGuidePaths.length - 1) {
77+
const nextGuidePath = trackGuidePaths[guideIndex + 1]
6978
const result = await getLinkData(nextGuidePath, req.context, { title: true, intro: false })
7079
if (!result) return noTrack()
7180

0 commit comments

Comments
 (0)