1+ <script setup lang="ts">
2+ // import ParentLayout from '@vuepress/theme-default/layouts/Layout.vue'
3+ import { Layout as ParentLayout , PageContent } from ' vuepress-theme-hope/client'
4+ import { useRoute , useRouter } from " vue-router" ;
5+ import { ref } from ' vue'
6+
7+ const version = ref (" " );
8+
9+
10+ function setVersionBasedOnCurrentPath() : void {
11+ if (route .path .startsWith (' /operations/' )) {
12+ const input = route .path .substring (' /operations/' .length );
13+ const firstSlash = input .indexOf (" /" );
14+ const secondSlash = input .indexOf (" /" , firstSlash + 1 );
15+ const result = secondSlash !== - 1 ? input .slice (0 , secondSlash ) : input ;
16+
17+ version .value = result ;
18+
19+
20+ } else {
21+ version .value = " " ;
22+ }
23+ }
24+
25+ const route = useRoute ();
26+
27+
28+ const router = useRouter ();
29+ router .afterEach ((_to , _from ) => {
30+ setVersionBasedOnCurrentPath ();
31+ });
32+
33+ setVersionBasedOnCurrentPath ();
34+
35+ function navigateToNewVersion() {
36+ const input = route .path .substring (' /operations/' .length );
37+ const firstSlash = input .indexOf (" /" );
38+ const secondSlash = input .indexOf (" /" , firstSlash + 1 );
39+ const result = secondSlash !== - 1 ? input .slice (secondSlash + 1 ) : " " ;
40+ router .push (' /operations/' + version .value + " /" + result );
41+ }
42+
43+ </script >
44+
45+ <template >
46+ <ParentLayout >
47+ <template #sidebarTop >
48+ <div class =" version-selector" v-if =" route.path.startsWith('/operations/')" >
49+ <label class =" vp-sidebar-header" for =" version-select" ><strong >Version:</strong > </label >
50+ <select id =" version-select" class =" vp-sidebar-header" v-model =" version" @change =" navigateToNewVersion" >
51+ <option value =" v2/latest" >next (2.0.0-M3)</option >
52+ <option value =" v1/latest" >latest (1.8.0)</option >
53+ <option value =" v1/v1.7.1" >1.7.1</option >
54+ <option value =" v1/v1.7.0" >1.7.0</option >
55+ <option value =" v1/v1.6.0" >1.6.0</option >
56+ <option value =" v1/v1.5.2" >1.5.2</option >
57+ <option value =" v1/v1.5.1" >1.5.1</option >
58+ <option value =" v1/v1.5.0" >1.5.0</option >
59+ <option value =" v1/v1.4.0" >1.4.0</option >
60+ <option value =" v1/v1.3.2" >1.3.2</option >
61+ <option value =" v1/v1.3.1" >1.3.1</option >
62+ <option value =" v1/v1.3.0" >1.3.0</option >
63+ <option value =" v1/v1.2.0" >1.2.0</option >
64+ <option value =" v1/v1.1.0" >1.1.0</option >
65+ <option value =" v1/v1.0.0" >1.0.0</option >
66+ </select ></div >
67+ </template >
68+ <PageContent id =" main-content" class =" vp-page" />
69+ </ParentLayout >
70+ </template >
71+
72+ <style lang="css">
73+ .version-selector {
74+ margin-top : 20px ;
75+ }
76+ </style >
0 commit comments