@@ -8,7 +8,8 @@ module.exports = async function genericToc (req, res, next) {
8
8
const currentSiteTree = req . context . siteTree [ req . context . currentLanguage ] [ req . context . currentVersion ]
9
9
10
10
// Find the array of child pages that start with the requested path.
11
- const currentPageInSiteTree = findPageInSiteTree ( currentSiteTree . childPages , req . context . currentPath )
11
+ const currentPageInSiteTree = findPageInSiteTree ( currentSiteTree . childPages , req . context . currentPath , req . context . currentLanguage )
12
+ if ( ! currentPageInSiteTree ) return next ( )
12
13
13
14
req . context . tocItems = sortBy (
14
15
await getUnsortedTocItems ( currentPageInSiteTree . childPages , req . context ) ,
@@ -21,13 +22,22 @@ module.exports = async function genericToc (req, res, next) {
21
22
22
23
// Recursively loop through the siteTree until we reach the point where the
23
24
// current siteTree page is the same as the requested page. Then stop.
24
- function findPageInSiteTree ( pageArray , currentPath ) {
25
+ function findPageInSiteTree ( pageArray , currentPath , currentLanguage ) {
25
26
const childPage = pageArray . find ( page => {
26
27
// Find a page that matches at least an initial part of the current path
27
28
const regex = new RegExp ( `^${ page . href } ($|/)` , 'm' )
28
29
return regex . test ( currentPath )
29
30
} )
30
31
32
+ // Fallback for outdated translations
33
+ if ( ! childPage && currentLanguage !== 'en' ) {
34
+ return findPageInSiteTree ( pageArray , currentPath . replace ( `/${ currentLanguage } ` , '/en' ) , 'en' )
35
+ }
36
+
37
+ if ( ! childPage && currentLanguage === 'en' ) {
38
+ return
39
+ }
40
+
31
41
if ( childPage . href === currentPath ) {
32
42
return childPage
33
43
}
0 commit comments