@viteplus/versions 2.0.8 → 2.1.0
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/env.d.ts +17 -0
- package/components/styles/scoped.css +79 -0
- package/components/styles/version-switcher.css +7 -0
- package/components/tsconfig.json +36 -0
- package/components/version-switcher.component.ts +662 -0
- package/components/version-switcher.component.vue +41 -181
- package/dist/index.d.ts +31 -7
- package/dist/index.js +2 -2
- package/dist/index.js.map +8 -1
- package/package.json +11 -10
- package/dist/package.json +0 -1
|
@@ -1,95 +1,44 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { computed, ref } from 'vue';
|
|
3
|
-
import { useData, useRouter } from 'vitepress';
|
|
4
|
-
import VPFlyout from 'vitepress/dist/client/theme-default/components/VPFlyout.vue';
|
|
5
|
-
import VPMenuLink from 'vitepress/dist/client/theme-default/components/VPMenuLink.vue';
|
|
6
|
-
|
|
7
|
-
interface VersioningPlugin {
|
|
8
|
-
versions: Set<string>;
|
|
9
|
-
currentVersion: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
interface Props {
|
|
13
|
-
versioningPlugin: VersioningPlugin;
|
|
14
|
-
screenMenu?: boolean;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface VersionMenuItem {
|
|
18
|
-
text: string;
|
|
19
|
-
link: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const props = defineProps<Props>();
|
|
23
|
-
const router = useRouter();
|
|
24
|
-
const { site } = useData();
|
|
25
|
-
const isOpen = ref(false);
|
|
26
|
-
|
|
27
|
-
// Computed properties
|
|
28
|
-
const versionSet = computed(() => new Set([...props.versioningPlugin.versions]));
|
|
29
|
-
const hasVersions = computed(() => versionSet.value.size > 0);
|
|
30
|
-
|
|
31
|
-
const currentLocale = computed(() =>
|
|
32
|
-
site.value.locales[site.value.localeIndex]?.link?.replace(/\//g, '') || ''
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
const pathSegments = computed(() => router.route.data.relativePath.split('/'));
|
|
36
2
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const locale = currentLocale.value;
|
|
3
|
+
/**
|
|
4
|
+
* Type-only imports erased during TypeScript compilation.
|
|
5
|
+
*/
|
|
41
6
|
|
|
42
|
-
|
|
43
|
-
const versionCandidate = segments[0] === locale ? segments[1] : segments[0];
|
|
7
|
+
import type { PropsInterface } from './version-switcher.component';
|
|
44
8
|
|
|
45
|
-
|
|
46
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Imports
|
|
11
|
+
*/
|
|
47
12
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const shouldShowCurrentVersion = computed(() =>
|
|
53
|
-
activeVersion.value !== props.versioningPlugin.currentVersion
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
// Helper functions
|
|
57
|
-
function isLocaleFirst(segments: string[]): boolean {
|
|
58
|
-
return segments[0] === currentLocale.value;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function removeVersionSegments(segments: string[]): string[] {
|
|
62
|
-
return segments.filter(seg => !versionSet.value.has(seg));
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function buildVersionPath(version: string): string {
|
|
66
|
-
const { currentVersion } = props.versioningPlugin;
|
|
67
|
-
const baseSegments = removeVersionSegments(pathSegments.value);
|
|
68
|
-
const hasLocale = isLocaleFirst(baseSegments);
|
|
69
|
-
|
|
70
|
-
let newSegments: string[];
|
|
71
|
-
|
|
72
|
-
if (version === currentVersion) {
|
|
73
|
-
newSegments = baseSegments;
|
|
74
|
-
} else if (hasLocale) {
|
|
75
|
-
newSegments = [baseSegments[0], version, ...baseSegments.slice(1)];
|
|
76
|
-
} else {
|
|
77
|
-
newSegments = [version, ...baseSegments];
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return `/${newSegments.join('/')}`;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function createVersionMenuItem(version: string): VersionMenuItem {
|
|
84
|
-
return {
|
|
85
|
-
text: version,
|
|
86
|
-
link: buildVersionPath(version)
|
|
87
|
-
};
|
|
88
|
-
}
|
|
13
|
+
import { useVersionSwitcher } from './version-switcher.component';
|
|
14
|
+
import VPFlyout from 'vitepress/dist/client/theme-default/components/VPFlyout.vue';
|
|
15
|
+
import VPMenuLink from 'vitepress/dist/client/theme-default/components/VPMenuLink.vue';
|
|
89
16
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
17
|
+
/**
|
|
18
|
+
* The props that the theme layout passed to the switcher.
|
|
19
|
+
*
|
|
20
|
+
* @see PropsInterface
|
|
21
|
+
* @since 2.1.0
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const props = defineProps<PropsInterface>();
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The reactive state and the handlers that the template renders.
|
|
28
|
+
*
|
|
29
|
+
* @see useVersionSwitcher
|
|
30
|
+
* @since 2.1.0
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
const {
|
|
34
|
+
isOpen,
|
|
35
|
+
toggle,
|
|
36
|
+
hasVersions,
|
|
37
|
+
activeVersion,
|
|
38
|
+
availableVersions,
|
|
39
|
+
createVersionMenuItem,
|
|
40
|
+
shouldShowCurrentVersion
|
|
41
|
+
} = useVersionSwitcher(props);
|
|
93
42
|
</script>
|
|
94
43
|
|
|
95
44
|
<template>
|
|
@@ -102,7 +51,7 @@ function toggle(): void {
|
|
|
102
51
|
:button="activeVersion"
|
|
103
52
|
label="Switch Version"
|
|
104
53
|
>
|
|
105
|
-
<
|
|
54
|
+
<ul class="items">
|
|
106
55
|
<VPMenuLink
|
|
107
56
|
v-if="shouldShowCurrentVersion"
|
|
108
57
|
:item="createVersionMenuItem(versioningPlugin.currentVersion)"
|
|
@@ -112,7 +61,7 @@ function toggle(): void {
|
|
|
112
61
|
:key="version"
|
|
113
62
|
:item="createVersionMenuItem(version)"
|
|
114
63
|
/>
|
|
115
|
-
</
|
|
64
|
+
</ul>
|
|
116
65
|
</VPFlyout>
|
|
117
66
|
|
|
118
67
|
<!-- Mobile dropdown -->
|
|
@@ -131,106 +80,17 @@ function toggle(): void {
|
|
|
131
80
|
<span class="vpi-plus button-icon" />
|
|
132
81
|
</button>
|
|
133
82
|
|
|
134
|
-
<
|
|
83
|
+
<ul id="navbar-group-version" class="items">
|
|
135
84
|
<VPMenuLink :item="createVersionMenuItem(versioningPlugin.currentVersion)" />
|
|
136
85
|
<VPMenuLink
|
|
137
86
|
v-for="version in versioningPlugin.versions"
|
|
138
87
|
:key="version"
|
|
139
88
|
:item="createVersionMenuItem(version)"
|
|
140
89
|
/>
|
|
141
|
-
</
|
|
90
|
+
</ul>
|
|
142
91
|
</div>
|
|
143
92
|
</template>
|
|
144
93
|
</template>
|
|
145
94
|
|
|
146
|
-
<style>
|
|
147
|
-
|
|
148
|
-
margin-right: 2px !important;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
.vpi-versioning {
|
|
152
|
-
--icon: url("data:image/svg+xml;charset=utf-8;base64,PHN2ZyB3aWR0aD0iNjRweCIgaGVpZ2h0PSI2NHB4IiB2aWV3Qm94PSIwIDAgMjQgMjQiIHN0cm9rZS13aWR0aD0iMi4yIiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGNvbG9yPSIjMDAwMDAwIj48cGF0aCBkPSJNMTcgN0MxOC4xMDQ2IDcgMTkgNi4xMDQ1NyAxOSA1QzE5IDMuODk1NDMgMTguMTA0NiAzIDE3IDNDMTUuODk1NCAzIDE1IDMuODk1NDMgMTUgNUMxNSA2LjEwNDU3IDE1Ljg5NTQgNyAxNyA3WiIgc3Ryb2tlPSIjMDAwMDAwIiBzdHJva2Utd2lkdGg9IjIuMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIj48L3BhdGg+PHBhdGggZD0iTTcgN0M4LjEwNDU3IDcgOSA2LjEwNDU3IDkgNUM5IDMuODk1NDMgOC4xMDQ1NyAzIDcgM0M1Ljg5NTQzIDMgNSAzLjg5NTQzIDUgNUM1IDYuMTA0NTcgNS44OTU0MyA3IDcgN1oiIHN0cm9rZT0iIzAwMDAwMCIgc3Ryb2tlLXdpZHRoPSIyLjIiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCI+PC9wYXRoPjxwYXRoIGQ9Ik03IDIxQzguMTA0NTcgMjEgOSAyMC4xMDQ2IDkgMTlDOSAxNy44OTU0IDguMTA0NTcgMTcgNyAxN0M1Ljg5NTQzIDE3IDUgMTcuODk1NCA1IDE5QzUgMjAuMTA0NiA1Ljg5NTQzIDIxIDcgMjFaIiBzdHJva2U9IiMwMDAwMDAiIHN0cm9rZS13aWR0aD0iMi4yIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiPjwvcGF0aD48cGF0aCBkPSJNNyA3VjE3IiBzdHJva2U9IiMwMDAwMDAiIHN0cm9rZS13aWR0aD0iMi4yIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiPjwvcGF0aD48cGF0aCBkPSJNMTcgN1Y4QzE3IDEwLjUgMTUgMTEgMTUgMTFMOSAxM0M5IDEzIDcgMTMuNSA3IDE2VjE3IiBzdHJva2U9IiMwMDAwMDAiIHN0cm9rZS13aWR0aD0iMi4yIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiPjwvcGF0aD48L3N2Zz4=");
|
|
153
|
-
}
|
|
154
|
-
</style>
|
|
155
|
-
|
|
156
|
-
<style scoped>
|
|
157
|
-
.VPVersionSwitcher {
|
|
158
|
-
display: flex;
|
|
159
|
-
align-items: center;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
.icon {
|
|
163
|
-
padding: 8px;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
.title {
|
|
167
|
-
padding: 0 24px 0 12px;
|
|
168
|
-
line-height: 32px;
|
|
169
|
-
font-size: 14px;
|
|
170
|
-
font-weight: 700;
|
|
171
|
-
color: var(--vp-c-text-1);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
.VPScreenVersionSwitcher {
|
|
175
|
-
border-bottom: 1px solid var(--vp-c-divider);
|
|
176
|
-
height: 48px;
|
|
177
|
-
overflow: hidden;
|
|
178
|
-
transition: border-color 0.5s;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
.VPScreenVersionSwitcher .items {
|
|
182
|
-
visibility: hidden;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
.VPScreenVersionSwitcher.open {
|
|
186
|
-
padding-bottom: 10px;
|
|
187
|
-
height: auto;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
.VPScreenVersionSwitcher.open .items {
|
|
191
|
-
visibility: visible;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
.VPScreenVersionSwitcher.open .button {
|
|
195
|
-
padding-bottom: 6px;
|
|
196
|
-
color: var(--vp-c-brand-1);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
.VPScreenVersionSwitcher.open .button-icon {
|
|
200
|
-
transform: rotate(45deg);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
.VPScreenVersionSwitcher button .icon {
|
|
204
|
-
margin-right: 8px;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
.button {
|
|
208
|
-
display: flex;
|
|
209
|
-
justify-content: space-between;
|
|
210
|
-
align-items: center;
|
|
211
|
-
padding: 12px 4px 11px 0;
|
|
212
|
-
width: 100%;
|
|
213
|
-
line-height: 24px;
|
|
214
|
-
font-size: 14px;
|
|
215
|
-
font-weight: 500;
|
|
216
|
-
color: var(--vp-c-text-1);
|
|
217
|
-
transition: color 0.25s;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
.button:hover {
|
|
221
|
-
color: var(--vp-c-brand-1);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
.button-icon {
|
|
225
|
-
transition: transform 0.25s;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
.group:first-child {
|
|
229
|
-
padding-top: 0;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
.group + .group,
|
|
233
|
-
.group + .item {
|
|
234
|
-
padding-top: 4px;
|
|
235
|
-
}
|
|
236
|
-
</style>
|
|
95
|
+
<style scoped src="./styles/scoped.css"></style>
|
|
96
|
+
<style src="./styles/version-switcher.css"></style>
|
package/dist/index.d.ts
CHANGED
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
|
|
6
6
|
import { DefaultTheme, LocaleSpecificConfig, UserConfig } from 'vitepress';
|
|
7
7
|
|
|
8
|
-
export * from 'vitepress';
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* Represents a sidebar item from VitePress with optional versioning control.
|
|
12
10
|
*
|
|
@@ -172,6 +170,7 @@ type SidebarType = Array<SidebarItemType> | PathSidebarInterface;
|
|
|
172
170
|
* @since 2.0.0
|
|
173
171
|
*/
|
|
174
172
|
type SidebarObjectType = Record<string, Array<SidebarItemType | SidebarGroupInterface>>;
|
|
173
|
+
|
|
175
174
|
/**
|
|
176
175
|
* Represents a locale-specific configuration for a VitePress site.
|
|
177
176
|
*
|
|
@@ -235,6 +234,7 @@ interface LocaleInterface extends LocaleSpecificConfig<ThemeInterface> {
|
|
|
235
234
|
interface LocalesInterface {
|
|
236
235
|
[key: string]: LocaleInterface;
|
|
237
236
|
}
|
|
237
|
+
|
|
238
238
|
/**
|
|
239
239
|
* Represents the configuration interface for a VitePress theme.
|
|
240
240
|
*
|
|
@@ -285,6 +285,7 @@ interface ThemeInterface extends Omit<DefaultTheme.Config, 'nav' | 'sidebar'> {
|
|
|
285
285
|
*/
|
|
286
286
|
sidebar?: SidebarType;
|
|
287
287
|
}
|
|
288
|
+
|
|
288
289
|
/**
|
|
289
290
|
* Represents a component-based navigation item from VitePress.
|
|
290
291
|
*
|
|
@@ -426,6 +427,7 @@ type NavObjectType = Record<string, Array<NavItemType>>;
|
|
|
426
427
|
* @since 2.0.0
|
|
427
428
|
*/
|
|
428
429
|
type NavType = Array<NavItemType> | NavObjectType;
|
|
430
|
+
|
|
429
431
|
/**
|
|
430
432
|
* Defines hooks for version- and locale-specific behavior.
|
|
431
433
|
*
|
|
@@ -718,6 +720,7 @@ interface VitepressConfigInterface extends Omit<VitepressConfigType, 'locales'>
|
|
|
718
720
|
*/
|
|
719
721
|
locales: LocalesInterface;
|
|
720
722
|
}
|
|
723
|
+
|
|
721
724
|
/**
|
|
722
725
|
* A generic type representing a function with any arguments and any return type.
|
|
723
726
|
*
|
|
@@ -773,8 +776,7 @@ type ConstructorType = new (...args: Array<any>) => any;
|
|
|
773
776
|
*
|
|
774
777
|
* @since 2.0.0
|
|
775
778
|
*/
|
|
776
|
-
type FunctionLikeType<Return = unknown, Args extends Array<unknown> = [
|
|
777
|
-
], Context = unknown> = (this: Context, ...args: Args) => Return;
|
|
779
|
+
type FunctionLikeType<Return = unknown, Args extends Array<unknown> = [], Context = unknown> = (this: Context, ...args: Args) => Return;
|
|
778
780
|
/**
|
|
779
781
|
* A type representing a constructor with specific arguments and return type.
|
|
780
782
|
*
|
|
@@ -796,8 +798,7 @@ type FunctionLikeType<Return = unknown, Args extends Array<unknown> = [
|
|
|
796
798
|
*
|
|
797
799
|
* @since 2.0.0
|
|
798
800
|
*/
|
|
799
|
-
type ConstructorLikeType<Return = unknown, Args extends Array<unknown> = [
|
|
800
|
-
]> = new (...args: Args) => Return;
|
|
801
|
+
type ConstructorLikeType<Return = unknown, Args extends Array<unknown> = []> = new (...args: Args) => Return;
|
|
801
802
|
/**
|
|
802
803
|
* Recursively makes all properties of a type optional.
|
|
803
804
|
*
|
|
@@ -864,6 +865,28 @@ type DeepPartialType<T> = T extends object ? {
|
|
|
864
865
|
* @since 2.0.0
|
|
865
866
|
*/
|
|
866
867
|
type RequireKeysType<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
868
|
+
/**
|
|
869
|
+
* A function that maps a documentation source path to the route VitePress publishes it at.
|
|
870
|
+
*
|
|
871
|
+
* @param id - The source path of a documentation file, relative to the docs root
|
|
872
|
+
* @returns The published route for that file, or the path unchanged when nothing rewrites it
|
|
873
|
+
*
|
|
874
|
+
* @remarks
|
|
875
|
+
* This is the shape VitePress expects from `rewrites` when it is given a function,
|
|
876
|
+
* and the shape the plugin reuses to list the routes of every version.
|
|
877
|
+
* Both readings come from one resolver, so a listed route always matches a served URL.
|
|
878
|
+
*
|
|
879
|
+
* @example
|
|
880
|
+
* ```ts
|
|
881
|
+
* const resolve: RouteResolverType = createRouteResolver();
|
|
882
|
+
* resolve('src/guide/index.md'); // 'guide/index.md'
|
|
883
|
+
* resolve('archive/v1.0.x/guide/index.md'); // 'v1.0.x/guide/index.md'
|
|
884
|
+
* ```
|
|
885
|
+
*
|
|
886
|
+
* @since 2.1.0
|
|
887
|
+
*/
|
|
888
|
+
type RouteResolverType = (id: string) => string;
|
|
889
|
+
|
|
867
890
|
declare function defineVersionedConfig(userConfiguration: PartialConfigurationType): UserConfig;
|
|
868
891
|
|
|
869
892
|
export {
|
|
@@ -889,4 +912,5 @@ export {
|
|
|
889
912
|
VitepressConfigInterface,
|
|
890
913
|
VitepressConfigType,
|
|
891
914
|
defineVersionedConfig
|
|
892
|
-
};
|
|
915
|
+
};
|
|
916
|
+
export * from 'vitepress';
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var
|
|
2
|
-
`),new Error(`Source directory ${this.sourcesPath} does not exist`);this.makeArchiveDirectory(this.archivePath),this.vitepressConfig=this.createVitepressConfig()}configuration;root;sources;archive;sourcesPath;archivePath;versionsConfig;vitepressConfig;versionsList=[];localesMap={};init(){this.vitepressConfig.locales.root={themeConfig:{}};let
|
|
1
|
+
var S=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var c=(t,e)=>S(t,"name",{value:e,configurable:!0});var O=(t,e,o,r)=>{for(var n=r>1?void 0:r?K(e,o):e,i=t.length-1,s;i>=0;i--)(s=t[i])&&(n=(r?s(e,o,n):s(n))||n);return r&&n&&S(e,o,n),n};import{join as C,posix as ee}from"path";import{Injectable as te}from"@remotex-labs/xinject";import{xterm as re}from"@remotex-labs/xansi/xterm.component";import{join as B}from"path/posix";import{inject as E}from"@remotex-labs/xinject";function T(t){return t.split(/[-_]/)[0]}c(T,"getLanguageOnly");function N(t){let e=Object.assign({},t);return e.themeConfig&&Object.keys(e.themeConfig).length>0&&(e.themeConfig=Object.assign({},e.themeConfig),delete e.themeConfig.nav,delete e.themeConfig.sidebar),e}c(N,"createSanitizedLocale");function R(t,e){return t?"/":`/${T(e)}/`}c(R,"generateLocaleLink");function J(t,e,o){let r=N(t);return r.label=" ",r.link=R(e,o),r}c(J,"createVersionedLocale");function w(){let t=E(p),{versionsList:e,vitepressConfig:o,configuration:r,localesMap:n}=t,{locales:i}=o,s=r.locales,a="root"in s;for(let[f,l]of Object.entries(n)){let g=l==="root",m=a?s[l]:s[f],u=N(m),h=u.lang??"";i[l]=u,i[l].link=R(g,h);for(let y of e){let j=g?y:B(f,y);i[j]=J(u,g,h)}}}c(w,"parseLocale");import{existsSync as V,mkdirSync as oe,readdirSync as ne,writeFileSync as ie}from"fs";import{join as I}from"path/posix";import{join as X}from"path";import{inject as L}from"@remotex-labs/xinject";import{readdirSync as q}from"fs";import{join as G,relative as Q}from"path/posix";function x(t,e){let o={...t};for(let r in e)if(Object.prototype.hasOwnProperty.call(e,r)){let n=e[r],i=t[r];i&&typeof i=="object"&&n&&typeof n=="object"&&!Array.isArray(n)&&!Array.isArray(n)?o[r]=x(i,n):o[r]=n}return o}c(x,"deepMerge");function d(t,e=t){let o=[],r=q(e,{withFileTypes:!0});for(let n of r){let i=G(e,n.name);if(n.isDirectory())o=o.concat(d(t,i));else if(n.isFile()&&n.name.endsWith(".md")){let s=Q(t,i);o.push(s)}}return o}c(d,"getAllMarkdownFilesRelative");function P(t,e,o){return I(o,e,t)}c(P,"rewritesHook");function Y(t,e,o){let r=o.includes(t[0])?t.shift():"";return{lang:e.includes(t[0])?t.shift():"",version:r}}c(Y,"extractLocale");function Z(){let t=L(p),e=Object.keys(t.localesMap),o=t.versionsList,r=`${t.sources}/`,n=`${t.archive}/`;return function(i){if(i.startsWith(r)){let s=i.slice(r.length),a=e.find(f=>s.startsWith(f+"/"));if(a){let f=t.localesMap[a]==="root"?"":a,l=s.slice(a.length+1);return t.versionsConfig.hooks.rewritesHook(l,"",f)}return s}if(i.startsWith(n)){let a=i.slice(n.length).split("/"),{lang:f,version:l}=Y(a,e,o),g=a.join("/");return t.versionsConfig.hooks.rewritesHook(g,l,t.localesMap[f]==="root"?"":f)}return i}}c(Z,"createRouteResolver");function _(t){let e=L(p),o={};o[e.versionsConfig.current]=d(e.sourcesPath).map(r=>t(I(e.sources,r)));for(let r of e.versionsList)o[r]=d(X(e.archivePath,r)).map(n=>t(I(e.archive,r,n)));return o}c(_,"parseVersionRoutes");function M(){let t=L(p),e=Z();t.vitepressConfig.rewrites=e,Object.assign(t.routesMap,_(e))}c(M,"parseRoutesComponent");var b={locales:{},rewrites:{},versionsConfig:{current:"latest",sources:"src",archive:"archive",hooks:{rewritesHook:P},versionSwitcher:{text:"Switch Version",includeCurrentVersion:!0}}};var p=class{constructor(e=b){this.configuration=e;let{sources:o,archive:r}=e.versionsConfig;if(this.sources=o,this.archive=r,this.versionsConfig=e.versionsConfig,this.root=C(process.cwd(),process.argv[3]??"",e.srcDir??""),this.sourcesPath=C(this.root,this.sources),this.archivePath=C(this.root,this.archive),!V(this.sourcesPath))throw console.error(re.red("[ viteplus ]"),`Source directory ${this.sourcesPath} does not exist
|
|
2
|
+
`),new Error(`Source directory ${this.sourcesPath} does not exist`);this.makeArchiveDirectory(this.archivePath),this.vitepressConfig=this.createVitepressConfig()}configuration;root;sources;archive;sourcesPath;archivePath;versionsConfig;vitepressConfig;versionsList=[];localesMap={};routesMap={};init(){this.vitepressConfig.locales.root={themeConfig:{}};let e=ne(this.archivePath,{withFileTypes:!0}).filter(o=>o.isDirectory()).map(o=>o.name);return this.versionsList.push(...e),this.initializeLocalesMap(),this}initializeLocalesMap(){let e=this.vitepressConfig.locales,o=this.configuration.locales;if(e.root={},Object.keys(o).length>0){let r=Object.keys(o),n="root"in o?"root":r[0];for(let i of r){let s=T(o[i].lang??i);for(let a of this.versionsList){if(i===n)continue;let f=ee.join(s,a);e[f]={}}i===n?this.localesMap[o[i].link??s]="root":(e[i]={},this.localesMap[o[i].link??s]=i)}}for(let r of this.versionsList)e[r]={}}makeArchiveDirectory(e){e&&(V(e)||(oe(e),ie(C(e,".gitkeep"),"")))}createVitepressConfig(){let e={},o=["locales","rewrites","themeConfig","versionsConfig"];for(let r of Object.keys(this.configuration))if(!o.includes(r))e[r]=this.configuration[r];else if(r==="themeConfig"){let n=this.configuration.themeConfig??{};e.themeConfig=Object.fromEntries(Object.entries(n).filter(([i])=>i!=="nav"&&i!=="sidebar"))}else r!=="versionsConfig"&&(e[r]={});return e}};c(p,"StateModel"),p=O([te({scope:"singleton"})],p);import{forceInject as ye}from"@remotex-labs/xinject";import{join as U}from"path/posix";import{inject as F}from"@remotex-labs/xinject";function W(t,e,o="Latest"){if(t.versionSwitcher===!1)return;let{text:r,includeCurrentVersion:n}=t.versionSwitcher,i=[];n&&i.push({link:"/",text:o==="Latest"?o:`${o} (latest)`,skipVersioning:!0});for(let s of e)i.push({text:s,link:`/${s}/`,skipVersioning:!0});return{text:r,items:i}}c(W,"versionSwitcher");function se(t){return"items"in t&&Array.isArray(t.items)}c(se,"isNavItemWithChildren");function ce(t){return"link"in t&&!!t.link&&typeof t.link=="string"&&!t.link.includes("http")}c(ce,"isNavItemWithLink");function $(t,e){return se(e)&&!e.skipVersioning?{...e,items:e.items.map(o=>$(t,o))}:ce(e)&&!e.skipVersioning?{...e,link:typeof e.link=="string"?U("/",t,e.link):e.link}:e}c($,"replaceLinksRecursive");function ae(t,e){let o=F(p);return e==="root"&&(e=""),t.map(r=>"component"in r&&r.component?{...r,props:{...r.props,versioningPlugin:{routes:o.routesMap,versions:o.versionsList,currentVersion:o.versionsConfig.current}}}:$(e,r))}c(ae,"populateNav");function z(t,e,o="",r={}){if(Array.isArray(e)){let n=o||"root";t[n]??=[],t[n].push(...e),r[n]?t[n].push(...r[n]):r.root&&t[n].push(...r.root);return}for(let[n,i]of Object.entries(e)){let a=n==="root"?n==="root"&&o===""?"root":o:U(o,n);t[a]??=[],t[a].push(...i),r[n]?t[a].push(...r[n]):r.root&&t[a].push(...r.root)}}c(z,"normalizeNav");function fe(t){let e=t.configuration.locales,o=Object.keys(e),r={root:[]};t.configuration.themeConfig?.nav&&z(r,t.configuration.themeConfig.nav);let n=W(t.versionsConfig,t.versionsList,t.versionsConfig.current);if(n&&r.root.push(n),!o.length)return r;let i={root:[]};for(let s of o){let a=s==="root"||t.localesMap[s]==="root"?"root":s;z(i,e[s].themeConfig?.nav??[],a,r)}return i}c(fe,"normalizeNavs");function pe(t,e){if(t[e])return t[e];if(e.includes("/")){let o=e.split("/")[0];if(t[o])return t[o]}return t.root}c(pe,"getNavForLocale");function D(){let t=F(p),{vitepressConfig:{locales:e}}=t,o=fe(t);for(let[r,n]of Object.entries(e)){let i=pe(o,r);n.themeConfig??={},n.themeConfig.nav=ae(i,r)}}c(D,"parseNavs");import{join as le}from"path/posix";import{inject as ge}from"@remotex-labs/xinject";function v(...t){let e=le(...t.filter(Boolean));return e==="."?"":e}c(v,"safeJoin");function ue(t,e){let o=e==="root"?"":e;return t.map(r=>r.skipVersioning||r?.link?.startsWith("http")||!(r.link||r.items)||!o?r:{...r,base:v("/",o,r.base??"","/")})}c(ue,"populateSidebar");function k(t,e,o){if(e.length===0&&(e=["root"]),o.includes(t[0]))return{lang:"",version:t.shift()};let r=e.includes(t[0])?t.shift():"",n=o.includes(t[0])?t.shift():"";return{lang:r,version:n}}c(k,"extractLocale");function A(t,e,o,r=""){if(!o)return;let n=r==="root"?"":r;if(Array.isArray(o)){let a=n||"/";e[r]??={},e[r][a]??=[],e[r][a].push(...o);return}let i=Object.values(t.localesMap),s=t.versionsList;for(let[a,f]of Object.entries(o)){let l=a.split("/").filter(Boolean),{lang:g,version:m}=k(l,i,s);if(g&&!r.startsWith(g))continue;let u=m?v(n,m):n,h=v(u,...l)||"/",y=u||"root";e[y]??={},e[y][h]??=[];let j=Array.isArray(f)?f:[f];e[y][h].push(...j)}}c(A,"normalizeSidebar");function me(t){let{vitepressConfig:e,configuration:{locales:o,themeConfig:r}}=t,n={};if(Object.keys(o).length>0)for(let[a,f]of Object.entries(o))A(t,n,r?.sidebar,a),A(t,n,f.themeConfig?.sidebar,a);else A(t,n,r?.sidebar,"root");let i=Object.values(t.localesMap),s=t.versionsList;for(let a of Object.keys(e.locales)){if(n[a])continue;let{lang:f}=k(a.split("/"),i,s),l=n[f||"root"];if(l){n[a]={};for(let[g,m]of Object.entries(l)){let u=g.split("/").filter(Boolean);k(u,i,s),n[a][v(a,...u)]=[...m]}}}return n}c(me,"normalizeSidebars");function H(){let t=ge(p),{vitepressConfig:{locales:e}}=t,o=Object.values(t.localesMap),r=t.versionsList,n=me(t);for(let[i,s]of Object.entries(e))if(n[i]){s.themeConfig??={},(!s.themeConfig.sidebar||Array.isArray(s.themeConfig.sidebar))&&(s.themeConfig.sidebar={});for(let[a,f]of Object.entries(n[i])){let{lang:l,version:g}=k(a.split("/"),o,r);s.themeConfig.sidebar[a]=ue(f,v(l,g))}}}c(H,"parseSidebars");function pt(t){let e=x(b,t),o=ye(p,e).init();return w(),M(),D(),H(),o.vitepressConfig}c(pt,"defineVersionedConfig");export{pt as defineVersionedConfig};
|
|
3
3
|
//# sourceMappingURL=index.js.map
|