@@ -19,6 +19,42 @@ import React from 'react';
19
19
import NavbarItem from '@theme-original/NavbarItem' ;
20
20
import { useLocation } from '@docusaurus/router' ;
21
21
22
+ const missingSites = calculateMissingSites ( require ( '../../../nodejs/sidebars' ) . docs , {
23
+ 'python' : require ( '../../../python/sidebars' ) . docs ,
24
+ 'dotnet' : require ( '../../../dotnet/sidebars' ) . docs ,
25
+ 'java' : require ( '../../../java/sidebars' ) . docs ,
26
+ } ) ;
27
+
28
+ function flatSidebar ( sidebar , result = [ ] ) {
29
+ for ( const item of sidebar ) {
30
+ if ( item . type === 'category' ) {
31
+ flatSidebar ( item . items , result ) ;
32
+ } else {
33
+ result . push ( item . id ) ;
34
+ }
35
+ }
36
+ return result ;
37
+ }
38
+
39
+ /**
40
+ * @param {object } baseSidebar
41
+ * @param {object } sidebars
42
+ * @returns {string[] }
43
+ */
44
+ function calculateMissingSites ( baseSidebar , sidebars ) {
45
+ const missing = [ ] ;
46
+ const baseItems = flatSidebar ( baseSidebar ) ;
47
+ for ( const [ language , sidebar ] of Object . entries ( sidebars ) ) {
48
+ const items = flatSidebar ( sidebar ) ;
49
+ const missingInLanguage = [ ] ;
50
+ for ( const item of baseItems ) {
51
+ if ( ! items . includes ( item ) )
52
+ missing . push ( `/${ language } /docs/${ item } ` ) ;
53
+ }
54
+ }
55
+ return missing ;
56
+ }
57
+
22
58
export default function NavbarItemWrapper ( props ) {
23
59
const location = useLocation ( ) ;
24
60
const languagePrefix = props [ 'data-language-prefix' ] ;
@@ -27,6 +63,8 @@ export default function NavbarItemWrapper(props) {
27
63
// Rewrite the new link
28
64
const newPathname = location . pathname . replace ( / ^ ( \/ ( j a v a | d o t n e t | p y t h o n ) ) ? \/ ( .* ) / , '$3' ) ;
29
65
propsOverrides . href = "pathname://" + languagePrefix + newPathname + location . hash ;
66
+ if ( isMissingInLanguagePort ( location . pathname , languagePrefix ) && newPathname . startsWith ( 'docs/test-' ) )
67
+ propsOverrides . href = "pathname://" + languagePrefix + 'docs/test-runners' ;
30
68
propsOverrides . autoAddBaseUrl = false
31
69
propsOverrides . target = '_self' ;
32
70
@@ -54,3 +92,15 @@ export default function NavbarItemWrapper(props) {
54
92
</ >
55
93
) ;
56
94
}
95
+
96
+ /**
97
+ * @param {string } location
98
+ * @param {string } linkPathPrefix
99
+ * @returns {boolean }
100
+ */
101
+ function isMissingInLanguagePort ( location , linkPathPrefix ) {
102
+ const languagePort = linkPathPrefix . replace ( / \/ / g, '' ) ;
103
+ if ( ! languagePort )
104
+ return false ;
105
+ return missingSites . includes ( '/' + languagePort + location . replace ( / ^ ( \/ ( j a v a | d o t n e t | p y t h o n ) ) ? ( \/ .* ) / , '$3' ) . replace ( / ( .* ) \. h t m l $ / , '$1' ) ) ;
106
+ }
0 commit comments