1- import { defineClientConfig , useRoute } from 'vuepress/client' ;
21import "iconify-icon" ;
32import { onMounted } from "vue" ;
4- import type { RouteLocationNormalized , Router } from "vue-router" ;
3+ import type { RouteLocationNormalized } from "vue-router" ;
4+ import { defineClientConfig , useRoute } from 'vuepress/client' ;
55import CloudBanner from "./components/CloudBanner.vue" ;
6+ import ClientsGrid from "./components/ClientsGrid.vue" ;
67import KapaWidget from './components/KapaWidget.vue' ;
78import UserFeedback from './components/TocWithFeedback' ;
8- import { usePostHog } from "./lib/usePosthog" ;
99import SidebarLayout from "./layouts/SidebarLayout.vue" ;
10+ import { usePostHog } from "./lib/usePosthog" ;
1011
11- declare const __VERSIONS__ : { latest : string , selected : string , all : string [ ] }
12+ declare const __VERSIONS__ : {
13+ latest : string ,
14+ selected : string ,
15+ all : {
16+ id : string ,
17+ group : string ,
18+ basePath : string ,
19+ versions : {
20+ version : string ,
21+ path : string ,
22+ startPage : string ,
23+ preview ?: boolean ,
24+ deprecated ?: boolean ,
25+ hide ?: boolean
26+ } [ ]
27+ } [ ]
28+ }
1229
1330const storageKey = "VUEPRESS_TAB_STORE" ;
1431
32+ const clients = ":lang(dotnet|golang|java|node|python|rust)"
33+
1534const findMetaKey = ( record : any [ ] , key : string ) => {
1635 if ( record [ 0 ] !== "meta" ) return null ;
1736 const data = record [ 1 ] ;
@@ -31,15 +50,6 @@ const findEsMeta = (route) => {
3150 }
3251}
3352
34- // interface ClientConfig {
35- // enhance?: (context: {
36- // app: any;
37- // router: Router;
38- // siteData: any;
39- // }) => void | Promise<void>;
40- // setup?: () => void;
41- // }
42-
4353const removeHtml = ( path : string ) => path . replace ( ".html" , "" ) ;
4454
4555const reload = ( ) => {
@@ -64,9 +74,9 @@ export default defineClientConfig({
6474 } ,
6575 enhance ( { app, router, _} ) {
6676 app . component ( "CloudBanner" , CloudBanner ) ;
77+ app . component ( "ClientsGrid" , ClientsGrid ) ;
6778 app . component ( "KapaWidget" , KapaWidget ) ;
6879 app . component ( "UserFeedback" , UserFeedback ) ;
69- const apiPath = __VERSIONS__ . latest . replace ( "server" , "http-api" ) ;
7080 const addFixedRoute = ( from : string , to : string ) => router . addRoute ( {
7181 path : from , redirect : _ => {
7282 reload ( ) ;
@@ -83,7 +93,7 @@ export default defineClientConfig({
8393 } ) ;
8494
8595 // Router configuration
86- addFixedRoute ( "/http-api/" , `${ apiPath } /introduction` ) ;
96+ addFixedRoute ( "/server/ http-api/" , `/ ${ __VERSIONS__ . latest } /http-api /introduction` ) ;
8797 addFixedRoute ( "/cloud/" , `/cloud/introduction.html` ) ;
8898 router . afterEach ( ( ) => {
8999 setTimeout ( ( ) => { // to ensure this runs after DOM updates
@@ -102,18 +112,46 @@ export default defineClientConfig({
102112 }
103113 } , 0 ) ;
104114 } ) ;
105- const operatorLatest = __VERSIONS__ . all . filter ( x => x . id == 'kubernetes-operator' ) [ 0 ] . versions [ 0 ] . version ;
115+ const operatorLatest = __VERSIONS__ . all . filter ( x => x . id === 'kubernetes-operator' ) [ 0 ] . versions [ 0 ] . version ;
106116 addDynamicRoute ( "/server/kubernetes-operator" , to => `/server/kubernetes-operator/${ operatorLatest } /getting-started/` ) ;
107117 addDynamicRoute ( "/server/kubernetes-operator/:version" , to => `/server/kubernetes-operator/${ to . params . version } /getting-started/` ) ;
108118
119+ // Clients routes
120+ addFixedRoute ( `/clients/grpc/:pathMatch(.*)*` , "/clients/" ) ;
121+
122+ addDynamicRoute ( `/clients/${ clients } /latest/:pathMatch(.*)*` , to => {
123+ const latestVersion = __VERSIONS__ . all . find ( x => x . id === `${ to . params . lang } -client` ) ?. versions [ 0 ]
124+ return `/clients/${ to . params . lang } /${ latestVersion ?. version } /${ to . params . pathMatch } ` ;
125+ } ) ;
126+ addDynamicRoute ( `/clients/${ clients } /latest` , to => {
127+ const latestVersion = __VERSIONS__ . all . find ( x => x . id === `${ to . params . lang } -client` ) ?. versions [ 0 ]
128+ return `/clients/${ to . params . lang } /${ latestVersion ?. version } /${ latestVersion ?. startPage } ` ;
129+ } ) ;
130+ addDynamicRoute ( `/clients/${ clients } /legacy/:version` , to => {
131+ const version = to . params . version ;
132+ const latestVersion = __VERSIONS__ . all . find ( x => x . id === `${ to . params . lang } -client` ) ?. versions . find ( v => v . path === `legacy/${ version } ` )
133+ return `/clients/${ to . params . lang } /legacy/${ to . params . version } /${ latestVersion ?. startPage } ` ;
134+ } ) ;
135+ addDynamicRoute ( `/clients/${ clients } /legacy` , to => {
136+ const latestVersion = __VERSIONS__ . all . find ( x => x . id === `${ to . params . lang } -client` ) ?. versions . find ( v => v . path . startsWith ( 'legacy/' ) )
137+ return `/clients/${ to . params . lang } /${ latestVersion ?. path } /${ latestVersion ?. startPage } ` ;
138+ } )
139+ addDynamicRoute ( `/clients/${ clients } /:version` , to => {
140+ const version = to . params . version ;
141+ const latestVersion = __VERSIONS__ . all . find ( x => x . id === `${ to . params . lang } -client` ) ?. versions . find ( v => v . path === version )
142+ return `/clients/${ to . params . lang } /${ version } /${ latestVersion ?. startPage } ` ;
143+ } ) ;
144+ addDynamicRoute ( `/clients/${ clients } ` , to => {
145+ const latestVersion = __VERSIONS__ . all . find ( x => x . id === `${ to . params . lang } -client` ) ?. versions [ 0 ]
146+ return `/clients/${ to . params . lang } /${ latestVersion ?. path } /${ latestVersion ?. startPage } ` ;
147+ } )
148+
149+
150+ // Add fixed routes for server versions because they don't use the same sidebar structure as the other versions
151+ addFixedRoute ( "/server/v22.10" , "/server/v22.10/introduction.html" ) ;
152+ addFixedRoute ( "/server/v5" , "/server/v5/introduction.html" ) ;
153+
109154 addDynamicRoute ( "/server/:version" , to => `/server/${ to . params . version } /quick-start/` ) ;
110- addDynamicRoute ( '/client/:lang' ,
111- to => {
112- const lang = to . params . lang === "csharp" ? "C#" : to . params . lang ;
113- const stored = JSON . parse ( localStorage . getItem ( storageKey ) ?? "{}" ) ;
114- localStorage . setItem ( storageKey , JSON . stringify ( { ...stored , code : lang } ) ) ;
115- return '/clients/grpc/getting-started.html' ;
116- } ) ;
117155 addDynamicRoute ( '/latest/:pathMatch(.*)*' , to => to . path . replace ( / ^ \/ l a t e s t / , `/${ __VERSIONS__ . latest } ` ) ) ;
118156 addFixedRoute ( "/server/latest" , `/${ __VERSIONS__ . latest } /quick-start/` ) ;
119157 addFixedRoute ( "/latest" , `/${ __VERSIONS__ . latest } /quick-start/` ) ;
0 commit comments