@@ -32,13 +32,22 @@ export default async function learningTrack(req, res, next) {
32
32
33
33
const currentLearningTrack = { trackName, trackProduct }
34
34
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 )
36
45
37
46
// The learning track path may use Liquid version conditionals, handle the
38
47
// case where the requested path is a learning track path but won't match
39
48
// because of a Liquid conditional.
40
49
if ( guideIndex < 0 ) {
41
- guideIndex = await indexOfLearningTrackGuide ( track . guides , guidePath , req . context )
50
+ guideIndex = await indexOfLearningTrackGuide ( trackGuidePaths , guidePath , req . context )
42
51
}
43
52
44
53
// 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) {
48
57
for ( const redirect of req . context . page . redirect_from ) {
49
58
if ( guideIndex >= 0 ) break
50
59
51
- guideIndex = await indexOfLearningTrackGuide ( track . guides , redirect , req . context )
60
+ guideIndex = await indexOfLearningTrackGuide ( trackGuidePaths , redirect , req . context )
52
61
}
53
62
}
54
63
55
64
if ( guideIndex < 0 ) return noTrack ( )
56
65
57
66
if ( guideIndex > 0 ) {
58
- const prevGuidePath = track . guides [ guideIndex - 1 ]
67
+ const prevGuidePath = trackGuidePaths [ guideIndex - 1 ]
59
68
const result = await getLinkData ( prevGuidePath , req . context , { title : true , intro : false } )
60
69
if ( ! result ) return noTrack ( )
61
70
@@ -64,8 +73,8 @@ export default async function learningTrack(req, res, next) {
64
73
currentLearningTrack . prevGuide = { href, title }
65
74
}
66
75
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 ]
69
78
const result = await getLinkData ( nextGuidePath , req . context , { title : true , intro : false } )
70
79
if ( ! result ) return noTrack ( )
71
80
0 commit comments