Skip to content

Commit

Permalink
feat: link to current page on version switch
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGreatRefrigerator committed Dec 10, 2024
1 parent 8fe1bf5 commit 80f0732
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions docs/.vitepress/components/VersionSwitcher.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,26 @@ const sortedVersions = computed(() => {
})
return versions
})
});
/**
* generates the correct link in the dropdown for the specific version
* @param version - the version text of the current dropdown entry
*/
function versionedLink(version: string): string {
let pathElementsToRemove = 2
if (!currentVersion.value.includes('latest')) {
pathElementsToRemove = 3
}
const sitePath = router.route.path.split('/').slice(pathElementsToRemove).join('/')
let returnPath = '/'
if (!version.includes('latest')) {
returnPath = `/${version}/`
}
return `${returnPath}${sitePath}`
}
const currentVersion = computed(() => {
let version = props.versioningPlugin.latestVersion;
Expand Down Expand Up @@ -50,7 +69,7 @@ const toggle = () => {
<template v-for="version in sortedVersions" :key="version">
<VPMenuLink v-if="currentVersion != version" :item="{
text: version,
link: `/${version === versioningPlugin.latestVersion ? '' : version + '/'}`,
link: versionedLink(version)
}" />
</template>
</div>
Expand All @@ -65,7 +84,7 @@ const toggle = () => {
<template v-for="version in sortedVersions" :key="version">
<VPMenuLink :item="{
text: version,
link: `/${version === versioningPlugin.latestVersion ? '' : version + '/'}`,
link: versionedLink(version)
}" />
</template>
</div>
Expand Down

0 comments on commit 80f0732

Please sign in to comment.