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" >Version: </label >
50
+ <select id =" version-select" class =" vp-sidebar-header" v-model =" version" @change =" navigateToNewVersion" >
51
+ <option value =" v2/latest" >next (v2.0.0-M2)</option >
52
+ <option value =" v1/latest" >latest (v1.7.1)</option >
53
+ <option value =" v1/v1.7.0" >v1.7.0</option >
54
+ <option value =" v1/v1.6.0" >v1.6.0</option >
55
+ <option value =" v1/v1.5.2" >v1.5.2</option >
56
+ <option value =" v1/v1.5.1" >v1.5.1</option >
57
+ <option value =" v1/v1.5.0" >v1.5.0</option >
58
+ <option value =" v1/v1.4.0" >v1.4.0</option >
59
+ <option value =" v1/v1.3.2" >v1.3.2</option >
60
+ <option value =" v1/v1.3.1" >v1.3.1</option >
61
+ <option value =" v1/v1.3.0" >v1.3.0</option >
62
+ <option value =" v1/v1.2.0" >v1.2.0</option >
63
+ <option value =" v1/v1.1.0" >v1.1.0</option >
64
+ <option value =" v1/v1.0.0" >v1.0.0</option >
65
+ </select ></div >
66
+ </template >
67
+ <PageContent id =" main-content" class =" vp-page" />
68
+ </ParentLayout >
69
+ </template >
70
+
71
+ <style lang="css">
72
+ .version-selector {
73
+ margin-top : 20px ;
74
+ }
75
+ </style >
0 commit comments