11<!-- modified from https://github.com/IMB11/vitepress-versioning-plugin , original license is MIT-->
22
33<script setup lang="ts">
4- import {onMounted , ref , watch } from ' vue '
5- import VPMenuLink from ' vitepress/dist/client/theme-default/components/VPMenuLink .vue'
6- import VPFlyout from ' vitepress/dist/client/theme-default/components/VPFlyout .vue'
7- import {parse } from " yaml " ;
8- import {useRoute } from " vitepress " ;
9- import {changingVersion , currentVersion , isLatest , latestVersion } from " ./version" ;
4+ import { useRoute } from " vitepress " ;
5+ import VPFlyout from " vitepress/dist/client/theme-default/components/VPFlyout .vue" ;
6+ import VPMenuLink from " vitepress/dist/client/theme-default/components/VPMenuLink .vue" ;
7+ import { computed , onMounted , ref , watch } from " vue " ;
8+ import { parse } from " yaml " ;
9+ import { changingVersion , currentVersion , isLatest , isOld , latestVersion } from " ./version" ;
1010
1111// noinspection JSUnusedGlobalSymbols
1212const props = defineProps <{
@@ -15,55 +15,65 @@ const props = defineProps<{
1515const route = useRoute ();
1616
1717let versionList: string [] = [];
18+ let oldVersionList: string [] = [];
1819const versions = ref <string []>([]);
20+ const docsPath = computed (() => {
21+ if (isLatest .value ) {
22+ return window .location .pathname ;
23+ } else {
24+ return window .location .pathname .split (` /${ currentVersion .value }/ ` )[1 ];
25+ }
26+ });
1927
2028function refresh() {
2129 let version = latestVersion .value ;
2230 let refreshPage = false ;
2331 isLatest .value = true ;
2432
2533 for (const v of versionList ) {
26- if (window .location .pathname .startsWith (` /${v }/ ` )) {
34+ if (window .location .pathname .startsWith (` /${ v }/ ` )) {
2735 version = v ;
2836 isLatest .value = false ;
2937 break ;
3038 }
3139 }
3240
33- if (currentVersion .value !== ' ' && currentVersion .value !== version ) {
41+ if (currentVersion .value !== " " && currentVersion .value !== version ) {
3442 refreshPage = true ;
3543 changingVersion .value = true ;
3644 }
3745
3846 currentVersion .value = version ;
3947 versions .value = versionList ;
48+ isOld .value = oldVersionList .includes (version );
4049
4150 if (refreshPage ) {
42- window .location .pathname = isLatest .value ? ' / ' : ` /${version }/ ` ;
51+ window .location .pathname = isLatest .value ? " / " : ` /${ version }/ ` ;
4352 window .location .reload ();
4453 }
4554}
4655
4756async function init() {
4857 changingVersion .value = false ;
49- const versionDataFileUrl = ` ${window .location .origin }/versions.yml ` ;
58+ const versionDataFileUrl = ` ${ window .location .origin }/versions.yml ` ;
5059 const versionDataFileContent = await (await fetch (versionDataFileUrl )).text ();
5160 const versionData = parse (versionDataFileContent );
5261 versionList = versionData .versions ;
62+ oldVersionList = versionData [" old-versions" ];
5363 latestVersion .value = versionList [0 ];
5464 versionList .shift ();
55- refresh ()
65+ refresh ();
5666}
5767
5868const isOpen = ref (false );
5969const toggle = () => {
6070 isOpen .value = ! isOpen .value ;
6171};
6272
63- onMounted (async () => init ())
73+ onMounted (async () => init ());
6474watch (
6575 () => route .path ,
66- () => refresh ()
76+ () => refresh (),
6777);
6878 </script >
6979
@@ -73,32 +83,32 @@ watch(
7383 <div class =" items" >
7484 <VPMenuLink v-if =" !isLatest" :item =" {
7585 text: latestVersion,
76- link: `/../`,
77- }" />
86+ link: `/../${docsPath}?from=${currentVersion} `,
87+ }" />
7888 <template v-for =" version in versions " :key =" version " >
7989 <VPMenuLink v-if =" currentVersion != version" :item =" {
8090 text: version,
81- link: `${isLatest? '' : '/..'}/${version}/`,
82- }" />
91+ link: `${isLatest? '' : '/..'}/${version}/${docsPath}?from=${currentVersion} `,
92+ }" />
8393 </template >
8494 </div >
8595 </VPFlyout >
8696 <div v-else class =" VPScreenVersionSwitcher" :class =" { open: isOpen }" >
8797 <button class =" button" aria-controls =" navbar-group-version" :aria-expanded =" isOpen" @click =" toggle" >
88- <span class =" button-text" ><span class =" vpi-versioning icon" />Switch Version</span >
89- <span class =" vpi-plus button-icon" />
98+ <span class =" button-text" ><span class =" vpi-versioning icon" />Switch Version</span >
99+ <span class =" vpi-plus button-icon" />
90100 </button >
91101
92102 <div id =" navbar-group-version" class =" items" >
93103 <VPMenuLink :item =" {
94104 text: latestVersion,
95105 link: `${isLatest? '' : '/..'}/`,
96- }" />
106+ }" />
97107 <template v-for =" version in versions " :key =" version " >
98108 <VPMenuLink :item =" {
99109 text: version,
100110 link: `${isLatest? '' : '/..'}/${version}/`,
101- }" />
111+ }" />
102112 </template >
103113 </div >
104114 </div >
@@ -116,11 +126,11 @@ watch(
116126
117127<style scoped>
118128.VPMenuLink {
119- font-family : ' Helvetica Neue' , sans-serif ;
129+ font-family : " Helvetica Neue" , sans-serif ;
120130}
121131
122132.VPVersionSwitcher {
123- font-family : ' Helvetica Neue' , sans-serif ;
133+ font-family : " Helvetica Neue" , sans-serif ;
124134 display : flex ;
125135 align-items : center ;
126136}
0 commit comments