@@ -104,8 +104,10 @@ function shouldIncludeSection(context: GitBookSiteContext, section: SiteSection)
104104/**
105105 * Find the best default site space to navigate to for a givent section:
106106 * 1. If we are on the default, continue on the default.
107- * 2. If a site space has the same path as the current one, return it.
108- * 3. Otherwise, return the default one.
107+ * 2. If there are site spaces with the same language as the current, filter by language.
108+ * 3. If a site space has the same path as the current one, return it.
109+ * 4. Otherwise, return the default first language match.
110+ * 5. Otherwise, return the default one.
109111 */
110112function findBestTargetURL ( context : GitBookSiteContext , section : SiteSection ) {
111113 const { siteSpace : currentSiteSpace } = context ;
@@ -114,9 +116,15 @@ function findBestTargetURL(context: GitBookSiteContext, section: SiteSection) {
114116 return getSectionURL ( context , section ) ;
115117 }
116118
117- const bestMatch = section . siteSpaces . find ( ( siteSpace ) =>
118- areSiteSpacesEquivalent ( siteSpace , currentSiteSpace )
119- ) ;
119+ const possibleMatches =
120+ section . siteSpaces . filter ( ( siteSpace ) =>
121+ areSiteSpacesSameLanguage ( siteSpace , currentSiteSpace )
122+ ) ?? section . siteSpaces ;
123+
124+ const bestMatch =
125+ possibleMatches . find ( ( siteSpace ) => areSiteSpacesEquivalent ( siteSpace , currentSiteSpace ) ) ??
126+ possibleMatches [ 0 ] ;
127+
120128 if ( bestMatch ) {
121129 return getSiteSpaceURL ( context , bestMatch ) ;
122130 }
@@ -130,3 +138,7 @@ function findBestTargetURL(context: GitBookSiteContext, section: SiteSection) {
130138function areSiteSpacesEquivalent ( siteSpace1 : SiteSpace , siteSpace2 : SiteSpace ) {
131139 return siteSpace1 . path === siteSpace2 . path ;
132140}
141+
142+ function areSiteSpacesSameLanguage ( siteSpace1 : SiteSpace , siteSpace2 : SiteSpace ) {
143+ return siteSpace1 . space . language === siteSpace2 . space . language ;
144+ }
0 commit comments