Skip to content

Commit

Permalink
fix: fix version switch again
Browse files Browse the repository at this point in the history
  • Loading branch information
MC-XiaoHei committed Dec 8, 2024
1 parent 420d3db commit 3985715
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
3 changes: 1 addition & 2 deletions docs/.vitepress/theme/prefer/prefer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {ref} from 'vue'

export const inBrowser = typeof window !== 'undefined'
import {inBrowser} from "vitepress";

function getBoolean(key: string, defaultValue: boolean) {
if (inBrowser) {
Expand Down
8 changes: 4 additions & 4 deletions docs/.vitepress/theme/versioning/VersionSwitcher.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ watch(
<div class="items">
<VPMenuLink v-if="!isLatest" :item="{
text: latestVersion,
link: `/../index`,
link: `/../`,
}"/>
<template v-for="version in versions" :key="version">
<VPMenuLink v-if="currentVersion != version" :item="{
text: version,
link: `${isLatest? '' : '/..'}/${version}/index`,
link: `${isLatest? '' : '/..'}/${version}/`,
}"/>
</template>
</div>
Expand All @@ -88,12 +88,12 @@ watch(
<div id="navbar-group-version" class="items">
<VPMenuLink :item="{
text: latestVersion,
link: `${isLatest? '' : '/..'}/index`,
link: `${isLatest? '' : '/..'}/`,
}"/>
<template v-for="version in versions" :key="version">
<VPMenuLink :item="{
text: version,
link: `${isLatest? '' : '/..'}/${version}/index`,
link: `${isLatest? '' : '/..'}/${version}/`,
}"/>
</template>
</div>
Expand Down
21 changes: 18 additions & 3 deletions docs/.vitepress/theme/versioning/version.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
import {ref} from "vue";
import {ref, watch} from "vue";
import {inBrowser} from "vitepress";

export const currentVersion = ref('');
export const latestVersion = ref('');
function getString(key: string, defaultValue: string) {
if (inBrowser) {
return localStorage.getItem(key) || defaultValue;
} else {
return defaultValue;
}
}

export const currentVersion = ref(getString('current-version', ''));
export const latestVersion = ref('');

watch(currentVersion, (value) => {
if (inBrowser) {
localStorage.setItem('current-version', value);
}
});

0 comments on commit 3985715

Please sign in to comment.