@viteplus/versions 2.0.3 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/components/version-switcher.component.vue +70 -64
- package/dist/index.d.ts +758 -198
- package/dist/index.js +2 -2
- package/dist/index.js.map +5 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](https://www.npmjs.com/package/@viteplus/versions)
|
|
5
5
|
[](https://opensource.org/licenses/MPL-2.0)
|
|
6
6
|
[](https://github.com/viteplus/versions/actions/workflows/node.js.yml)
|
|
7
|
-
[](https://discord.gg/
|
|
7
|
+
[](https://discord.gg/6vgFhJTEGn)
|
|
8
8
|
[](https://deepwiki.com/viteplus/versions)
|
|
9
9
|
|
|
10
10
|
@viteplus/versions is a powerful VitePress plugin that enables versioned documentation with built-in localization support,
|
|
@@ -35,95 +35,101 @@ const props = defineProps<{
|
|
|
35
35
|
}>();
|
|
36
36
|
|
|
37
37
|
const versionSet = computed(() => new Set([ ...props.versioningPlugin.versions ]));
|
|
38
|
-
|
|
39
|
-
function getPathSegments(): string[] {
|
|
40
|
-
return router.route.data.relativePath.split('/');
|
|
41
|
-
}
|
|
38
|
+
const hasVersions = computed(() => versionSet.value.size > 0);
|
|
42
39
|
|
|
43
40
|
const getActiveVersion = computed(() => {
|
|
44
|
-
const segments =
|
|
41
|
+
const segments = router.route.data.relativePath.split('/');
|
|
45
42
|
const { currentVersion } = props.versioningPlugin;
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
const locale = site.value.locales[site.value.localeIndex].link.replace(/\//g, '');
|
|
44
|
+
|
|
45
|
+
// Check if the first segment is locale, use the second segment if so, otherwise first
|
|
46
|
+
const candidate = segments[0] === locale ? segments[1] : segments[0];
|
|
49
47
|
|
|
50
48
|
return versionSet.value.has(candidate) ? candidate : currentVersion;
|
|
51
|
-
})
|
|
49
|
+
});
|
|
52
50
|
|
|
53
51
|
function createVersionMenuItem(version: string): { text: string, link: string } {
|
|
54
52
|
const { currentVersion } = props.versioningPlugin;
|
|
55
|
-
const segments =
|
|
53
|
+
const segments = router.route.data.relativePath.split('/');
|
|
54
|
+
const locale = site.value.locales[site.value.localeIndex].link.replace(/\//g, '');
|
|
55
|
+
|
|
56
|
+
// Filter out version segments
|
|
56
57
|
const baseSegments = segments.filter(seg => !versionSet.value.has(seg));
|
|
57
58
|
|
|
58
|
-
//
|
|
59
|
-
const
|
|
60
|
-
const langIsFirst = first === site.value.lang;
|
|
59
|
+
// Check if first segment matches current locale
|
|
60
|
+
const langIsFirst = baseSegments[0] === locale;
|
|
61
61
|
|
|
62
|
-
let newSegments:
|
|
63
|
-
if (version === currentVersion)
|
|
64
|
-
|
|
65
|
-
else
|
|
62
|
+
let newSegments: string[];
|
|
63
|
+
if (version === currentVersion) {
|
|
64
|
+
newSegments = baseSegments;
|
|
65
|
+
} else if (langIsFirst) {
|
|
66
|
+
newSegments = [ baseSegments[0], version, ...baseSegments.slice(1) ];
|
|
67
|
+
} else {
|
|
68
|
+
newSegments = [ version, ...baseSegments ];
|
|
69
|
+
}
|
|
66
70
|
|
|
67
71
|
return { text: version, link: `/${ newSegments.join('/') }` };
|
|
68
72
|
}
|
|
69
73
|
|
|
70
74
|
function toggle() {
|
|
71
|
-
|
|
75
|
+
isOpen.value = !isOpen.value;
|
|
72
76
|
}
|
|
73
77
|
</script>
|
|
74
78
|
|
|
75
79
|
<template>
|
|
76
|
-
<!--
|
|
77
|
-
<
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
<
|
|
87
|
-
|
|
88
|
-
:item="createVersionMenuItem(versioningPlugin.currentVersion)"
|
|
89
|
-
/>
|
|
90
|
-
<!-- Show all version links except current version -->
|
|
91
|
-
<template v-for="version in versioningPlugin.versions" :key="version">
|
|
80
|
+
<!-- Only render if versions exist -->
|
|
81
|
+
<template v-if="hasVersions">
|
|
82
|
+
<!-- Desktop version flyout -->
|
|
83
|
+
<VPFlyout
|
|
84
|
+
v-if="!screenMenu"
|
|
85
|
+
class="VPVersionSwitcher"
|
|
86
|
+
icon="vpi-versioning"
|
|
87
|
+
:button="getActiveVersion"
|
|
88
|
+
label="Switch Version"
|
|
89
|
+
>
|
|
90
|
+
<div class="items">
|
|
91
|
+
<!-- Only show latest version link if we're not already on latest -->
|
|
92
92
|
<VPMenuLink
|
|
93
|
-
v-if="getActiveVersion !==
|
|
93
|
+
v-if="getActiveVersion !== versioningPlugin.currentVersion"
|
|
94
|
+
:item="createVersionMenuItem(versioningPlugin.currentVersion)"
|
|
95
|
+
/>
|
|
96
|
+
<!-- Show all version links except current version -->
|
|
97
|
+
<template v-for="version in versioningPlugin.versions" :key="version">
|
|
98
|
+
<VPMenuLink
|
|
99
|
+
v-if="getActiveVersion !== version"
|
|
100
|
+
:item="createVersionMenuItem(version)"
|
|
101
|
+
/>
|
|
102
|
+
</template>
|
|
103
|
+
</div>
|
|
104
|
+
</VPFlyout>
|
|
105
|
+
|
|
106
|
+
<!-- Mobile version dropdown -->
|
|
107
|
+
<div v-else class="VPScreenVersionSwitcher" :class="{ open: isOpen }">
|
|
108
|
+
<button
|
|
109
|
+
class="button"
|
|
110
|
+
aria-controls="navbar-group-version"
|
|
111
|
+
:aria-expanded="isOpen"
|
|
112
|
+
@click="toggle"
|
|
113
|
+
>
|
|
114
|
+
<span class="button-text">
|
|
115
|
+
<span class="vpi-versioning icon"/>Switch Version
|
|
116
|
+
</span>
|
|
117
|
+
<span class="vpi-plus button-icon"/>
|
|
118
|
+
</button>
|
|
119
|
+
|
|
120
|
+
<div id="navbar-group-version" class="items">
|
|
121
|
+
<!-- Always show latest version link -->
|
|
122
|
+
<VPMenuLink :item="createVersionMenuItem(versioningPlugin.currentVersion)"/>
|
|
123
|
+
<!-- Show all version links -->
|
|
124
|
+
<VPMenuLink
|
|
125
|
+
v-for="version in versioningPlugin.versions"
|
|
126
|
+
:key="version"
|
|
94
127
|
:item="createVersionMenuItem(version)"
|
|
95
128
|
/>
|
|
96
|
-
</
|
|
129
|
+
</div>
|
|
97
130
|
</div>
|
|
98
|
-
</
|
|
99
|
-
|
|
100
|
-
<!-- Mobile version dropdown -->
|
|
101
|
-
<div v-else class="VPScreenVersionSwitcher" :class="{ open: isOpen }">
|
|
102
|
-
<button
|
|
103
|
-
class="button"
|
|
104
|
-
aria-controls="navbar-group-version"
|
|
105
|
-
:aria-expanded="isOpen"
|
|
106
|
-
@click="toggle"
|
|
107
|
-
>
|
|
108
|
-
<span class="button-text">
|
|
109
|
-
<span class="vpi-versioning icon"/>Switch Version
|
|
110
|
-
</span>
|
|
111
|
-
<span class="vpi-plus button-icon"/>
|
|
112
|
-
</button>
|
|
113
|
-
|
|
114
|
-
<div id="navbar-group-version" class="items">
|
|
115
|
-
<!-- Always show latest version link -->
|
|
116
|
-
<VPMenuLink :item="createVersionMenuItem(versioningPlugin.currentVersion)"/>
|
|
117
|
-
<!-- Show all version links -->
|
|
118
|
-
<VPMenuLink
|
|
119
|
-
v-for="version in versioningPlugin.versions"
|
|
120
|
-
:key="version"
|
|
121
|
-
:item="createVersionMenuItem(version)"
|
|
122
|
-
/>
|
|
123
|
-
</div>
|
|
124
|
-
</div>
|
|
131
|
+
</template>
|
|
125
132
|
</template>
|
|
126
|
-
|
|
127
133
|
<style>
|
|
128
134
|
/* Versioning icon styling */
|
|
129
135
|
.vpi-versioning.option-icon {
|