@viteplus/versions 2.0.4 → 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/components/version-switcher.component.vue +21 -17
- 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
|
@@ -36,39 +36,43 @@ const props = defineProps<{
|
|
|
36
36
|
|
|
37
37
|
const versionSet = computed(() => new Set([ ...props.versioningPlugin.versions ]));
|
|
38
38
|
const hasVersions = computed(() => versionSet.value.size > 0);
|
|
39
|
-
function getPathSegments(): string[] {
|
|
40
|
-
return router.route.data.relativePath.split('/');
|
|
41
|
-
}
|
|
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
|
|