@@ -6,8 +6,25 @@ import CloudBanner from "./components/CloudBanner.vue";
66import KapaWidget from './components/KapaWidget.vue' ;
77import UserFeedback from './components/TocWithFeedback' ;
88import { usePostHog } from "./lib/usePosthog" ;
9+ import SidebarLayout from "./layouts/SidebarLayout.vue" ;
910
10- declare const __VERSIONS__ : { latest : string , selected : string , all : string [ ] }
11+ declare const __VERSIONS__ : {
12+ latest : string ,
13+ selected : string ,
14+ all : {
15+ id : string ,
16+ group : string ,
17+ basePath : string ,
18+ versions : {
19+ version : string ,
20+ path : string ,
21+ startPage : string ,
22+ preview ?: boolean ,
23+ deprecated ?: boolean ,
24+ hide ?: boolean
25+ } [ ]
26+ } [ ]
27+ }
1128
1229const storageKey = "VUEPRESS_TAB_STORE" ;
1330
@@ -30,15 +47,6 @@ const findEsMeta = (route) => {
3047 }
3148}
3249
33- interface ClientConfig {
34- enhance ?: ( context : {
35- app : any ;
36- router : Router ;
37- siteData : any ;
38- } ) => void | Promise < void > ;
39- setup ?: ( ) => void ;
40- }
41-
4250const removeHtml = ( path : string ) => path . replace ( ".html" , "" ) ;
4351
4452const reload = ( ) => {
@@ -55,14 +63,16 @@ const leave = (to: RouteLocationNormalized, from: RouteLocationNormalized) => {
5563 }
5664}
5765
58- const { posthog } = usePostHog ( ) ;
66+ const { posthog} = usePostHog ( ) ;
5967
6068export default defineClientConfig ( {
69+ layouts : {
70+ Layout : SidebarLayout
71+ } ,
6172 enhance ( { app, router, _} ) {
6273 app . component ( "CloudBanner" , CloudBanner ) ;
6374 app . component ( "KapaWidget" , KapaWidget ) ;
6475 app . component ( "UserFeedback" , UserFeedback ) ;
65- const apiPath = __VERSIONS__ . latest . replace ( "server" , "http-api" ) ;
6676 const addFixedRoute = ( from : string , to : string ) => router . addRoute ( {
6777 path : from , redirect : _ => {
6878 reload ( ) ;
@@ -79,16 +89,16 @@ export default defineClientConfig({
7989 } ) ;
8090
8191 // Router configuration
82- addFixedRoute ( "/http-api/" , `${ apiPath } /introduction` ) ;
92+ addFixedRoute ( "/server/ http-api/" , `/ ${ __VERSIONS__ . latest } /http-api /introduction` ) ;
8393 addFixedRoute ( "/cloud/" , `/cloud/introduction.html` ) ;
8494 router . afterEach ( ( ) => {
8595 setTimeout ( ( ) => { // to ensure this runs after DOM updates
8696 try {
87- const { code} = JSON . parse ( localStorage . getItem ( 'VUEPRESS_TAB_STORE' ) ) ;
97+ const { code} = JSON . parse ( localStorage . getItem ( 'VUEPRESS_TAB_STORE' ) ! ) ;
8898 if ( code ) { // If a valid 'code' is found in localStorage
8999 Array . from ( document . querySelectorAll ( '.vp-tab-nav' ) )
90100 . forEach ( ( button : HTMLButtonElement ) => {
91- if ( button . textContent . trim ( ) === code ) {
101+ if ( button . textContent ! . trim ( ) === code ) {
92102 button . click ( ) ; // click the button to switch the tab
93103 }
94104 } ) ;
@@ -98,18 +108,36 @@ export default defineClientConfig({
98108 }
99109 } , 0 ) ;
100110 } ) ;
101- const operatorLatest = __VERSIONS__ . all . filter ( x => x . id == 'kubernetes-operator' ) [ 0 ] . versions [ 0 ] . version ;
111+ const operatorLatest = __VERSIONS__ . all . filter ( x => x . id === 'kubernetes-operator' ) [ 0 ] . versions [ 0 ] . version ;
102112 addDynamicRoute ( "/server/kubernetes-operator" , to => `/server/kubernetes-operator/${ operatorLatest } /getting-started/` ) ;
103113 addDynamicRoute ( "/server/kubernetes-operator/:version" , to => `/server/kubernetes-operator/${ to . params . version } /getting-started/` ) ;
104114
115+ addDynamicRoute ( '/clients/:lang(dotnet|golang|java|node|python|rust)/legacy/:version' , to => {
116+ const version = to . params . version ;
117+ const latestVersion = __VERSIONS__ . all . find ( x => x . id === `${ to . params . lang } -client` ) ?. versions . find ( v => v . path === `legacy/${ version } ` )
118+ return `/clients/${ to . params . lang } /legacy/${ to . params . version } /${ latestVersion ?. startPage } ` ;
119+ } ) ;
120+ addDynamicRoute ( '/clients/:lang(dotnet|golang|java|node|python|rust)/legacy' , to => {
121+ const latestVersion = __VERSIONS__ . all . find ( x => x . id === `${ to . params . lang } -client` ) ?. versions . find ( v => v . path . startsWith ( 'legacy/' ) )
122+ return `/clients/${ to . params . lang } /${ latestVersion ?. path } /${ latestVersion ?. startPage } ` ;
123+ } )
124+
125+ addDynamicRoute ( '/clients/:lang(dotnet|golang|java|node|python|rust)/:version' , to => {
126+ const version = to . params . version ;
127+ const latestVersion = __VERSIONS__ . all . find ( x => x . id === `${ to . params . lang } -client` ) ?. versions . find ( v => v . path === version )
128+ return `/clients/${ to . params . lang } /${ version } /${ latestVersion ?. startPage } ` ;
129+ } ) ;
130+ addDynamicRoute ( '/clients/:lang(dotnet|golang|java|node|python|rust)' , to => {
131+ const latestVersion = __VERSIONS__ . all . find ( x => x . id === `${ to . params . lang } -client` ) ?. versions [ 0 ]
132+ return `/clients/${ to . params . lang } /${ latestVersion ?. path } /${ latestVersion ?. startPage } ` ;
133+ } )
134+
135+
136+ // Add fixed routes for server versions because they don't use the same sidebar structure as the other versions
137+ addFixedRoute ( "/server/v22.10" , "/server/v22.10/introduction.html" ) ;
138+ addFixedRoute ( "/server/v5" , "/server/v5/introduction.html" ) ;
139+
105140 addDynamicRoute ( "/server/:version" , to => `/server/${ to . params . version } /quick-start/` ) ;
106- addDynamicRoute ( '/client/:lang' ,
107- to => {
108- const lang = to . params . lang === "csharp" ? "C#" : to . params . lang ;
109- const stored = JSON . parse ( localStorage . getItem ( storageKey ) ?? "{}" ) ;
110- localStorage . setItem ( storageKey , JSON . stringify ( { ...stored , code : lang } ) ) ;
111- return '/clients/grpc/getting-started.html' ;
112- } ) ;
113141 addDynamicRoute ( '/latest/:pathMatch(.*)*' , to => to . path . replace ( / ^ \/ l a t e s t / , `/${ __VERSIONS__ . latest } ` ) ) ;
114142 addFixedRoute ( "/server/latest" , `/${ __VERSIONS__ . latest } /quick-start/` ) ;
115143 addFixedRoute ( "/latest" , `/${ __VERSIONS__ . latest } /quick-start/` ) ;
@@ -135,13 +163,13 @@ export default defineClientConfig({
135163 } ) ;
136164 } , 1000 ) ;
137165 }
138-
166+
139167 // Check for 404 page after navigation completes
140168 setTimeout ( ( ) => {
141169 // Check for the specific elements with classes error-code and error-hint
142170 const errorCodeElement = document . querySelector ( 'p.error-code' ) ;
143171 const errorHintElement = document . querySelector ( 'p.error-hint' ) ;
144-
172+
145173 // If both elements exist, we're on a 404 page
146174 if ( errorCodeElement && errorHintElement ) {
147175 // Capture the 404 event in PostHog
@@ -154,15 +182,15 @@ export default defineClientConfig({
154182 } ) ;
155183 }
156184 }
157- } , 50 ) ;
185+ } , 50 ) ;
158186 } ) ;
159187 router . beforeEach ( ( to , from ) => leave ( to , from ) ) ;
160188 } ,
161189 setup ( ) {
162190 onMounted ( ( ) => {
163191 const route = useRoute ( ) ;
164- if ( route . path !== "/" ) ;
192+ if ( route . path !== "/" ) ;
165193 } ) ;
166194
167195 } ,
168- } satisfies ClientConfig ) ;
196+ } ) ;
0 commit comments