@viteplus/versions 2.0.6 → 2.0.8
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 +108 -120
- package/dist/index.d.ts +415 -2114
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -8
- package/package.json +77 -72
package/dist/index.d.ts
CHANGED
|
@@ -1,322 +1,240 @@
|
|
|
1
|
-
|
|
2
1
|
/**
|
|
3
2
|
* This file was automatically generated by xBuild.
|
|
4
3
|
* DO NOT EDIT MANUALLY.
|
|
5
4
|
*/
|
|
6
|
-
import type { UserConfig } from 'vitepress';
|
|
7
|
-
export type * from 'vitepress';
|
|
8
|
-
import type { DefaultTheme, UserConfig } from 'vitepress';
|
|
9
|
-
import type { DefaultTheme } from 'vitepress';
|
|
10
|
-
import type { LocaleSpecificConfig } from 'vitepress';
|
|
11
|
-
import type { SidebarItemType } from '@viteplus/versions';
|
|
12
5
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Export interfaces
|
|
18
|
-
*/
|
|
19
|
-
export declare function defineVersionedConfig(userConfiguration: PartialConfigurationType): UserConfig;
|
|
6
|
+
import { DefaultTheme, LocaleSpecificConfig, UserConfig } from 'vitepress';
|
|
7
|
+
|
|
8
|
+
export * from 'vitepress';
|
|
20
9
|
|
|
21
10
|
/**
|
|
22
|
-
*
|
|
23
|
-
*/
|
|
24
|
-
/**
|
|
25
|
-
* Defines hooks for version- and locale-specific behavior.
|
|
11
|
+
* Represents a sidebar item from VitePress with optional versioning control.
|
|
26
12
|
*
|
|
27
13
|
* @remarks
|
|
28
|
-
*
|
|
29
|
-
*
|
|
14
|
+
* Extends VitePress's {@link DefaultTheme.SidebarItem} type by adding an optional
|
|
15
|
+
* `skipVersioning` flag. Use this flag to indicate that the item should not be
|
|
16
|
+
* automatically versioned in multi-version documentation setups.
|
|
30
17
|
*
|
|
31
18
|
* @example
|
|
32
19
|
* ```ts
|
|
33
|
-
* const
|
|
34
|
-
*
|
|
35
|
-
*
|
|
20
|
+
* const item: SidebarItemType = {
|
|
21
|
+
* text: "Introduction",
|
|
22
|
+
* link: "/guide/introduction",
|
|
23
|
+
* skipVersioning: true
|
|
36
24
|
* };
|
|
37
25
|
* ```
|
|
38
26
|
*
|
|
39
27
|
* @since 2.0.0
|
|
40
28
|
*/
|
|
41
|
-
|
|
29
|
+
type SidebarItemType = DefaultTheme.SidebarItem & {
|
|
42
30
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* @param source - The original file path or source string.
|
|
46
|
-
* @param version - The current documentation version (e.g., "2.0").
|
|
47
|
-
* @param locale - The locale code or folder name (e.g., "en", "de").
|
|
48
|
-
*
|
|
49
|
-
* @returns The rewritten path string, which can be used for routing or file organization.
|
|
31
|
+
* Determines whether this sidebar item should be excluded from automatic versioning.
|
|
50
32
|
*
|
|
33
|
+
* @default false
|
|
51
34
|
* @remarks
|
|
52
|
-
*
|
|
53
|
-
* allowing complete control over URL or file structure.
|
|
35
|
+
* When `true`, this sidebar item will remain consistent across all documentation versions.
|
|
54
36
|
*
|
|
55
37
|
* @since 2.0.0
|
|
56
38
|
*/
|
|
57
|
-
|
|
58
|
-
}
|
|
39
|
+
skipVersioning?: boolean;
|
|
40
|
+
};
|
|
59
41
|
/**
|
|
60
|
-
*
|
|
42
|
+
* Represents a sidebar group containing multiple sidebar items.
|
|
61
43
|
*
|
|
62
44
|
* @remarks
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* should appear in the switcher dropdown.
|
|
45
|
+
* Each group has a `base` path and an array of sidebar items.
|
|
46
|
+
* Useful for organizing related pages under a common path prefix.
|
|
66
47
|
*
|
|
67
48
|
* @example
|
|
68
49
|
* ```ts
|
|
69
|
-
* const
|
|
70
|
-
*
|
|
71
|
-
*
|
|
50
|
+
* const group: SidebarGroupInterface = {
|
|
51
|
+
* base: "/guide/",
|
|
52
|
+
* items: [
|
|
53
|
+
* { text: "Introduction", link: "/guide/introduction" },
|
|
54
|
+
* { text: "Setup", link: "/guide/setup" }
|
|
55
|
+
* ]
|
|
72
56
|
* };
|
|
73
57
|
* ```
|
|
74
58
|
*
|
|
59
|
+
* @see SidebarItemType
|
|
75
60
|
* @since 2.0.0
|
|
76
61
|
*/
|
|
77
|
-
|
|
62
|
+
interface SidebarGroupInterface {
|
|
78
63
|
/**
|
|
79
|
-
* The
|
|
64
|
+
* The base path for the sidebar group.
|
|
80
65
|
*
|
|
81
66
|
* @remarks
|
|
82
|
-
* This
|
|
67
|
+
* This path is prepended to all child sidebar items within the group.
|
|
68
|
+
* Typically corresponds to the folder containing the group’s pages, e.g., `"en"`.
|
|
83
69
|
*
|
|
84
70
|
* @since 2.0.0
|
|
85
71
|
*/
|
|
86
|
-
|
|
72
|
+
base: string;
|
|
87
73
|
/**
|
|
88
|
-
*
|
|
74
|
+
* The list of sidebar items within this group.
|
|
89
75
|
*
|
|
90
76
|
* @remarks
|
|
91
|
-
*
|
|
77
|
+
* Each item is typed as {@link SidebarItemType}, which may include links,
|
|
78
|
+
* collapsible sections, or other sidebar elements.
|
|
92
79
|
*
|
|
93
80
|
* @since 2.0.0
|
|
94
81
|
*/
|
|
95
|
-
|
|
82
|
+
items: Array<SidebarItemType>;
|
|
96
83
|
}
|
|
97
84
|
/**
|
|
98
|
-
*
|
|
85
|
+
* Represents a mapping of paths to sidebar items or groups.
|
|
99
86
|
*
|
|
100
87
|
* @remarks
|
|
101
|
-
*
|
|
102
|
-
* -
|
|
103
|
-
* -
|
|
104
|
-
* - `hooks` allows for custom rewriting logic per version.
|
|
105
|
-
* - `versionSwitcher` enables or disables the version switcher, or provides its configuration.
|
|
88
|
+
* The keys are path strings, and the values can be either:
|
|
89
|
+
* - An array of sidebar items (`SidebarItemType[]`), or
|
|
90
|
+
* - A sidebar group (`SidebarGroupInterface`).
|
|
106
91
|
*
|
|
107
92
|
* @example
|
|
108
93
|
* ```ts
|
|
109
|
-
* const
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* },
|
|
116
|
-
* versionSwitcher: { text: "Version", includeCurrentVersion: true }
|
|
94
|
+
* const sidebar: PathSidebarInterface = {
|
|
95
|
+
* guide: [
|
|
96
|
+
* { text: "Intro", link: "/guide/intro" },
|
|
97
|
+
* { text: "Setup", link: "/guide/setup" }
|
|
98
|
+
* ],
|
|
99
|
+
* api: { base: "/api/", items: [ { text: "Functions", link: "/api/functions" } ] }
|
|
117
100
|
* };
|
|
118
101
|
* ```
|
|
119
102
|
*
|
|
103
|
+
* @see SidebarItemType
|
|
104
|
+
* @see SidebarGroupInterface
|
|
105
|
+
*
|
|
120
106
|
* @since 2.0.0
|
|
121
107
|
*/
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
* The currently active documentation version.
|
|
125
|
-
*
|
|
126
|
-
* @remarks
|
|
127
|
-
* Used to determine which version to serve by default and which version
|
|
128
|
-
* should be highlighted in the version switcher.
|
|
129
|
-
*
|
|
130
|
-
* @since 2.0.0
|
|
131
|
-
*/
|
|
132
|
-
current: string;
|
|
133
|
-
/**
|
|
134
|
-
* The folder or path where the current versioned sources reside.
|
|
135
|
-
*
|
|
136
|
-
* @since 2.0.0
|
|
137
|
-
*/
|
|
138
|
-
sources: string;
|
|
139
|
-
/**
|
|
140
|
-
* The folder or path where archived versions are stored.
|
|
141
|
-
*
|
|
142
|
-
* @since 2.0.0
|
|
143
|
-
*/
|
|
144
|
-
archive: string;
|
|
145
|
-
/**
|
|
146
|
-
* Hooks for custom behavior when working with versioned content.
|
|
147
|
-
*
|
|
148
|
-
* @remarks
|
|
149
|
-
* Currently, supports `rewritesHook`, which can programmatically rewrite
|
|
150
|
-
* paths based on version and locale.
|
|
151
|
-
*
|
|
152
|
-
* @see VersionsHooksInterface
|
|
153
|
-
* @since 2.0.0
|
|
154
|
-
*/
|
|
155
|
-
hooks: VersionsHooksInterface;
|
|
156
|
-
/**
|
|
157
|
-
* Configuration for the version switcher or `false` to disable it.
|
|
158
|
-
*
|
|
159
|
-
* @remarks
|
|
160
|
-
* If enabled, this object defines the switcher text and whether the
|
|
161
|
-
* current version is included in the switcher options.
|
|
162
|
-
*
|
|
163
|
-
* @see VersionsSwitcherInterface
|
|
164
|
-
* @since 2.0.0
|
|
165
|
-
*/
|
|
166
|
-
versionSwitcher: false | VersionsSwitcherInterface;
|
|
108
|
+
interface PathSidebarInterface {
|
|
109
|
+
[path: string]: Array<SidebarItemType> | SidebarGroupInterface;
|
|
167
110
|
}
|
|
168
111
|
/**
|
|
169
|
-
*
|
|
112
|
+
* Represents the overall sidebar configuration.
|
|
170
113
|
*
|
|
171
114
|
* @remarks
|
|
172
|
-
*
|
|
173
|
-
* -
|
|
174
|
-
* -
|
|
175
|
-
*
|
|
115
|
+
* Can be defined in one of two ways:
|
|
116
|
+
* - As a flat array of {@link SidebarItemType}, or
|
|
117
|
+
* - As a path-based mapping using {@link PathSidebarInterface}.
|
|
118
|
+
*
|
|
119
|
+
* This flexibility allows defining either a single global sidebar
|
|
120
|
+
* or multiple sidebars scoped to different route prefixes.
|
|
176
121
|
*
|
|
177
122
|
* @example
|
|
123
|
+
* Flat sidebar:
|
|
178
124
|
* ```ts
|
|
179
|
-
* const
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
125
|
+
* const sidebar: SidebarType = [
|
|
126
|
+
* { text: "Home", link: "/" },
|
|
127
|
+
* { text: "Guide", link: "/guide/" }
|
|
128
|
+
* ];
|
|
129
|
+
* ```
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* Path-based sidebars:
|
|
133
|
+
* ```ts
|
|
134
|
+
* const sidebar: SidebarType = {
|
|
135
|
+
* "/guide/": [
|
|
136
|
+
* { text: "Introduction", link: "/guide/introduction" }
|
|
137
|
+
* ],
|
|
138
|
+
* "/api/": [
|
|
139
|
+
* { text: "API Reference", link: "/api/" }
|
|
140
|
+
* ]
|
|
194
141
|
* };
|
|
195
142
|
* ```
|
|
196
143
|
*
|
|
144
|
+
* @see SidebarItemType
|
|
145
|
+
* @see PathSidebarInterface
|
|
146
|
+
*
|
|
197
147
|
* @since 2.0.0
|
|
198
148
|
*/
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Locale-specific configuration for the site.
|
|
202
|
-
*
|
|
203
|
-
* @remarks
|
|
204
|
-
* Uses {@link LocalesInterface} to strongly type each locale's settings.
|
|
205
|
-
*
|
|
206
|
-
* @since 2.0.0
|
|
207
|
-
*/
|
|
208
|
-
locales: LocalesInterface;
|
|
209
|
-
/**
|
|
210
|
-
* Path rewrites for the site.
|
|
211
|
-
*
|
|
212
|
-
* @remarks
|
|
213
|
-
* Maps old paths to new paths, enabling URL restructuring without breaking links.
|
|
214
|
-
*
|
|
215
|
-
* @since 2.0.0
|
|
216
|
-
*/
|
|
217
|
-
rewrites: Record<string, string>;
|
|
218
|
-
/**
|
|
219
|
-
* Versioning configuration for documentation.
|
|
220
|
-
*
|
|
221
|
-
* @remarks
|
|
222
|
-
* Defines the current version, source directory, archive, hooks, and version switcher behavior.
|
|
223
|
-
*
|
|
224
|
-
* @see VersionsConfigInterface
|
|
225
|
-
* @since 2.0.0
|
|
226
|
-
*/
|
|
227
|
-
versionsConfig: VersionsConfigInterface;
|
|
228
|
-
}
|
|
149
|
+
type SidebarType = Array<SidebarItemType> | PathSidebarInterface;
|
|
229
150
|
/**
|
|
230
|
-
* Represents a
|
|
151
|
+
* Represents a mapping of paths to sidebar item arrays.
|
|
231
152
|
*
|
|
232
153
|
* @remarks
|
|
233
|
-
* This
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
* Useful for scenarios where you want to provide only a subset of the configuration,
|
|
237
|
-
* for example, when overriding default settings or merging user-provided options.
|
|
154
|
+
* This structure allows defining sidebars on a per-path basis,
|
|
155
|
+
* where each key is a route prefix (e.g., `"/guide/"`) and its value
|
|
156
|
+
* is an array of {@link SidebarItemType}.
|
|
238
157
|
*
|
|
239
158
|
* @example
|
|
240
159
|
* ```ts
|
|
241
|
-
* const
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
160
|
+
* const sidebars: SidebarObjectType = {
|
|
161
|
+
* "/guide/": [
|
|
162
|
+
* { text: "Introduction", link: "/guide/introduction" },
|
|
163
|
+
* { text: "Setup", link: "/guide/setup" }
|
|
164
|
+
* ],
|
|
165
|
+
* "/api/": [
|
|
166
|
+
* { text: "API Reference", link: "/api/" }
|
|
167
|
+
* ]
|
|
248
168
|
* };
|
|
249
169
|
* ```
|
|
250
170
|
*
|
|
171
|
+
* @see SidebarItemType
|
|
251
172
|
* @since 2.0.0
|
|
252
173
|
*/
|
|
253
|
-
|
|
174
|
+
type SidebarObjectType = Record<string, Array<SidebarItemType | SidebarGroupInterface>>;
|
|
254
175
|
/**
|
|
255
|
-
*
|
|
176
|
+
* Represents a locale-specific configuration for a VitePress site.
|
|
256
177
|
*
|
|
257
178
|
* @remarks
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
* - `
|
|
261
|
-
* - `
|
|
262
|
-
* - `themeConfig`
|
|
179
|
+
* Extends VitePress's `LocaleSpecificConfig` with a custom {@link ThemeInterface}.
|
|
180
|
+
* Adds optional properties:
|
|
181
|
+
* - `link` — the base URL or path for this locale.
|
|
182
|
+
* - `label` — a human-readable label for the locale (e.g., "English", "Deutsch").
|
|
263
183
|
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
184
|
+
* This interface allows configuring per-locale theme settings, navigation,
|
|
185
|
+
* sidebar, and other locale-specific behavior.
|
|
266
186
|
*
|
|
267
187
|
* @example
|
|
268
188
|
* ```ts
|
|
269
|
-
* const
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
* themeConfig: {
|
|
189
|
+
* const enLocale: LocaleInterface = {
|
|
190
|
+
* link: "/en/",
|
|
191
|
+
* label: "English",
|
|
192
|
+
* themeConfig: {
|
|
193
|
+
* nav: [{ text: "Home", link: "/en/" }],
|
|
194
|
+
* sidebar: { "/en/guide/": [{ text: "Intro", link: "/en/guide/" }] }
|
|
195
|
+
* }
|
|
273
196
|
* };
|
|
274
197
|
* ```
|
|
275
198
|
*
|
|
276
199
|
* @since 2.0.0
|
|
277
200
|
*/
|
|
278
|
-
|
|
201
|
+
interface LocaleInterface extends LocaleSpecificConfig<ThemeInterface> {
|
|
202
|
+
/**
|
|
203
|
+
* The base path for the locale.
|
|
204
|
+
*
|
|
205
|
+
* @default undefined
|
|
206
|
+
* @since 2.0.0
|
|
207
|
+
*/
|
|
208
|
+
link?: string;
|
|
209
|
+
/**
|
|
210
|
+
* A human-readable label for the locale.
|
|
211
|
+
*
|
|
212
|
+
* @default undefined
|
|
213
|
+
* @since 2.0.0
|
|
214
|
+
*/
|
|
215
|
+
label?: string;
|
|
216
|
+
}
|
|
279
217
|
/**
|
|
280
|
-
*
|
|
218
|
+
* Represents a mapping of locale codes to their corresponding locale configurations.
|
|
281
219
|
*
|
|
282
220
|
* @remarks
|
|
283
|
-
*
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
* This ensures:
|
|
287
|
-
* - `locales` are fully typed with per-locale configurations.
|
|
288
|
-
* - Other required properties from `VitepressConfigType` (`rewrites`, `themeConfig`) remain enforced.
|
|
289
|
-
* - Remaining properties from `UserConfig<DefaultTheme.Config>` retain their optionality.
|
|
221
|
+
* The keys are locale codes (e.g., `"en"`, `"de"`), and the values are `LocaleInterface` objects.
|
|
222
|
+
* Useful for multi-language or localized documentation setups in VitePress.
|
|
290
223
|
*
|
|
291
224
|
* @example
|
|
292
225
|
* ```ts
|
|
293
|
-
* const
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
* de: { link: "/de/", label: "Deutsch" }
|
|
297
|
-
* },
|
|
298
|
-
* rewrites: { "/old-path": "/new-path" },
|
|
299
|
-
* themeConfig: { nav: [], sidebar: {} }
|
|
226
|
+
* const locales: LocalesInterface = {
|
|
227
|
+
* en: { link: "/en/", label: "English" },
|
|
228
|
+
* de: { link: "/de/", label: "Deutsch" }
|
|
300
229
|
* };
|
|
301
230
|
* ```
|
|
302
231
|
*
|
|
232
|
+
* @see LocaleInterface
|
|
303
233
|
* @since 2.0.0
|
|
304
234
|
*/
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
* Locale-specific configuration for the site.
|
|
308
|
-
*
|
|
309
|
-
* @remarks
|
|
310
|
-
* Uses {@link LocalesInterface} to strongly type each locale's settings.
|
|
311
|
-
*
|
|
312
|
-
* @since 2.0.0
|
|
313
|
-
*/
|
|
314
|
-
locales: LocalesInterface;
|
|
235
|
+
interface LocalesInterface {
|
|
236
|
+
[key: string]: LocaleInterface;
|
|
315
237
|
}
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* Import will remove at compile time
|
|
319
|
-
*/
|
|
320
238
|
/**
|
|
321
239
|
* Represents the configuration interface for a VitePress theme.
|
|
322
240
|
*
|
|
@@ -347,7 +265,7 @@ export interface VitepressConfigInterface extends Omit<VitepressConfigType, 'loc
|
|
|
347
265
|
*
|
|
348
266
|
* @since 2.0.0
|
|
349
267
|
*/
|
|
350
|
-
|
|
268
|
+
interface ThemeInterface extends Omit<DefaultTheme.Config, 'nav' | 'sidebar'> {
|
|
351
269
|
/**
|
|
352
270
|
* Navigation structure of the site.
|
|
353
271
|
*
|
|
@@ -367,10 +285,6 @@ export interface ThemeInterface extends Omit<DefaultTheme.Config, 'nav' | 'sideb
|
|
|
367
285
|
*/
|
|
368
286
|
sidebar?: SidebarType;
|
|
369
287
|
}
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* Import will remove at compile time
|
|
373
|
-
*/
|
|
374
288
|
/**
|
|
375
289
|
* Represents a component-based navigation item from VitePress.
|
|
376
290
|
*
|
|
@@ -380,7 +294,7 @@ export interface ThemeInterface extends Omit<DefaultTheme.Config, 'nav' | 'sideb
|
|
|
380
294
|
*
|
|
381
295
|
* @since 2.0.0
|
|
382
296
|
*/
|
|
383
|
-
|
|
297
|
+
type NavItemComponentType = DefaultTheme.NavItemComponent;
|
|
384
298
|
/**
|
|
385
299
|
* Represents a navigation item with a link.
|
|
386
300
|
*
|
|
@@ -401,7 +315,7 @@ export type NavItemComponentType = DefaultTheme.NavItemComponent;
|
|
|
401
315
|
*
|
|
402
316
|
* @since 2.0.0
|
|
403
317
|
*/
|
|
404
|
-
|
|
318
|
+
type NavItemWithLinkType = DefaultTheme.NavItemWithLink & {
|
|
405
319
|
/**
|
|
406
320
|
* Indicates whether this navigation item should be excluded from automatic versioning.
|
|
407
321
|
*
|
|
@@ -445,7 +359,7 @@ export type NavItemWithLinkType = DefaultTheme.NavItemWithLink & {
|
|
|
445
359
|
*
|
|
446
360
|
* @since 2.0.0
|
|
447
361
|
*/
|
|
448
|
-
|
|
362
|
+
type NavItemWithChildrenType = Omit<DefaultTheme.NavItemWithChildren, 'items'> & {
|
|
449
363
|
/**
|
|
450
364
|
* Child navigation items for this item.
|
|
451
365
|
*
|
|
@@ -474,7 +388,7 @@ export type NavItemWithChildrenType = Omit<DefaultTheme.NavItemWithChildren, 'it
|
|
|
474
388
|
*
|
|
475
389
|
* @since 2.0.0
|
|
476
390
|
*/
|
|
477
|
-
|
|
391
|
+
type NavItemType = NavItemComponentType | NavItemWithLinkType | NavItemWithChildrenType;
|
|
478
392
|
/**
|
|
479
393
|
* Represents a record of named navigation groups.
|
|
480
394
|
*
|
|
@@ -500,7 +414,7 @@ export type NavItemType = NavItemComponentType | NavItemWithLinkType | NavItemWi
|
|
|
500
414
|
*
|
|
501
415
|
* @since 2.0.0
|
|
502
416
|
*/
|
|
503
|
-
|
|
417
|
+
type NavObjectType = Record<string, Array<NavItemType>>;
|
|
504
418
|
/**
|
|
505
419
|
* Represents the navigation structure.
|
|
506
420
|
*
|
|
@@ -511,2081 +425,468 @@ export type NavObjectType = Record<string, Array<NavItemType>>;
|
|
|
511
425
|
*
|
|
512
426
|
* @since 2.0.0
|
|
513
427
|
*/
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
/**
|
|
517
|
-
* Import will remove at compile time
|
|
518
|
-
*/
|
|
428
|
+
type NavType = Array<NavItemType> | NavObjectType;
|
|
519
429
|
/**
|
|
520
|
-
*
|
|
430
|
+
* Defines hooks for version- and locale-specific behavior.
|
|
521
431
|
*
|
|
522
432
|
* @remarks
|
|
523
|
-
*
|
|
524
|
-
*
|
|
525
|
-
* automatically versioned in multi-version documentation setups.
|
|
433
|
+
* The `rewritesHook` function allows you to programmatically rewrite
|
|
434
|
+
* paths or content based on the documentation version and locale being served.
|
|
526
435
|
*
|
|
527
436
|
* @example
|
|
528
437
|
* ```ts
|
|
529
|
-
* const
|
|
530
|
-
*
|
|
531
|
-
*
|
|
532
|
-
* skipVersioning: true
|
|
438
|
+
* const hooks: VersionsHooksInterface = {
|
|
439
|
+
* rewritesHook: (source, version, locale) =>
|
|
440
|
+
* `${version}/${locale}/${source}`
|
|
533
441
|
* };
|
|
534
442
|
* ```
|
|
535
443
|
*
|
|
536
444
|
* @since 2.0.0
|
|
537
445
|
*/
|
|
538
|
-
|
|
446
|
+
interface VersionsHooksInterface {
|
|
539
447
|
/**
|
|
540
|
-
*
|
|
448
|
+
* A function that rewrites a source path based on version and locale.
|
|
449
|
+
*
|
|
450
|
+
* @param source - The original file path or source string.
|
|
451
|
+
* @param version - The current documentation version (e.g., "2.0").
|
|
452
|
+
* @param locale - The locale code or folder name (e.g., "en", "de").
|
|
453
|
+
*
|
|
454
|
+
* @returns The rewritten path string, which can be used for routing or file organization.
|
|
541
455
|
*
|
|
542
|
-
* @default false
|
|
543
456
|
* @remarks
|
|
544
|
-
*
|
|
457
|
+
* This hook is invoked whenever paths need to be version- and locale-aware,
|
|
458
|
+
* allowing complete control over URL or file structure.
|
|
545
459
|
*
|
|
546
460
|
* @since 2.0.0
|
|
547
461
|
*/
|
|
548
|
-
|
|
549
|
-
}
|
|
462
|
+
rewritesHook(source: string, version: string, locale: string): string;
|
|
463
|
+
}
|
|
550
464
|
/**
|
|
551
|
-
*
|
|
465
|
+
* Configuration for a version switcher component.
|
|
552
466
|
*
|
|
553
467
|
* @remarks
|
|
554
|
-
*
|
|
555
|
-
*
|
|
468
|
+
* - `text` is the display label for the version switcher.
|
|
469
|
+
* - `includeCurrentVersion` determines whether the currently active version
|
|
470
|
+
* should appear in the switcher dropdown.
|
|
556
471
|
*
|
|
557
472
|
* @example
|
|
558
473
|
* ```ts
|
|
559
|
-
* const
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
* { text: "Introduction", link: "/guide/introduction" },
|
|
563
|
-
* { text: "Setup", link: "/guide/setup" }
|
|
564
|
-
* ]
|
|
474
|
+
* const switcher: VersionsSwitcherInterface = {
|
|
475
|
+
* text: "Version",
|
|
476
|
+
* includeCurrentVersion: true
|
|
565
477
|
* };
|
|
566
478
|
* ```
|
|
567
479
|
*
|
|
568
|
-
* @see SidebarItemType
|
|
569
480
|
* @since 2.0.0
|
|
570
481
|
*/
|
|
571
|
-
|
|
482
|
+
interface VersionsSwitcherInterface {
|
|
572
483
|
/**
|
|
573
|
-
* The
|
|
484
|
+
* The display label for the version switcher component.
|
|
574
485
|
*
|
|
575
486
|
* @remarks
|
|
576
|
-
* This
|
|
577
|
-
* Typically corresponds to the folder containing the group’s pages, e.g., `"en"`.
|
|
487
|
+
* This text is shown in the UI as the version selector label.
|
|
578
488
|
*
|
|
579
489
|
* @since 2.0.0
|
|
580
490
|
*/
|
|
581
|
-
|
|
491
|
+
text: string;
|
|
582
492
|
/**
|
|
583
|
-
*
|
|
493
|
+
* Determines whether the currently active version should appear in the switcher dropdown.
|
|
584
494
|
*
|
|
585
495
|
* @remarks
|
|
586
|
-
*
|
|
587
|
-
* collapsible sections, or other sidebar elements.
|
|
496
|
+
* If `true`, the current version will be included; if `false`, it will be omitted.
|
|
588
497
|
*
|
|
589
498
|
* @since 2.0.0
|
|
590
499
|
*/
|
|
591
|
-
|
|
592
|
-
}
|
|
593
|
-
/**
|
|
594
|
-
* Represents a mapping of paths to sidebar items or groups.
|
|
595
|
-
*
|
|
596
|
-
* @remarks
|
|
597
|
-
* The keys are path strings, and the values can be either:
|
|
598
|
-
* - An array of sidebar items (`SidebarItemType[]`), or
|
|
599
|
-
* - A sidebar group (`SidebarGroupInterface`).
|
|
600
|
-
*
|
|
601
|
-
* @example
|
|
602
|
-
* ```ts
|
|
603
|
-
* const sidebar: PathSidebarInterface = {
|
|
604
|
-
* guide: [
|
|
605
|
-
* { text: "Intro", link: "/guide/intro" },
|
|
606
|
-
* { text: "Setup", link: "/guide/setup" }
|
|
607
|
-
* ],
|
|
608
|
-
* api: { base: "/api/", items: [ { text: "Functions", link: "/api/functions" } ] }
|
|
609
|
-
* };
|
|
610
|
-
* ```
|
|
611
|
-
*
|
|
612
|
-
* @see SidebarItemType
|
|
613
|
-
* @see SidebarGroupInterface
|
|
614
|
-
*
|
|
615
|
-
* @since 2.0.0
|
|
616
|
-
*/
|
|
617
|
-
export interface PathSidebarInterface {
|
|
618
|
-
[path: string]: Array<SidebarItemType> | SidebarGroupInterface;
|
|
500
|
+
includeCurrentVersion: boolean;
|
|
619
501
|
}
|
|
620
502
|
/**
|
|
621
|
-
*
|
|
622
|
-
*
|
|
623
|
-
* @remarks
|
|
624
|
-
* Can be defined in one of two ways:
|
|
625
|
-
* - As a flat array of {@link SidebarItemType}, or
|
|
626
|
-
* - As a path-based mapping using {@link PathSidebarInterface}.
|
|
627
|
-
*
|
|
628
|
-
* This flexibility allows defining either a single global sidebar
|
|
629
|
-
* or multiple sidebars scoped to different route prefixes.
|
|
630
|
-
*
|
|
631
|
-
* @example
|
|
632
|
-
* Flat sidebar:
|
|
633
|
-
* ```ts
|
|
634
|
-
* const sidebar: SidebarType = [
|
|
635
|
-
* { text: "Home", link: "/" },
|
|
636
|
-
* { text: "Guide", link: "/guide/" }
|
|
637
|
-
* ];
|
|
638
|
-
* ```
|
|
639
|
-
*
|
|
640
|
-
* @example
|
|
641
|
-
* Path-based sidebars:
|
|
642
|
-
* ```ts
|
|
643
|
-
* const sidebar: SidebarType = {
|
|
644
|
-
* "/guide/": [
|
|
645
|
-
* { text: "Introduction", link: "/guide/introduction" }
|
|
646
|
-
* ],
|
|
647
|
-
* "/api/": [
|
|
648
|
-
* { text: "API Reference", link: "/api/" }
|
|
649
|
-
* ]
|
|
650
|
-
* };
|
|
651
|
-
* ```
|
|
652
|
-
*
|
|
653
|
-
* @see SidebarItemType
|
|
654
|
-
* @see PathSidebarInterface
|
|
655
|
-
*
|
|
656
|
-
* @since 2.0.0
|
|
657
|
-
*/
|
|
658
|
-
export type SidebarType = Array<SidebarItemType> | PathSidebarInterface;
|
|
659
|
-
/**
|
|
660
|
-
* Represents a mapping of paths to sidebar item arrays.
|
|
661
|
-
*
|
|
662
|
-
* @remarks
|
|
663
|
-
* This structure allows defining sidebars on a per-path basis,
|
|
664
|
-
* where each key is a route prefix (e.g., `"/guide/"`) and its value
|
|
665
|
-
* is an array of {@link SidebarItemType}.
|
|
666
|
-
*
|
|
667
|
-
* @example
|
|
668
|
-
* ```ts
|
|
669
|
-
* const sidebars: SidebarObjectType = {
|
|
670
|
-
* "/guide/": [
|
|
671
|
-
* { text: "Introduction", link: "/guide/introduction" },
|
|
672
|
-
* { text: "Setup", link: "/guide/setup" }
|
|
673
|
-
* ],
|
|
674
|
-
* "/api/": [
|
|
675
|
-
* { text: "API Reference", link: "/api/" }
|
|
676
|
-
* ]
|
|
677
|
-
* };
|
|
678
|
-
* ```
|
|
679
|
-
*
|
|
680
|
-
* @see SidebarItemType
|
|
681
|
-
* @since 2.0.0
|
|
682
|
-
*/
|
|
683
|
-
export type SidebarObjectType = Record<string, Array<SidebarItemType | SidebarGroupInterface>>;
|
|
684
|
-
|
|
685
|
-
/**
|
|
686
|
-
* Import will remove at compile time
|
|
687
|
-
*/
|
|
688
|
-
/**
|
|
689
|
-
* Represents a locale-specific configuration for a VitePress site.
|
|
503
|
+
* Configuration for documentation versions.
|
|
690
504
|
*
|
|
691
505
|
* @remarks
|
|
692
|
-
*
|
|
693
|
-
*
|
|
694
|
-
* - `
|
|
695
|
-
* - `
|
|
696
|
-
*
|
|
697
|
-
* This interface allows configuring per-locale theme settings, navigation,
|
|
698
|
-
* sidebar, and other locale-specific behavior.
|
|
506
|
+
* - `current` specifies the currently active version.
|
|
507
|
+
* - `sources` is the folder or path where current versioned sources reside.
|
|
508
|
+
* - `archive` is the folder or path for archived versions.
|
|
509
|
+
* - `hooks` allows for custom rewriting logic per version.
|
|
510
|
+
* - `versionSwitcher` enables or disables the version switcher, or provides its configuration.
|
|
699
511
|
*
|
|
700
512
|
* @example
|
|
701
513
|
* ```ts
|
|
702
|
-
* const
|
|
703
|
-
*
|
|
704
|
-
*
|
|
705
|
-
*
|
|
706
|
-
*
|
|
707
|
-
*
|
|
708
|
-
* }
|
|
514
|
+
* const versionsConfig: VersionsConfigInterface = {
|
|
515
|
+
* current: "2.0",
|
|
516
|
+
* sources: "src",
|
|
517
|
+
* archive: "archive",
|
|
518
|
+
* hooks: {
|
|
519
|
+
* rewritesHook: (source, version) => `/v${version}/${source}`
|
|
520
|
+
* },
|
|
521
|
+
* versionSwitcher: { text: "Version", includeCurrentVersion: true }
|
|
709
522
|
* };
|
|
710
523
|
* ```
|
|
711
524
|
*
|
|
712
525
|
* @since 2.0.0
|
|
713
526
|
*/
|
|
714
|
-
|
|
527
|
+
interface VersionsConfigInterface {
|
|
715
528
|
/**
|
|
716
|
-
* The
|
|
717
|
-
*
|
|
718
|
-
* @default undefined
|
|
719
|
-
* @since 2.0.0
|
|
720
|
-
*/
|
|
721
|
-
link?: string;
|
|
722
|
-
/**
|
|
723
|
-
* A human-readable label for the locale.
|
|
724
|
-
*
|
|
725
|
-
* @default undefined
|
|
726
|
-
* @since 2.0.0
|
|
727
|
-
*/
|
|
728
|
-
label?: string;
|
|
729
|
-
}
|
|
730
|
-
/**
|
|
731
|
-
* Represents a mapping of locale codes to their corresponding locale configurations.
|
|
732
|
-
*
|
|
733
|
-
* @remarks
|
|
734
|
-
* The keys are locale codes (e.g., `"en"`, `"de"`), and the values are `LocaleInterface` objects.
|
|
735
|
-
* Useful for multi-language or localized documentation setups in VitePress.
|
|
736
|
-
*
|
|
737
|
-
* @example
|
|
738
|
-
* ```ts
|
|
739
|
-
* const locales: LocalesInterface = {
|
|
740
|
-
* en: { link: "/en/", label: "English" },
|
|
741
|
-
* de: { link: "/de/", label: "Deutsch" }
|
|
742
|
-
* };
|
|
743
|
-
* ```
|
|
744
|
-
*
|
|
745
|
-
* @see LocaleInterface
|
|
746
|
-
* @since 2.0.0
|
|
747
|
-
*/
|
|
748
|
-
export interface LocalesInterface {
|
|
749
|
-
[key: string]: LocaleInterface;
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
/**
|
|
753
|
-
* A generic type representing a function with any arguments and any return type.
|
|
754
|
-
*
|
|
755
|
-
* @remarks
|
|
756
|
-
* This type is a very flexible function type, allowing any arguments of any type
|
|
757
|
-
* and returning any type. Use with caution, as it bypasses TypeScript's type safety.
|
|
758
|
-
*
|
|
759
|
-
* @example
|
|
760
|
-
* ```ts
|
|
761
|
-
* const exampleFn: FunctionType = (a, b, c) => a + b + c;
|
|
762
|
-
*
|
|
763
|
-
* const anotherFn: FunctionType = (...args) => args.length;
|
|
764
|
-
* ```
|
|
765
|
-
*
|
|
766
|
-
* @since 2.0.0
|
|
767
|
-
*/
|
|
768
|
-
type FunctionType = (...args: Array<any>) => any;
|
|
769
|
-
/**
|
|
770
|
-
* Represents a generic constructor type.
|
|
771
|
-
*
|
|
772
|
-
* @remarks
|
|
773
|
-
* This utility type describes a class constructor that accepts any number of arguments
|
|
774
|
-
* and returns any instance type. Useful for mixins or generic factory functions.
|
|
775
|
-
*
|
|
776
|
-
* @example
|
|
777
|
-
* ```ts
|
|
778
|
-
* function WithTimestamp<TBase extends ConstructorType>(Base: TBase) {
|
|
779
|
-
* return class extends Base {
|
|
780
|
-
* timestamp = Date.now();
|
|
781
|
-
* };
|
|
782
|
-
* }
|
|
783
|
-
* ```
|
|
784
|
-
*
|
|
785
|
-
* @since 2.0.0
|
|
786
|
-
*/
|
|
787
|
-
type ConstructorType = new (...args: Array<any>) => any;
|
|
788
|
-
/**
|
|
789
|
-
* A type representing a function with a specific return type, arguments, and optional context.
|
|
790
|
-
*
|
|
791
|
-
* @typeParam Return - The type returned by the function. Defaults to `unknown`.
|
|
792
|
-
* @typeParam Args - A tuple of argument types for the function. Defaults to an empty array `[]`.
|
|
793
|
-
* @typeParam Context - The type of `this` context for the function. Defaults to `unknown`.
|
|
794
|
-
*
|
|
795
|
-
* @remarks
|
|
796
|
-
* This type allows you to strongly type functions with a specific `this` context and arguments.
|
|
797
|
-
*
|
|
798
|
-
* @example
|
|
799
|
-
* ```ts
|
|
800
|
-
* const fn: FunctionLikeType<number, [string, string], { prefix: string }> = function(this, a, b) {
|
|
801
|
-
* return (this.prefix + a + b).length;
|
|
802
|
-
* }
|
|
803
|
-
* ```
|
|
804
|
-
*
|
|
805
|
-
* @since 2.0.0
|
|
806
|
-
*/
|
|
807
|
-
type FunctionLikeType<Return = unknown, Args extends Array<unknown> = [], Context = unknown> = (this: Context, ...args: Args) => Return;
|
|
808
|
-
/**
|
|
809
|
-
* A type representing a constructor with specific arguments and return type.
|
|
810
|
-
*
|
|
811
|
-
* @typeParam Return - The instance type returned by the constructor. Defaults to `unknown`.
|
|
812
|
-
* @typeParam Args - A tuple of argument types for the constructor. Defaults to an empty array `[]`.
|
|
813
|
-
*
|
|
814
|
-
* @remarks
|
|
815
|
-
* This type allows strong typing of class constructors with defined argument types.
|
|
816
|
-
*
|
|
817
|
-
* @example
|
|
818
|
-
* ```ts
|
|
819
|
-
* class MyClass {
|
|
820
|
-
* constructor(public name: string) {}
|
|
821
|
-
* }
|
|
822
|
-
*
|
|
823
|
-
* const ctor: ConstructorLikeType<MyClass, [string]> = MyClass;
|
|
824
|
-
* const instance = new ctor("Hello");
|
|
825
|
-
* ```
|
|
826
|
-
*
|
|
827
|
-
* @since 2.0.0
|
|
828
|
-
*/
|
|
829
|
-
type ConstructorLikeType<Return = unknown, Args extends Array<unknown> = []> = new (...args: Args) => Return;
|
|
830
|
-
/**
|
|
831
|
-
* Recursively makes all properties of a type optional.
|
|
832
|
-
*
|
|
833
|
-
* @typeParam T - The type to transform into a deeply partial type.
|
|
834
|
-
*
|
|
835
|
-
* @remarks
|
|
836
|
-
* This type is similar to TypeScript's built-in `Partial<T>`, but it applies recursively
|
|
837
|
-
* to all nested objects. Arrays and other non-object types are left unchanged.
|
|
838
|
-
*
|
|
839
|
-
* Use `DeepPartialType` when you need to work with objects where only some properties,
|
|
840
|
-
* including nested properties, may be provided.
|
|
841
|
-
*
|
|
842
|
-
* @example
|
|
843
|
-
* ```ts
|
|
844
|
-
* interface User {
|
|
845
|
-
* name: string;
|
|
846
|
-
* address: {
|
|
847
|
-
* street: string;
|
|
848
|
-
* city: string;
|
|
849
|
-
* };
|
|
850
|
-
* }
|
|
851
|
-
*
|
|
852
|
-
* const partialUser: DeepPartialType<User> = {
|
|
853
|
-
* name: "Alice",
|
|
854
|
-
* address: { city: "Wonderland" }
|
|
855
|
-
* };
|
|
856
|
-
* ```
|
|
857
|
-
*
|
|
858
|
-
* @since 2.0.0
|
|
859
|
-
*/
|
|
860
|
-
type DeepPartialType<T> = T extends object ? {
|
|
861
|
-
[P in keyof T]?: DeepPartialType<T[P]>;
|
|
862
|
-
} : T;
|
|
863
|
-
/**
|
|
864
|
-
* Makes specific keys of a type required while leaving the rest unchanged.
|
|
865
|
-
*
|
|
866
|
-
* @typeParam T - The base type.
|
|
867
|
-
* @typeParam K - The subset of keys from `T` that should be required.
|
|
868
|
-
*
|
|
869
|
-
* @remarks
|
|
870
|
-
* This utility type is useful when you want to enforce that certain properties
|
|
871
|
-
* of a type are mandatory, without affecting the optionality of other properties.
|
|
872
|
-
* It works by combining:
|
|
873
|
-
* - `Omit<T, K>` to remove the keys that will become required.
|
|
874
|
-
* - `Required<Pick<T, K>>` to mark the specified keys as required.
|
|
875
|
-
*
|
|
876
|
-
* @example
|
|
877
|
-
* ```ts
|
|
878
|
-
* interface User {
|
|
879
|
-
* id?: number;
|
|
880
|
-
* name?: string;
|
|
881
|
-
* email?: string;
|
|
882
|
-
* }
|
|
883
|
-
*
|
|
884
|
-
* // Make 'id' and 'name' required, 'email' remains optional
|
|
885
|
-
* type UserWithRequiredIdName = RequireKeysType<User, 'id' | 'name'>;
|
|
886
|
-
*
|
|
887
|
-
* const user: UserWithRequiredIdName = {
|
|
888
|
-
* id: 1,
|
|
889
|
-
* name: "Alice"
|
|
890
|
-
* };
|
|
891
|
-
* ```
|
|
892
|
-
*
|
|
893
|
-
* @since 2.0.0
|
|
894
|
-
*/
|
|
895
|
-
type RequireKeysType<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
896
|
-
|
|
897
|
-
/**
|
|
898
|
-
* Import will remove at compile time
|
|
899
|
-
*/
|
|
900
|
-
/**
|
|
901
|
-
* Manages the state of a versioned VitePress documentation project.
|
|
902
|
-
*
|
|
903
|
-
* @remarks
|
|
904
|
-
* The `StateModel` class is responsible for:
|
|
905
|
-
* - Managing source and archive directories for versioned documentation.
|
|
906
|
-
* - Initializing the VitePress configuration (`VitepressConfigInterface`) from
|
|
907
|
-
* a provided {@link ConfigurationInterface}.
|
|
908
|
-
* - Maintaining a list of documentation versions and a map of Markdown files per version.
|
|
909
|
-
* - Ensuring the necessary directories exist and are initialized.
|
|
910
|
-
*
|
|
911
|
-
* This service is designed as a singleton, making it safe to inject across
|
|
912
|
-
* your application using `@Injectable({ scope: 'singleton' })`.
|
|
913
|
-
*
|
|
914
|
-
* @example
|
|
915
|
-
* ```ts
|
|
916
|
-
* import { StateModel } from "@models/state.model";
|
|
917
|
-
*
|
|
918
|
-
* const state = new StateModel(config).init();
|
|
919
|
-
* console.log(state.versionsList);
|
|
920
|
-
* ```
|
|
921
|
-
*
|
|
922
|
-
* @since 2.0.0
|
|
923
|
-
*/
|
|
924
|
-
declare class StateModel {
|
|
925
|
-
readonly configuration: ConfigurationInterface;
|
|
926
|
-
/**
|
|
927
|
-
* The root path of the documentation project,
|
|
928
|
-
* based on the current working directory and optional srcDir.
|
|
929
|
-
*
|
|
930
|
-
* @since 2.0.0
|
|
931
|
-
*/
|
|
932
|
-
readonly root: string;
|
|
933
|
-
/**
|
|
934
|
-
* The name of the sources directory from which current content.
|
|
935
|
-
*
|
|
936
|
-
* @default `src`
|
|
937
|
-
* @since 2.0.0
|
|
938
|
-
*/
|
|
939
|
-
readonly sources: string;
|
|
940
|
-
/**
|
|
941
|
-
* The name of the archive directory where old versions are stored.
|
|
942
|
-
*
|
|
943
|
-
* @default `archive`
|
|
944
|
-
* @since 2.0.0
|
|
945
|
-
*/
|
|
946
|
-
readonly archive: string;
|
|
947
|
-
/**
|
|
948
|
-
* Full path to the `sources` directory.
|
|
949
|
-
*
|
|
950
|
-
* @since 2.0.0
|
|
951
|
-
*/
|
|
952
|
-
readonly sourcesPath: string;
|
|
953
|
-
/**
|
|
954
|
-
* Full path to the `archive` directory.
|
|
955
|
-
*
|
|
956
|
-
* @since 2.0.0
|
|
957
|
-
*/
|
|
958
|
-
readonly archivePath: string;
|
|
959
|
-
/**
|
|
960
|
-
* The `versions` configuration object for the plugin.
|
|
529
|
+
* The currently active documentation version.
|
|
961
530
|
*
|
|
962
531
|
* @remarks
|
|
963
|
-
*
|
|
964
|
-
*
|
|
965
|
-
* like the current version, sources, archive, hooks, and version switcher.
|
|
966
|
-
*
|
|
967
|
-
* @see VersionsConfigInterface
|
|
968
|
-
* @since 2.0.0
|
|
969
|
-
*/
|
|
970
|
-
readonly versionsConfig: VersionsConfigInterface;
|
|
971
|
-
/**
|
|
972
|
-
* The VitePress configuration object crafted from the user-provided configuration,
|
|
973
|
-
* with versioning support added.
|
|
974
|
-
*
|
|
975
|
-
* @remarks
|
|
976
|
-
* This object is based on the user configuration and extended to include
|
|
977
|
-
* locales, rewrites, and versioning-aware settings. It is typed as
|
|
978
|
-
* {@link VitepressConfigInterface}.
|
|
532
|
+
* Used to determine which version to serve by default and which version
|
|
533
|
+
* should be highlighted in the version switcher.
|
|
979
534
|
*
|
|
980
|
-
* @see VitepressConfigInterface
|
|
981
535
|
* @since 2.0.0
|
|
982
536
|
*/
|
|
983
|
-
|
|
537
|
+
current: string;
|
|
984
538
|
/**
|
|
985
|
-
*
|
|
986
|
-
*
|
|
987
|
-
* @remarks
|
|
988
|
-
* This array is populated during initialization (`init()`) by reading the archive
|
|
989
|
-
* and sources directories. Each element is a version string (e.g., `"1.0"`, `"2.0"`).
|
|
539
|
+
* The folder or path where the current versioned sources reside.
|
|
990
540
|
*
|
|
991
541
|
* @since 2.0.0
|
|
992
542
|
*/
|
|
993
|
-
|
|
543
|
+
sources: string;
|
|
994
544
|
/**
|
|
995
|
-
*
|
|
996
|
-
*
|
|
997
|
-
* @remarks
|
|
998
|
-
* - Keys are the locale identifiers as defined in the user configuration
|
|
999
|
-
* (e.g., `"de"`, `"root"`).
|
|
1000
|
-
* - Values are the corresponding effective base paths or link prefixes
|
|
1001
|
-
* used inside the generated VitePress config.
|
|
1002
|
-
* - The `"root"` locale always maps to the default language of the site.
|
|
1003
|
-
*
|
|
1004
|
-
* This mapping is used internally to resolve and normalize locale-based
|
|
1005
|
-
* routing for both source files and versioned archives.
|
|
1006
|
-
*
|
|
1007
|
-
* @example
|
|
1008
|
-
* ```ts
|
|
1009
|
-
* localesMap = {
|
|
1010
|
-
* en: "root",
|
|
1011
|
-
* de: "de"
|
|
1012
|
-
* };
|
|
1013
|
-
* ```
|
|
545
|
+
* The folder or path where archived versions are stored.
|
|
1014
546
|
*
|
|
1015
547
|
* @since 2.0.0
|
|
1016
548
|
*/
|
|
1017
|
-
|
|
549
|
+
archive: string;
|
|
1018
550
|
/**
|
|
1019
|
-
*
|
|
1020
|
-
*
|
|
1021
|
-
* @param configuration - Optional configuration object; defaults to {@link defaultConfiguration}.
|
|
1022
|
-
*
|
|
1023
|
-
* @throws Will throw an error if the sources directory does not exist.
|
|
551
|
+
* Hooks for custom behavior when working with versioned content.
|
|
1024
552
|
*
|
|
1025
553
|
* @remarks
|
|
1026
|
-
*
|
|
1027
|
-
*
|
|
1028
|
-
* - Constructing full paths for `root`, `sourcesPath`, and `archivePath`.
|
|
1029
|
-
* - Validating that the sources directory exists.
|
|
1030
|
-
* - Ensuring the archive directory exists and creating a `.gitkeep` file if necessary.
|
|
1031
|
-
* - Creating a VitePress configuration object with versioning support.
|
|
554
|
+
* Currently, supports `rewritesHook`, which can programmatically rewrite
|
|
555
|
+
* paths based on version and locale.
|
|
1032
556
|
*
|
|
557
|
+
* @see VersionsHooksInterface
|
|
1033
558
|
* @since 2.0.0
|
|
1034
559
|
*/
|
|
1035
|
-
|
|
560
|
+
hooks: VersionsHooksInterface;
|
|
1036
561
|
/**
|
|
1037
|
-
*
|
|
1038
|
-
*
|
|
1039
|
-
* @returns The current instance for method chaining.
|
|
562
|
+
* Configuration for the version switcher or `false` to disable it.
|
|
1040
563
|
*
|
|
1041
564
|
* @remarks
|
|
1042
|
-
*
|
|
1043
|
-
*
|
|
1044
|
-
* three primary operations:
|
|
1045
|
-
*
|
|
1046
|
-
* 1. **Root Locale Initialization**: Sets up the root locale entry in {@link vitepressConfig.locales}
|
|
1047
|
-
* with an empty theme configuration, establishing the foundation for all locale-specific settings
|
|
1048
|
-
* 2. **Version Discovery**: Scans {@link archivePath} using {@link readdirSync} to identify all
|
|
1049
|
-
* subdirectories, which represent available documentation versions. Each subdirectory name
|
|
1050
|
-
* is added to {@link versionsList}
|
|
1051
|
-
* 3. **Locale Map Setup**: Calls {@link initializeLocalesMap} to establish the locale mapping
|
|
1052
|
-
* structure and populate versioned locale entries
|
|
1053
|
-
*
|
|
1054
|
-
* The archive directory structure is expected to contain version folders:
|
|
1055
|
-
* ```
|
|
1056
|
-
* archive/
|
|
1057
|
-
* ├── v1.0/
|
|
1058
|
-
* ├── v2.0/
|
|
1059
|
-
* └── latest/
|
|
1060
|
-
* ```
|
|
1061
|
-
*
|
|
1062
|
-
* Each subdirectory discovered becomes a version entry, enabling the system to generate
|
|
1063
|
-
* versioned locale configurations and routing structures for multi-version documentation.
|
|
1064
|
-
*
|
|
1065
|
-
* The root locale is initialized first to ensure a consistent base exists before user-defined
|
|
1066
|
-
* locale configurations are applied through {@link initializeLocalesMap}.
|
|
1067
|
-
*
|
|
1068
|
-
* Method chaining support allows for fluent initialization patterns, making it easy to
|
|
1069
|
-
* combine multiple setup operations in a readable sequence.
|
|
1070
|
-
*
|
|
1071
|
-
* @example
|
|
1072
|
-
* ```ts
|
|
1073
|
-
* // Basic initialization
|
|
1074
|
-
* const state = new StateModel(config);
|
|
1075
|
-
* state.init();
|
|
1076
|
-
*
|
|
1077
|
-
* console.log(state.versionsList);
|
|
1078
|
-
* // ['v1.0', 'v2.0', 'v3.0', 'latest']
|
|
1079
|
-
*
|
|
1080
|
-
* console.log(state.vitepressConfig.locales['root']);
|
|
1081
|
-
* // { themeConfig: {} }
|
|
1082
|
-
*
|
|
1083
|
-
* // Method chaining pattern
|
|
1084
|
-
* const state = new StateModel(config)
|
|
1085
|
-
* .init();
|
|
1086
|
-
*
|
|
1087
|
-
* console.log(`Initialized with ${state.versionsList.length} versions`);
|
|
1088
|
-
*
|
|
1089
|
-
* // Use case: Dynamic version detection
|
|
1090
|
-
* const config = {
|
|
1091
|
-
* versionsConfig: {
|
|
1092
|
-
* sources: 'src',
|
|
1093
|
-
* archive: 'versions'
|
|
1094
|
-
* },
|
|
1095
|
-
* locales: {
|
|
1096
|
-
* root: { lang: 'en-US', label: 'English' },
|
|
1097
|
-
* '/de/': { lang: 'de-DE', label: 'Deutsch' }
|
|
1098
|
-
* }
|
|
1099
|
-
* };
|
|
1100
|
-
*
|
|
1101
|
-
* const state = new StateModel(config).init();
|
|
1102
|
-
*
|
|
1103
|
-
* // Archive structure:
|
|
1104
|
-
* // versions/
|
|
1105
|
-
* // ├── v1.0.0/
|
|
1106
|
-
* // ├── v2.0.0/
|
|
1107
|
-
* // └── latest/
|
|
1108
|
-
*
|
|
1109
|
-
* console.log(state.versionsList);
|
|
1110
|
-
* // ['v1.0.0', 'v2.0.0']
|
|
1111
|
-
*
|
|
1112
|
-
* // Locale entries created for each version
|
|
1113
|
-
* console.log(Object.keys(state.vitepressConfig.locales));
|
|
1114
|
-
* // ['root', 'v1.0.0', 'v2.0.0', 'latest', '/de/', 'de/v1.0.0', 'de/v2.0.0']
|
|
1115
|
-
*
|
|
1116
|
-
* // Use case: Error handling
|
|
1117
|
-
* try {
|
|
1118
|
-
* const state = new StateModel(config).init();
|
|
1119
|
-
* if (state.versionsList.length === 0) {
|
|
1120
|
-
* console.warn('No versions found in archive');
|
|
1121
|
-
* }
|
|
1122
|
-
* } catch (error) {
|
|
1123
|
-
* console.error('Failed to initialize state:', error);
|
|
1124
|
-
* }
|
|
1125
|
-
* ```
|
|
1126
|
-
*
|
|
1127
|
-
* @see archivePath
|
|
1128
|
-
* @see readdirSync
|
|
1129
|
-
* @see versionsList
|
|
1130
|
-
* @see vitepressConfig
|
|
1131
|
-
* @see initializeLocalesMap
|
|
565
|
+
* If enabled, this object defines the switcher text and whether the
|
|
566
|
+
* current version is included in the switcher options.
|
|
1132
567
|
*
|
|
1133
|
-
* @
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
* of locales to their links for all versions.
|
|
1139
|
-
*
|
|
1140
|
-
* @remarks
|
|
1141
|
-
* - Adds a `root` locale entry.
|
|
1142
|
-
* - Copies all user-defined locales into the VitePress config.
|
|
1143
|
-
* - Populates `localesMap` with locale keys and their corresponding links (or folder names).
|
|
1144
|
-
* - Ensures that for each documentation version, a locale entry exists in the VitePress config.
|
|
1145
|
-
* - Handles both root and non-root locales, creating versioned paths automatically.
|
|
1146
|
-
*
|
|
1147
|
-
* @since 2.0.0
|
|
1148
|
-
*/
|
|
1149
|
-
private initializeLocalesMap;
|
|
1150
|
-
/**
|
|
1151
|
-
* Ensures that the archive directory exists.
|
|
1152
|
-
*
|
|
1153
|
-
* @param path - The path to the archive directory.
|
|
1154
|
-
*
|
|
1155
|
-
* @remarks
|
|
1156
|
-
* - If the directory does not exist, it is created.
|
|
1157
|
-
* - A `.gitkeep` file is also added to ensure the directory is tracked by Git.
|
|
1158
|
-
*
|
|
1159
|
-
* @since 2.0.0
|
|
1160
|
-
*/
|
|
1161
|
-
private makeArchiveDirectory;
|
|
1162
|
-
/**
|
|
1163
|
-
* Creates a VitePress configuration object from the user-provided configuration.
|
|
1164
|
-
*
|
|
1165
|
-
* @returns A `VitepressConfigInterface` object with versioning support added.
|
|
1166
|
-
*
|
|
1167
|
-
* @remarks
|
|
1168
|
-
* - Copies all configuration properties except for `locales`, `rewrites`, `themeConfig`, and `versionsConfig`.
|
|
1169
|
-
* - Initializes excluded properties (except `versionsConfig`) with empty objects.
|
|
1170
|
-
* - Returns a configuration object typed as {@link VitepressConfigInterface}, ready for VitePress usage.
|
|
1171
|
-
*
|
|
1172
|
-
* @see VitepressConfigInterface
|
|
1173
|
-
* @since 2.0.0
|
|
1174
|
-
*/
|
|
1175
|
-
private createVitepressConfig;
|
|
1176
|
-
}
|
|
1177
|
-
|
|
1178
|
-
/**
|
|
1179
|
-
* Import will remove at compile time
|
|
1180
|
-
*/
|
|
1181
|
-
/**
|
|
1182
|
-
* Extracts the language code from a locale string.
|
|
1183
|
-
*
|
|
1184
|
-
* @param locale - The locale string to parse (e.g., 'en-US', 'fr_CA', 'zh-Hans-CN').
|
|
1185
|
-
* @returns The language code portion of the locale (e.g., 'en', 'fr', 'zh').
|
|
1186
|
-
*
|
|
1187
|
-
* @remarks
|
|
1188
|
-
* This function parses a locale string and returns only the primary language code,
|
|
1189
|
-
* discarding region, script, and variant information. It handles both standard
|
|
1190
|
-
* separators used in locale strings:
|
|
1191
|
-
* - Hyphen (`-`): BCP 47 standard (e.g., 'en-US', 'zh-Hans-CN')
|
|
1192
|
-
* - Underscore (`_`): POSIX/Java standard (e.g., 'en_US', 'pt_BR')
|
|
1193
|
-
*
|
|
1194
|
-
* The language code is always the first component of a locale identifier and
|
|
1195
|
-
* represents the base language without regional or script variations.
|
|
1196
|
-
*
|
|
1197
|
-
* Common use cases:
|
|
1198
|
-
* - Fallback language selection when a specific locale is unavailable
|
|
1199
|
-
* - Grouping locales by language family
|
|
1200
|
-
* - Simplifying locale matching for translations
|
|
1201
|
-
* - Language detection without regional specificity
|
|
1202
|
-
* - API requests that only accept language codes
|
|
1203
|
-
*
|
|
1204
|
-
* Locale format examples:
|
|
1205
|
-
* - Language only: 'en', 'fr', 'ja'
|
|
1206
|
-
* - Language + Region: 'en-US', 'fr-CA', 'pt-BR'
|
|
1207
|
-
* - Language + Script + Region: 'zh-Hans-CN', 'zh-Hant-TW'
|
|
1208
|
-
* - POSIX format: 'en_US', 'de_DE', 'es_MX'
|
|
1209
|
-
*
|
|
1210
|
-
* @example
|
|
1211
|
-
* ```ts
|
|
1212
|
-
* // BCP 47 format with region
|
|
1213
|
-
* console.log(getLanguageOnly('en-US')); // 'en'
|
|
1214
|
-
* console.log(getLanguageOnly('fr-CA')); // 'fr'
|
|
1215
|
-
* console.log(getLanguageOnly('pt-BR')); // 'pt'
|
|
1216
|
-
*
|
|
1217
|
-
* // POSIX format with underscore
|
|
1218
|
-
* console.log(getLanguageOnly('en_GB')); // 'en'
|
|
1219
|
-
* console.log(getLanguageOnly('de_DE')); // 'de'
|
|
1220
|
-
*
|
|
1221
|
-
* // Complex locale with script
|
|
1222
|
-
* console.log(getLanguageOnly('zh-Hans-CN')); // 'zh'
|
|
1223
|
-
* console.log(getLanguageOnly('zh-Hant-TW')); // 'zh'
|
|
1224
|
-
*
|
|
1225
|
-
* // Language code only (no separator)
|
|
1226
|
-
* console.log(getLanguageOnly('ja')); // 'ja'
|
|
1227
|
-
* console.log(getLanguageOnly('ko')); // 'ko'
|
|
1228
|
-
*
|
|
1229
|
-
* // Use case: Fallback language selection
|
|
1230
|
-
* const userLocale = 'es-MX';
|
|
1231
|
-
* const language = getLanguageOnly(userLocale); // 'es'
|
|
1232
|
-
* const translations = loadTranslations(language); // Load Spanish translations
|
|
1233
|
-
* ```
|
|
1234
|
-
*
|
|
1235
|
-
* @since 2.0.5
|
|
1236
|
-
*/
|
|
1237
|
-
declare function getLanguageOnly(locale: string): string;
|
|
1238
|
-
/**
|
|
1239
|
-
* Parses and configures locale settings for a multi-version, multi-language documentation site.
|
|
1240
|
-
*
|
|
1241
|
-
* @remarks
|
|
1242
|
-
* This function orchestrates the complete locale configuration process by combining
|
|
1243
|
-
* user-defined locale settings with version information to generate a comprehensive
|
|
1244
|
-
* locale map. It handles both root and non-root locales across multiple documentation
|
|
1245
|
-
* versions.
|
|
1246
|
-
*
|
|
1247
|
-
* The function operates on injected state from {@link StateModel} and processes:
|
|
1248
|
-
* - {@link versionsList}: Available documentation versions (e.g., ['v1', 'v2', 'v3'])
|
|
1249
|
-
* - {@link vitepressConfig}: VitePress configuration containing locale definitions
|
|
1250
|
-
* - {@link configuration}: User-provided locale configurations
|
|
1251
|
-
* - {@link localesMap}: Mapping between locale keys and indices
|
|
1252
|
-
*
|
|
1253
|
-
* Processing workflow:
|
|
1254
|
-
* 1. Injects application state to access configuration data
|
|
1255
|
-
* 2. Determines if 'root' key exists in user-provided locales
|
|
1256
|
-
* 3. Iterates through each locale in the locale map
|
|
1257
|
-
* 4. Creates sanitized base locale using {@link createSanitizedLocale} (removes nav/sidebar)
|
|
1258
|
-
* 5. Sets up the root locale entry with a generated link via {@link generateLocaleLink}
|
|
1259
|
-
* 6. Creates versioned locale entries for each version using {@link createVersionedLocale}
|
|
1260
|
-
*
|
|
1261
|
-
* Locale key structure:
|
|
1262
|
-
* - Root locale: Direct version keys (e.g., 'v1', 'v2')
|
|
1263
|
-
* - Non-root locales: Prefixed version keys (e.g., 'fr/v1', 'es/v2')
|
|
1264
|
-
*
|
|
1265
|
-
* The sanitization process removes navigation structures to reduce memory overhead
|
|
1266
|
-
* and prevent duplication of large theme configuration objects across versions.
|
|
1267
|
-
*
|
|
1268
|
-
* @example
|
|
1269
|
-
* ```ts
|
|
1270
|
-
* // Configuration state before parsing
|
|
1271
|
-
* const state = {
|
|
1272
|
-
* versionsList: ['v1', 'v2'],
|
|
1273
|
-
* localesMap: {
|
|
1274
|
-
* '/': 'root',
|
|
1275
|
-
* '/fr/': 'fr',
|
|
1276
|
-
* '/es/': 'es'
|
|
1277
|
-
* },
|
|
1278
|
-
* configuration: {
|
|
1279
|
-
* locales: {
|
|
1280
|
-
* root: {
|
|
1281
|
-
* lang: 'en-US',
|
|
1282
|
-
* label: 'English',
|
|
1283
|
-
* themeConfig: { nav: [...], sidebar: {...} }
|
|
1284
|
-
* },
|
|
1285
|
-
* fr: {
|
|
1286
|
-
* lang: 'fr-CA',
|
|
1287
|
-
* label: 'Français',
|
|
1288
|
-
* themeConfig: { nav: [...], sidebar: {...} }
|
|
1289
|
-
* }
|
|
1290
|
-
* }
|
|
1291
|
-
* }
|
|
1292
|
-
* };
|
|
1293
|
-
*
|
|
1294
|
-
* parseLocale();
|
|
1295
|
-
*
|
|
1296
|
-
* // Result in vitepressConfig.locales:
|
|
1297
|
-
* // {
|
|
1298
|
-
* // 'root': { lang: 'en-US', label: 'English', link: '/', ... },
|
|
1299
|
-
* // 'v1': { lang: 'en-US', label: ' ', link: '/', ... },
|
|
1300
|
-
* // 'v2': { lang: 'en-US', label: ' ', link: '/', ... },
|
|
1301
|
-
* // 'fr': { lang: 'fr-CA', label: 'Français', link: '/fr/', ... },
|
|
1302
|
-
* // 'fr/v1': { lang: 'fr-CA', label: ' ', link: '/fr/', ... },
|
|
1303
|
-
* // 'fr/v2': { lang: 'fr-CA', label: ' ', link: '/fr/', ... }
|
|
1304
|
-
* // }
|
|
1305
|
-
*
|
|
1306
|
-
* // Use case: Multi-version documentation with multiple languages
|
|
1307
|
-
* const state = inject(StateModel);
|
|
1308
|
-
* state.versionsList = ['latest', 'v3', 'v2'];
|
|
1309
|
-
* state.configuration.locales = {
|
|
1310
|
-
* '/': { lang: 'en-US', label: 'English' },
|
|
1311
|
-
* '/de/': { lang: 'de-DE', label: 'Deutsch' },
|
|
1312
|
-
* '/ja/': { lang: 'ja-JP', label: '日本語' }
|
|
1313
|
-
* };
|
|
1314
|
-
*
|
|
1315
|
-
* parseLocale();
|
|
1316
|
-
* // Generates 12 locale entries (3 versions × 3 languages + 3 base locales)
|
|
1317
|
-
* ```
|
|
1318
|
-
*
|
|
1319
|
-
* @see StateModel
|
|
1320
|
-
* @see generateLocaleLink
|
|
1321
|
-
* @see createSanitizedLocale
|
|
1322
|
-
* @see createVersionedLocale
|
|
1323
|
-
*
|
|
1324
|
-
* @since 2.0.5
|
|
1325
|
-
*/
|
|
1326
|
-
declare function parseLocale(): void;
|
|
1327
|
-
|
|
1328
|
-
/**
|
|
1329
|
-
* Import will remove at compile time
|
|
1330
|
-
*/
|
|
1331
|
-
/**
|
|
1332
|
-
* A collection of singleton instances for injectable classes.
|
|
1333
|
-
*
|
|
1334
|
-
* @remarks
|
|
1335
|
-
* This map stores instances of classes marked as `singleton` in `@Injectable` metadata.
|
|
1336
|
-
* It ensures that only one instance exists for the lifetime of the application.
|
|
1337
|
-
*
|
|
1338
|
-
* @see ConstructorType
|
|
1339
|
-
* @since 2.0.0
|
|
1340
|
-
*/
|
|
1341
|
-
declare const SINGLETONS: Map<ConstructorType, unknown>;
|
|
1342
|
-
/**
|
|
1343
|
-
* Stores metadata for all classes marked with the `@Injectable` decorator.
|
|
1344
|
-
*
|
|
1345
|
-
* @remarks
|
|
1346
|
-
* The metadata includes scope, factory function, and provider dependencies.
|
|
1347
|
-
*
|
|
1348
|
-
* @see Injectable
|
|
1349
|
-
* @since 2.0.0
|
|
1350
|
-
*/
|
|
1351
|
-
declare const INJECTABLES: Map<ConstructorType, InjectableOptionsInterface<ConstructorType>>;
|
|
1352
|
-
/**
|
|
1353
|
-
* Type guard to check if a provider uses a class.
|
|
1354
|
-
*
|
|
1355
|
-
* @param provider - The provider to check.
|
|
1356
|
-
* @returns True if the provider is a {@link ProviderUseClassInterface}.
|
|
1357
|
-
*
|
|
1358
|
-
* @see ProviderUseClassInterface
|
|
1359
|
-
* @since 2.0.0
|
|
1360
|
-
*/
|
|
1361
|
-
declare function isProviderUseClass(provider: unknown): provider is ProviderUseClassInterface;
|
|
1362
|
-
/**
|
|
1363
|
-
* Type guard to check if a provider uses a factory function.
|
|
1364
|
-
*
|
|
1365
|
-
* @param provider - The provider to check.
|
|
1366
|
-
* @returns True if the provider is a {@link ProviderUseFactoryInterface}.
|
|
1367
|
-
*
|
|
1368
|
-
* @see ProviderUseFactoryInterface
|
|
1369
|
-
* @since 2.0.0
|
|
1370
|
-
*/
|
|
1371
|
-
declare function isProviderUseFactory(provider: unknown): provider is ProviderUseFactoryInterface;
|
|
1372
|
-
/**
|
|
1373
|
-
* Type guard to check if a provider uses a value.
|
|
1374
|
-
*
|
|
1375
|
-
* @param provider - The provider to check.
|
|
1376
|
-
* @returns True if the provider is a {@link ProviderUseValueInterface}.
|
|
1377
|
-
*
|
|
1378
|
-
* @see ProviderUseValueInterface
|
|
1379
|
-
* @since 2.0.0
|
|
1380
|
-
*/
|
|
1381
|
-
declare function isProviderUseValue(provider: unknown): provider is ProviderUseValueInterface;
|
|
1382
|
-
/**
|
|
1383
|
-
* Marks a class as injectable, optionally providing metadata.
|
|
1384
|
-
*
|
|
1385
|
-
* @param options - Optional configuration for the injectable class.
|
|
1386
|
-
*
|
|
1387
|
-
* @remarks
|
|
1388
|
-
* The `@Injectable` decorator allows classes to be automatically instantiated
|
|
1389
|
-
* and injected with dependencies using the `inject` function.
|
|
1390
|
-
*
|
|
1391
|
-
* @example
|
|
1392
|
-
* ```ts
|
|
1393
|
-
* @Injectable({ scope: 'singleton' })
|
|
1394
|
-
* class MyService {}
|
|
1395
|
-
*
|
|
1396
|
-
* const instance = inject(MyService);
|
|
1397
|
-
* ```
|
|
1398
|
-
*
|
|
1399
|
-
* @see InjectableOptionsInterface
|
|
1400
|
-
* @since 2.0.0
|
|
1401
|
-
*/
|
|
1402
|
-
declare function Injectable<T extends ConstructorType = ConstructorType>(options?: InjectableOptionsInterface<T>): (target: T) => void;
|
|
1403
|
-
/**
|
|
1404
|
-
* Converts an array of providers into constructor arguments for injection.
|
|
1405
|
-
*
|
|
1406
|
-
* @param providers - An optional array of providers to resolve.
|
|
1407
|
-
* @param args - Optional initial arguments to prepend before resolving providers.
|
|
1408
|
-
* @returns An array of resolved arguments including the results from providers.
|
|
1409
|
-
*
|
|
1410
|
-
* @remarks
|
|
1411
|
-
* This function iterates over the provided `ProvidersType` array and converts each provider
|
|
1412
|
-
* into its resolved value. It supports class providers, factory providers, value providers,
|
|
1413
|
-
* and direct constructor functions. The returned array can be used to construct instances
|
|
1414
|
-
* with dependencies injected in the correct order.
|
|
1415
|
-
*
|
|
1416
|
-
* @example
|
|
1417
|
-
* ```ts
|
|
1418
|
-
* const args = providersIntoArgs([{ useValue: 42 }, { useFactory: () => 'hello' }]);
|
|
1419
|
-
* // args = [42, 'hello']
|
|
1420
|
-
* ```
|
|
1421
|
-
*
|
|
1422
|
-
* @see isProviderUseClass
|
|
1423
|
-
* @see isProviderUseValue
|
|
1424
|
-
* @see isProviderUseFactory
|
|
1425
|
-
*
|
|
1426
|
-
* @since 2.0.0
|
|
1427
|
-
*/
|
|
1428
|
-
declare function providersIntoArgs(providers?: ProvidersType, args?: Array<unknown>): Array<unknown>;
|
|
1429
|
-
/**
|
|
1430
|
-
* Resolves and instantiates a class with its dependencies.
|
|
1431
|
-
*
|
|
1432
|
-
* @param token - The constructor function or class to instantiate.
|
|
1433
|
-
* @param args - Optional arguments to pass to the constructor, which can override
|
|
1434
|
-
* or supplement provider-resolved values.
|
|
1435
|
-
* @returns An instance of the class with all dependencies injected.
|
|
1436
|
-
*
|
|
1437
|
-
* @remarks
|
|
1438
|
-
* The `inject` function looks up metadata for the class marked with `@Injectable`.
|
|
1439
|
-
* It resolves all providers recursively using `providersIntoArgs`. If the class is
|
|
1440
|
-
* marked as a `singleton`, the same instance will be returned on further calls.
|
|
1441
|
-
*
|
|
1442
|
-
* @example
|
|
1443
|
-
* ```ts
|
|
1444
|
-
* @Injectable({ scope: 'singleton' })
|
|
1445
|
-
* class MyService {}
|
|
1446
|
-
*
|
|
1447
|
-
* const instance = inject(MyService);
|
|
1448
|
-
* ```
|
|
1449
|
-
*
|
|
1450
|
-
* @see Injectable
|
|
1451
|
-
* @see providersIntoArgs
|
|
1452
|
-
*
|
|
1453
|
-
* @since 2.0.0
|
|
1454
|
-
*/
|
|
1455
|
-
declare function inject<T, Args extends Array<unknown>>(token: ConstructorLikeType<T, Args>, ...args: Partial<Args>): T;
|
|
1456
|
-
/**
|
|
1457
|
-
* Forces the instantiation of a class, bypassing any existing singleton instance.
|
|
1458
|
-
*
|
|
1459
|
-
* @param token - The constructor function or class to instantiate.
|
|
1460
|
-
* @param args - Optional arguments to pass to the constructor, which can override
|
|
1461
|
-
* or supplement provider-resolved values.
|
|
1462
|
-
* @returns A new instance of the class, even if a singleton instance already exists.
|
|
1463
|
-
*
|
|
1464
|
-
* @remarks
|
|
1465
|
-
* Unlike the `inject` function, `forceInject` will delete any existing singleton
|
|
1466
|
-
* instance for the given class before creating a new one. This is useful when you
|
|
1467
|
-
* need a fresh instance regardless of the singleton scope.
|
|
1468
|
-
*
|
|
1469
|
-
* @example
|
|
1470
|
-
* ```ts
|
|
1471
|
-
* @Injectable({ scope: 'singleton' })
|
|
1472
|
-
* class MyService {}
|
|
1473
|
-
*
|
|
1474
|
-
* const freshInstance = forceInject(MyService);
|
|
1475
|
-
* ```
|
|
1476
|
-
*
|
|
1477
|
-
* @see inject
|
|
1478
|
-
* @since 2.0.0
|
|
1479
|
-
*/
|
|
1480
|
-
declare function forceInject<T, Args extends Array<unknown>>(token: ConstructorLikeType<T, Args>, ...args: Partial<Args>): T;
|
|
1481
|
-
|
|
1482
|
-
/**
|
|
1483
|
-
* Import will remove at compile time
|
|
1484
|
-
*/
|
|
1485
|
-
/**
|
|
1486
|
-
* Represents a provider that uses a factory function to generate a value.
|
|
1487
|
-
*
|
|
1488
|
-
* @remarks
|
|
1489
|
-
* A factory provider can also declare dependencies through `providers`, which
|
|
1490
|
-
* will be resolved and passed to the factory function.
|
|
1491
|
-
*
|
|
1492
|
-
* @example
|
|
1493
|
-
* ```ts
|
|
1494
|
-
* const factoryProvider: ProviderUseFactoryInterface = {
|
|
1495
|
-
* useFactory: (dep: MyService) => new AnotherService(dep),
|
|
1496
|
-
* providers: [MyService]
|
|
1497
|
-
* };
|
|
1498
|
-
* ```
|
|
1499
|
-
*
|
|
1500
|
-
* @see ProvidersType
|
|
1501
|
-
* @since 2.0.0
|
|
1502
|
-
*/
|
|
1503
|
-
interface ProviderUseFactoryInterface {
|
|
1504
|
-
useFactory: FunctionType;
|
|
1505
|
-
providers?: ProvidersType;
|
|
1506
|
-
}
|
|
1507
|
-
/**
|
|
1508
|
-
* Represents a provider that uses a class constructor to generate a value.
|
|
1509
|
-
*
|
|
1510
|
-
* @remarks
|
|
1511
|
-
* Class providers can also declare dependencies through `providers`, which
|
|
1512
|
-
* will be injected when the class is instantiated.
|
|
1513
|
-
*
|
|
1514
|
-
* @example
|
|
1515
|
-
* ```ts
|
|
1516
|
-
* const classProvider: ProviderUseClassInterface = {
|
|
1517
|
-
* useClass: MyService,
|
|
1518
|
-
* providers: [DependencyService]
|
|
1519
|
-
* };
|
|
1520
|
-
* ```
|
|
1521
|
-
*
|
|
1522
|
-
* @see ProvidersType
|
|
1523
|
-
* @since 2.0.0
|
|
1524
|
-
*/
|
|
1525
|
-
interface ProviderUseClassInterface {
|
|
1526
|
-
useClass: ConstructorType;
|
|
1527
|
-
providers?: ProvidersType;
|
|
1528
|
-
}
|
|
1529
|
-
/**
|
|
1530
|
-
* Represents a provider that uses a static value.
|
|
1531
|
-
*
|
|
1532
|
-
* @remarks
|
|
1533
|
-
* Value providers do not have dependencies and are injected as-is.
|
|
1534
|
-
*
|
|
1535
|
-
* @example
|
|
1536
|
-
* ```ts
|
|
1537
|
-
* const valueProvider: ProviderUseValueInterface = {
|
|
1538
|
-
* useValue: 42
|
|
1539
|
-
* };
|
|
1540
|
-
* ```
|
|
1541
|
-
*
|
|
1542
|
-
* @see ProvidersType
|
|
1543
|
-
* @since 2.0.0
|
|
1544
|
-
*/
|
|
1545
|
-
interface ProviderUseValueInterface {
|
|
1546
|
-
useValue: unknown;
|
|
1547
|
-
}
|
|
1548
|
-
/**
|
|
1549
|
-
* Type for all possible providers that can be injected.
|
|
1550
|
-
*
|
|
1551
|
-
* @remarks
|
|
1552
|
-
* Providers can be:
|
|
1553
|
-
* - A class constructor (`ConstructorType`)
|
|
1554
|
-
* - A factory provider (`ProviderUseFactoryInterface`)
|
|
1555
|
-
* - A class provider (`ProviderUseClassInterface`)
|
|
1556
|
-
* - A value provider (`ProviderUseValueInterface`)
|
|
1557
|
-
*
|
|
1558
|
-
* @example
|
|
1559
|
-
* ```ts
|
|
1560
|
-
* const providers: ProvidersType = [
|
|
1561
|
-
* MyService,
|
|
1562
|
-
* { useFactory: () => new AnotherService() },
|
|
1563
|
-
* { useValue: 42 }
|
|
1564
|
-
* ];
|
|
1565
|
-
* ```
|
|
1566
|
-
*
|
|
1567
|
-
* @see ProviderUseClassInterface
|
|
1568
|
-
* @see ProviderUseValueInterface
|
|
1569
|
-
* @see ProviderUseFactoryInterface
|
|
1570
|
-
*
|
|
1571
|
-
* @since 2.0.0
|
|
1572
|
-
*/
|
|
1573
|
-
type ProvidersType = Array<ConstructorType | ProviderUseFactoryInterface | ProviderUseClassInterface | ProviderUseValueInterface>;
|
|
1574
|
-
/**
|
|
1575
|
-
* Options for configuring an injectable class.
|
|
1576
|
-
*
|
|
1577
|
-
* @remarks
|
|
1578
|
-
* - `scope`: Determines whether the class should behave as a singleton or transient.
|
|
1579
|
-
* - `factory`: Optional factory function to instantiate the class.
|
|
1580
|
-
* - `providers`: Optional dependencies to inject when creating the instance.
|
|
1581
|
-
*
|
|
1582
|
-
* @example
|
|
1583
|
-
* ```ts
|
|
1584
|
-
* @Injectable({ scope: 'singleton', providers: [DepService] })
|
|
1585
|
-
* class MyService {}
|
|
1586
|
-
* ```
|
|
1587
|
-
*
|
|
1588
|
-
* @see ProvidersType
|
|
1589
|
-
* @since 2.0.0
|
|
1590
|
-
*/
|
|
1591
|
-
interface InjectableOptionsInterface<T extends ConstructorType = ConstructorType> {
|
|
1592
|
-
scope?: 'singleton' | 'transient';
|
|
1593
|
-
factory?: FunctionLikeType<InstanceType<T>, ConstructorParameters<T>>;
|
|
1594
|
-
providers?: ProvidersType;
|
|
1595
|
-
}
|
|
1596
|
-
|
|
1597
|
-
/**
|
|
1598
|
-
* Import will remove at compile time
|
|
1599
|
-
*/
|
|
1600
|
-
/**
|
|
1601
|
-
* Default configuration object for the `versions` system.
|
|
1602
|
-
*
|
|
1603
|
-
* @remarks
|
|
1604
|
-
* Provides a baseline implementation of {@link ConfigurationInterface}.
|
|
1605
|
-
* This includes:
|
|
1606
|
-
* - Empty `locales` and `rewrites` mappings.
|
|
1607
|
-
* - A `versionsConfig` with:
|
|
1608
|
-
* - `current` set to `"latest"`.
|
|
1609
|
-
* - `sources` pointing to `"src"`.
|
|
1610
|
-
* - `archive` pointing to `"archive"`.
|
|
1611
|
-
* - `hooks.rewritesHook` bound to the default {@link rewritesHook}.
|
|
1612
|
-
* - A `versionSwitcher` enabled with label `"Switch Version"` and
|
|
1613
|
-
* `includeCurrentVersion` set to `true`.
|
|
1614
|
-
*
|
|
1615
|
-
* This default setup can be extended or overridden as needed when
|
|
1616
|
-
* customizing your documentation site.
|
|
1617
|
-
*
|
|
1618
|
-
* @example
|
|
1619
|
-
* ```ts
|
|
1620
|
-
* import { defaultConfiguration } from "@config/default.configuration";
|
|
1621
|
-
*
|
|
1622
|
-
* export default {
|
|
1623
|
-
* ...defaultConfiguration,
|
|
1624
|
-
* locales: {
|
|
1625
|
-
* en: { link: "/en/", label: "English" }
|
|
1626
|
-
* }
|
|
1627
|
-
* };
|
|
1628
|
-
* ```
|
|
1629
|
-
*
|
|
1630
|
-
* @since 2.0.0
|
|
1631
|
-
*/
|
|
1632
|
-
declare const defaultConfiguration: ConfigurationInterface;
|
|
1633
|
-
|
|
1634
|
-
/**
|
|
1635
|
-
* Import will remove at compile time
|
|
1636
|
-
*/
|
|
1637
|
-
/**
|
|
1638
|
-
* Rewrites a documentation source path using version and locale.
|
|
1639
|
-
*
|
|
1640
|
-
* @remarks
|
|
1641
|
-
* This implementation joins the `version`, `locale`, and original `source`
|
|
1642
|
-
* into a normalized POSIX-style path. It is commonly used to generate
|
|
1643
|
-
* consistent URLs or filesystem paths for versioned and localized docs.
|
|
1644
|
-
*
|
|
1645
|
-
* @param source - The original file path or content identifier.
|
|
1646
|
-
* @param version - The version string of the documentation (e.g., `"1.2.0"`).
|
|
1647
|
-
* @param locale - The locale code (e.g., `"en"`, `"de"`).
|
|
1648
|
-
*
|
|
1649
|
-
* @returns The rewritten path string in the format `version/locale/source`.
|
|
1650
|
-
*
|
|
1651
|
-
* @example
|
|
1652
|
-
* ```ts
|
|
1653
|
-
* rewritesHook("guide/intro.md", "v2.0.0", "en");
|
|
1654
|
-
* // → "en/v2.0.0/guide/intro.md"
|
|
1655
|
-
* ```
|
|
1656
|
-
*
|
|
1657
|
-
* @since 2.0.0
|
|
1658
|
-
*/
|
|
1659
|
-
declare function rewritesHook(source: string, version: string, locale: string): string;
|
|
1660
|
-
/**
|
|
1661
|
-
* Extracts locale and version information from URL path segments.
|
|
1662
|
-
*
|
|
1663
|
-
* @param segments - Array of URL path segments to parse (will be modified by shifting elements).
|
|
1664
|
-
* @param localesList - List of valid locale identifiers for matching.
|
|
1665
|
-
* @param versionsList - List of valid version identifiers for matching.
|
|
1666
|
-
* @returns An object containing extracted language and version {@link PathSegmentsInterface}.
|
|
1667
|
-
*
|
|
1668
|
-
* @remarks
|
|
1669
|
-
* This function parses URL path segments to identify and extract locale and version
|
|
1670
|
-
* information, supporting both version-first and locale-first URL structures. The
|
|
1671
|
-
* function operates on the segment array destructively, removing matched elements
|
|
1672
|
-
* via {@link Array.shift}.
|
|
1673
|
-
*
|
|
1674
|
-
* **Parsing logic**:
|
|
1675
|
-
* 1. If the first segment matches a version → extract it as `version`.
|
|
1676
|
-
* 2. If the first segment matches a locale → extract it as `lang`.
|
|
1677
|
-
* 3. Return both extracted values (empty strings if not found).
|
|
1678
|
-
*
|
|
1679
|
-
* **URL patterns supported**:
|
|
1680
|
-
* - `/v2.0/guide/` → `{ lang: '', version: 'v2.0' }`
|
|
1681
|
-
* - `/fr/v2.0/guide/` → `{ lang: 'fr', version: 'v2.0' }`
|
|
1682
|
-
* - `/fr/guide/` → `{ lang: 'fr', version: '' }`
|
|
1683
|
-
* - `/guide/` → `{ lang: '', version: '' }`
|
|
1684
|
-
*
|
|
1685
|
-
* The segment array is mutated during extraction, with matched segments removed
|
|
1686
|
-
* from the beginning. This allows the following processing to work with the remaining
|
|
1687
|
-
* path components.
|
|
1688
|
-
*
|
|
1689
|
-
* @example
|
|
1690
|
-
* ```ts
|
|
1691
|
-
* const localesList = ['en', 'fr', 'de'];
|
|
1692
|
-
* const versionsList = ['v1.0', 'v2.0', 'latest'];
|
|
1693
|
-
*
|
|
1694
|
-
* // Version-first pattern
|
|
1695
|
-
* const segments1 = ['v2.0', 'guide', 'intro'];
|
|
1696
|
-
* const result1 = extractLocale(segments1, localesList, versionsList);
|
|
1697
|
-
* console.log(result1); // { lang: '', version: 'v2.0' }
|
|
1698
|
-
* console.log(segments1); // ['guide', 'intro']
|
|
1699
|
-
*
|
|
1700
|
-
* // Locale-first pattern
|
|
1701
|
-
* const segments2 = ['fr', 'v2.0', 'api', 'reference'];
|
|
1702
|
-
* const result2 = extractLocale(segments2, localesList, versionsList);
|
|
1703
|
-
* console.log(result2); // { lang: 'fr', version: 'v2.0' }
|
|
1704
|
-
* console.log(segments2); // ['api', 'reference']
|
|
1705
|
-
*
|
|
1706
|
-
* // No locale or version
|
|
1707
|
-
* const segments3 = ['docs', 'getting-started'];
|
|
1708
|
-
* const result3 = extractLocale(segments3, localesList, versionsList);
|
|
1709
|
-
* console.log(result3); // { lang: '', version: '' }
|
|
1710
|
-
* console.log(segments3); // ['docs', 'getting-started']
|
|
1711
|
-
*
|
|
1712
|
-
* // Use case: URL parsing for routing
|
|
1713
|
-
* const url = '/de/latest/guide/installation';
|
|
1714
|
-
* const segments = url.split('/').filter(Boolean);
|
|
1715
|
-
* const { lang, version } = extractLocale(
|
|
1716
|
-
* segments,
|
|
1717
|
-
* ['en', 'de', 'fr'],
|
|
1718
|
-
* ['latest', 'v1', 'v2']
|
|
1719
|
-
* );
|
|
1720
|
-
* const route = segments.join('/');
|
|
1721
|
-
* console.log({ lang, version, route });
|
|
1722
|
-
* // { lang: 'de', version: 'latest', route: 'guide/installation' }
|
|
1723
|
-
* ```
|
|
1724
|
-
*
|
|
1725
|
-
* @see PathSegmentsInterface
|
|
1726
|
-
* @since 2.0.5
|
|
1727
|
-
*/
|
|
1728
|
-
declare function extractLocale(segments: Array<string>, localesList: Array<string>, versionsList: Array<string>): PathSegmentsInterface;
|
|
1729
|
-
/**
|
|
1730
|
-
* Parses all documentation routes and generates rewritten paths for versioned and localized files.
|
|
1731
|
-
*
|
|
1732
|
-
* @remarks
|
|
1733
|
-
* - Iterates through the `fileMap` of the `StateModel` to process all Markdown files.
|
|
1734
|
-
* - Determines the correct locale for each file using `localesMap`.
|
|
1735
|
-
* - Uses the `rewritesHook` from `versionsConfig.hooks` to generate the versioned and localized path.
|
|
1736
|
-
* - Populates the `vitepressConfig.rewrites` object with the mapping of original paths to rewritten paths.
|
|
1737
|
-
*
|
|
1738
|
-
* @example
|
|
1739
|
-
* ```ts
|
|
1740
|
-
* parseRoutesComponent();
|
|
1741
|
-
* console.log(state.vitepressConfig.rewrites);
|
|
1742
|
-
* // → {
|
|
1743
|
-
* "src/en/index.md": "en/index.md",
|
|
1744
|
-
* "src/de/index.md": "index.md",
|
|
1745
|
-
* "archive/x0.0.1/en/index.md": "x0.0.1/en/index.md"
|
|
1746
|
-
* ...
|
|
1747
|
-
* }
|
|
1748
|
-
* ```
|
|
1749
|
-
*
|
|
1750
|
-
* @since 2.0.0
|
|
1751
|
-
*/
|
|
1752
|
-
declare function parseRoutesComponent(): void;
|
|
1753
|
-
|
|
1754
|
-
/**
|
|
1755
|
-
* Represents extracted locale and version information from URL path segments.
|
|
1756
|
-
*
|
|
1757
|
-
* @remarks
|
|
1758
|
-
* This interface defines the structure returned by {@link extractLocale} when parsing
|
|
1759
|
-
* URL paths in a multi-version, multi-locale documentation system. It separates the
|
|
1760
|
-
* locale identifier from the version identifier, enabling proper routing and content
|
|
1761
|
-
* resolution.
|
|
1762
|
-
*
|
|
1763
|
-
* Both properties use empty strings as sentinel values to indicate absence, rather
|
|
1764
|
-
* than undefined or null, simplifying string concatenation and path construction
|
|
1765
|
-
* operations.
|
|
1766
|
-
*
|
|
1767
|
-
* Common usage patterns:
|
|
1768
|
-
* - Route parsing and URL analysis
|
|
1769
|
-
* - Content path resolution
|
|
1770
|
-
* - Locale and version detection from request URLs
|
|
1771
|
-
* - Sidebar and navigation path construction
|
|
1772
|
-
* - Determining which content variant to serve
|
|
1773
|
-
*
|
|
1774
|
-
* The interface supports various URL structures:
|
|
1775
|
-
* - Root locale, no version: `{ lang: '', version: '' }` → `/guide/`
|
|
1776
|
-
* - Root locale with version: `{ lang: '', version: 'v2.0' }` → `/v2.0/guide/`
|
|
1777
|
-
* - Specific locale, no version: `{ lang: 'fr', version: '' }` → `/fr/guide/`
|
|
1778
|
-
* - Specific locale with version: `{ lang: 'fr', version: 'v2.0' }` → `/fr/v2.0/guide/`
|
|
1779
|
-
*
|
|
1780
|
-
* @example
|
|
1781
|
-
* ```ts
|
|
1782
|
-
* // Parse URL segments
|
|
1783
|
-
* const segments = ['fr', 'v2.0', 'guide', 'intro'];
|
|
1784
|
-
* const result: PathSegmentsInterface = extractLocale(
|
|
1785
|
-
* segments,
|
|
1786
|
-
* ['en', 'fr', 'de'],
|
|
1787
|
-
* ['v1.0', 'v2.0', 'latest']
|
|
1788
|
-
* );
|
|
1789
|
-
* console.log(result);
|
|
1790
|
-
* // { lang: 'fr', version: 'v2.0' }
|
|
1791
|
-
*
|
|
1792
|
-
* // Handle missing locale/version
|
|
1793
|
-
* const segments2 = ['docs', 'api'];
|
|
1794
|
-
* const result2: PathSegmentsInterface = extractLocale(segments2, locales, versions);
|
|
1795
|
-
* console.log(result2);
|
|
1796
|
-
* // { lang: '', version: '' }
|
|
1797
|
-
*
|
|
1798
|
-
* // Use in routing logic
|
|
1799
|
-
* function resolveContent(path: string): string {
|
|
1800
|
-
* const segments = path.split('/').filter(Boolean);
|
|
1801
|
-
* const { lang, version }: PathSegmentsInterface = extractLocale(
|
|
1802
|
-
* segments,
|
|
1803
|
-
* availableLocales,
|
|
1804
|
-
* availableVersions
|
|
1805
|
-
* );
|
|
1806
|
-
*
|
|
1807
|
-
* const contentPath = [
|
|
1808
|
-
* lang || 'en',
|
|
1809
|
-
* version || 'latest',
|
|
1810
|
-
* ...segments
|
|
1811
|
-
* ].join('/');
|
|
1812
|
-
*
|
|
1813
|
-
* return loadContent(contentPath);
|
|
1814
|
-
* }
|
|
1815
|
-
*
|
|
1816
|
-
* // Use in path construction
|
|
1817
|
-
* function buildPath(info: PathSegmentsInterface, ...segments: string[]): string {
|
|
1818
|
-
* const parts = [
|
|
1819
|
-
* info.lang,
|
|
1820
|
-
* info.version,
|
|
1821
|
-
* ...segments
|
|
1822
|
-
* ].filter(Boolean);
|
|
1823
|
-
*
|
|
1824
|
-
* return '/' + parts.join('/');
|
|
1825
|
-
* }
|
|
1826
|
-
*
|
|
1827
|
-
* const pathInfo: PathSegmentsInterface = { lang: 'de', version: 'v3.0' };
|
|
1828
|
-
* console.log(buildPath(pathInfo, 'guide', 'intro'));
|
|
1829
|
-
* // '/de/v3.0/guide/intro'
|
|
1830
|
-
* ```
|
|
1831
|
-
*
|
|
1832
|
-
* @see extractLocale
|
|
1833
|
-
* @since 2.0.5
|
|
1834
|
-
*/
|
|
1835
|
-
interface PathSegmentsInterface {
|
|
1836
|
-
lang: string;
|
|
1837
|
-
version: string;
|
|
1838
|
-
}
|
|
1839
|
-
|
|
1840
|
-
/**
|
|
1841
|
-
* Import will remove at compile time
|
|
1842
|
-
*/
|
|
1843
|
-
/**
|
|
1844
|
-
* Type guard to check if a navigation item has children.
|
|
1845
|
-
*
|
|
1846
|
-
* @param item - The navigation item to test.
|
|
1847
|
-
* @returns `true` if the item is a {@link NavItemWithChildrenType}, `false` otherwise.
|
|
1848
|
-
*
|
|
1849
|
-
* @remarks
|
|
1850
|
-
* - This function checks for the presence of an `item` property that is an array.
|
|
1851
|
-
* - Use this type guard to safely access child navigation items when iterating
|
|
1852
|
-
* or transforming navigation trees.
|
|
1853
|
-
*
|
|
1854
|
-
* @example
|
|
1855
|
-
* ```ts
|
|
1856
|
-
* const item: NavItemType = { text: "Docs", items: [{ text: "Guide", link: "/guide/" }] };
|
|
1857
|
-
* if (isNavItemWithChildren(item)) {
|
|
1858
|
-
* console.log(item.items); // Safe to access
|
|
1859
|
-
* }
|
|
1860
|
-
* ```
|
|
1861
|
-
*
|
|
1862
|
-
* @since 2.0.0
|
|
1863
|
-
*/
|
|
1864
|
-
declare function isNavItemWithChildren(item: NavItemType): item is NavItemWithChildrenType;
|
|
1865
|
-
/**
|
|
1866
|
-
* Type guard to check if a navigation item has a link.
|
|
1867
|
-
*
|
|
1868
|
-
* @param item - The navigation item to test.
|
|
1869
|
-
* @returns `true` if the item is a {@link NavItemWithLinkType}, `false` otherwise.
|
|
1870
|
-
*
|
|
1871
|
-
* @remarks
|
|
1872
|
-
* - This function checks for the presence of a `link` property.
|
|
1873
|
-
* - Use this type guard to safely access the `link` property when iterating
|
|
1874
|
-
* or transforming navigation trees.
|
|
1875
|
-
*
|
|
1876
|
-
* @example
|
|
1877
|
-
* ```ts
|
|
1878
|
-
* const item: NavItemType = { text: "Home", link: "/" };
|
|
1879
|
-
* if (isNavItemWithLink(item)) {
|
|
1880
|
-
* console.log(item.link); // Safe to access
|
|
1881
|
-
* }
|
|
1882
|
-
* ```
|
|
1883
|
-
*
|
|
1884
|
-
* @since 2.0.0
|
|
1885
|
-
*/
|
|
1886
|
-
declare function isNavItemWithLink(item: NavItemType): item is NavItemWithLinkType;
|
|
1887
|
-
/**
|
|
1888
|
-
* Recursively prepends a version prefix to navigation item links.
|
|
1889
|
-
*
|
|
1890
|
-
* @param version - The version string to prefix (e.g., `"v2.0.0"`).
|
|
1891
|
-
* @param item - The navigation item to process, which can be a link, a group with children, or a component.
|
|
1892
|
-
* @returns A new navigation item with updated `link` values where applicable.
|
|
1893
|
-
*
|
|
1894
|
-
* @remarks
|
|
1895
|
-
* - For {@link NavItemWithLinkType}, prepends the given `version` to the `link`
|
|
1896
|
-
* unless `skipVersioning` is `true`.
|
|
1897
|
-
* - For {@link NavItemWithChildrenType}, recursively traverses all children and applies
|
|
1898
|
-
* the same transformation.
|
|
1899
|
-
* - Component-based navigation items ({@link NavItemComponentType}) are returned as-is.
|
|
1900
|
-
* - Preserves other properties of the navigation items.
|
|
1901
|
-
*
|
|
1902
|
-
* @example
|
|
1903
|
-
* ```ts
|
|
1904
|
-
* const navItem: NavItemWithLinkType = { text: "Guide", link: "/guide/" };
|
|
1905
|
-
* const result = replaceLinksRecursive("v2.0.0", navItem);
|
|
1906
|
-
* // → { text: "Guide", link: "/v2.0.0/guide/" }
|
|
1907
|
-
*
|
|
1908
|
-
* const navGroup: NavItemWithChildrenType = {
|
|
1909
|
-
* text: "Docs",
|
|
1910
|
-
* items: [{ text: "Intro", link: "/intro/" }]
|
|
1911
|
-
* };
|
|
1912
|
-
* const groupResult = replaceLinksRecursive("v2.0.0", navGroup);
|
|
1913
|
-
* // → { text: "Docs", items: [{ text: "Intro", link: "/v2.0.0/intro/" }] }
|
|
1914
|
-
* ```
|
|
1915
|
-
*
|
|
1916
|
-
* @since 2.0.0
|
|
1917
|
-
*/
|
|
1918
|
-
declare function replaceLinksRecursive(version: string, item: NavItemType): NavItemType;
|
|
1919
|
-
/**
|
|
1920
|
-
* Applies version prefixes to an array of navigation items.
|
|
1921
|
-
*
|
|
1922
|
-
* @param items - An array of navigation items to process.
|
|
1923
|
-
* @param version - The version string to prepend to links (e.g., `"v2.0.0"`).
|
|
1924
|
-
* - If `"root"` is provided, no version prefix is added.
|
|
1925
|
-
* @returns A new array of navigation items with versioned links applied.
|
|
1926
|
-
*
|
|
1927
|
-
* @remarks
|
|
1928
|
-
* - Uses {@link replaceLinksRecursive} to traverse each navigation item.
|
|
1929
|
-
* - Only items that are link-based or have children are modified; component items remain unchanged.
|
|
1930
|
-
* - Preserves other properties of the navigation items.
|
|
1931
|
-
*
|
|
1932
|
-
* @example
|
|
1933
|
-
* ```ts
|
|
1934
|
-
* const navItems: NavItemType[] = [
|
|
1935
|
-
* { text: "Guide", link: "/guide/" },
|
|
1936
|
-
* { text: "Docs", items: [{ text: "Intro", link: "/intro/" }] }
|
|
1937
|
-
* ];
|
|
1938
|
-
* const versionedNav = populateNav(navItems, "v2.0.0");
|
|
1939
|
-
* // → [
|
|
1940
|
-
* // { text: "Guide", link: "/v2.0.0/guide/" },
|
|
1941
|
-
* // { text: "Docs", items: [{ text: "Intro", link: "/v2.0.0/intro/" }] }
|
|
1942
|
-
* // ]
|
|
1943
|
-
* ```
|
|
1944
|
-
*
|
|
1945
|
-
* @since 2.0.0
|
|
1946
|
-
*/
|
|
1947
|
-
declare function populateNav(items: Array<NavItemType>, version: string): Array<NavItemType>;
|
|
1948
|
-
/**
|
|
1949
|
-
* Normalizes a navigation structure into a flat, prefixed record.
|
|
1950
|
-
*
|
|
1951
|
-
* @param results - The target {@link NavObjectType} to populate with normalized items.
|
|
1952
|
-
* @param nav - The navigation structure to normalize. Can be:
|
|
1953
|
-
* - An array of navigation items (`NavItemType[]`), or
|
|
1954
|
-
* - A record mapping strings to arrays of navigation items (`NavObjectType`).
|
|
1955
|
-
* @param prefix - Optional prefix for keys when processing nested navigation objects.
|
|
1956
|
-
* Defaults to an empty string.
|
|
1957
|
-
* @param root - Optional root-level navigation items to include in all normalized entries.
|
|
1958
|
-
*
|
|
1959
|
-
* @remarks
|
|
1960
|
-
* - If `nav` is an array, it merges it with the root items (if any) and appends to `results.root`.
|
|
1961
|
-
* - If `nav` is a record:
|
|
1962
|
-
* - Each key is prefixed with `prefix` unless it is `'root'`.
|
|
1963
|
-
* - Items from `root` or `root.root` are merged into each key.
|
|
1964
|
-
* - All items are accumulated in the `results` object, preserving the hierarchy as flat keys.
|
|
1965
|
-
*
|
|
1966
|
-
* @example
|
|
1967
|
-
* ```ts
|
|
1968
|
-
* const nav: NavObjectType = {
|
|
1969
|
-
* root: [{ text: "Home", link: "/" }],
|
|
1970
|
-
* guide: [{ text: "Intro", link: "/intro/" }]
|
|
1971
|
-
* };
|
|
1972
|
-
* const results: NavObjectType = { root: [] };
|
|
1973
|
-
* normalizeNav(results, nav, "v2.0.0");
|
|
1974
|
-
* // results → {
|
|
1975
|
-
* // root: [{ text: "Home", link: "/" }],
|
|
1976
|
-
* // "v2.0.0/guide": [{ text: "Intro", link: "/intro/" }]
|
|
1977
|
-
* // }
|
|
1978
|
-
* ```
|
|
1979
|
-
*
|
|
1980
|
-
* @since 2.0.0
|
|
1981
|
-
*/
|
|
1982
|
-
declare function normalizeNav(results: NavObjectType, nav: NavType, prefix?: string, root?: NavObjectType): void;
|
|
568
|
+
* @see VersionsSwitcherInterface
|
|
569
|
+
* @since 2.0.0
|
|
570
|
+
*/
|
|
571
|
+
versionSwitcher: false | VersionsSwitcherInterface;
|
|
572
|
+
}
|
|
1983
573
|
/**
|
|
1984
|
-
*
|
|
1985
|
-
*
|
|
1986
|
-
* @param state - The current {@link StateModel} providing configuration data:
|
|
1987
|
-
* - `configuration.themeConfig.nav` — global navigation configuration.
|
|
1988
|
-
* - `configuration.locales` — locale-specific configurations with optional `nav`.
|
|
1989
|
-
*
|
|
1990
|
-
* @returns A flat record of navigation items keyed by locale or `'root'`, suitable for further processing.
|
|
574
|
+
* Main configuration interface for a VitePress site with extended features.
|
|
1991
575
|
*
|
|
1992
576
|
* @remarks
|
|
1993
|
-
*
|
|
1994
|
-
* -
|
|
1995
|
-
* -
|
|
1996
|
-
*
|
|
1997
|
-
* - Merges in global navigation items as fallback where necessary.
|
|
1998
|
-
* - Ensures that all navigation entries are flattened and ready for versioning or rendering.
|
|
577
|
+
* Extends VitePress's `UserConfig` but overrides:
|
|
578
|
+
* - `locales` to use a strongly typed `LocalesInterface`.
|
|
579
|
+
* - `rewrites` to define path rewrites for the site.
|
|
580
|
+
* - `versionsConfig` to manage documentation versions and the version switcher.
|
|
1999
581
|
*
|
|
2000
582
|
* @example
|
|
2001
583
|
* ```ts
|
|
2002
|
-
* const
|
|
2003
|
-
*
|
|
2004
|
-
*
|
|
2005
|
-
*
|
|
2006
|
-
*
|
|
2007
|
-
*
|
|
2008
|
-
*
|
|
584
|
+
* const config: ConfigurationInterface = {
|
|
585
|
+
* locales: {
|
|
586
|
+
* en: { link: "/en/", label: "English" },
|
|
587
|
+
* de: { link: "/de/", label: "Deutsch" }
|
|
588
|
+
* },
|
|
589
|
+
* rewrites: {
|
|
590
|
+
* "/old-path": "/new-path"
|
|
591
|
+
* },
|
|
592
|
+
* versionsConfig: {
|
|
593
|
+
* current: "2.0",
|
|
594
|
+
* sources: "src",
|
|
595
|
+
* archive: "archive",
|
|
596
|
+
* hooks: { rewritesHook: (src, ver) => `/v${ver}/${src}` },
|
|
597
|
+
* versionSwitcher: { text: "Version", includeCurrentVersion: true }
|
|
598
|
+
* }
|
|
599
|
+
* };
|
|
2009
600
|
* ```
|
|
2010
601
|
*
|
|
2011
602
|
* @since 2.0.0
|
|
2012
603
|
*/
|
|
2013
|
-
|
|
604
|
+
interface ConfigurationInterface extends Omit<UserConfig<ThemeInterface>, 'rewrites' | 'locales'> {
|
|
605
|
+
/**
|
|
606
|
+
* Locale-specific configuration for the site.
|
|
607
|
+
*
|
|
608
|
+
* @remarks
|
|
609
|
+
* Uses {@link LocalesInterface} to strongly type each locale's settings.
|
|
610
|
+
*
|
|
611
|
+
* @since 2.0.0
|
|
612
|
+
*/
|
|
613
|
+
locales: LocalesInterface;
|
|
614
|
+
/**
|
|
615
|
+
* Path rewrites for the site.
|
|
616
|
+
*
|
|
617
|
+
* @remarks
|
|
618
|
+
* Maps old paths to new paths, enabling URL restructuring without breaking links.
|
|
619
|
+
*
|
|
620
|
+
* @since 2.0.0
|
|
621
|
+
*/
|
|
622
|
+
rewrites: Record<string, string>;
|
|
623
|
+
/**
|
|
624
|
+
* Versioning configuration for documentation.
|
|
625
|
+
*
|
|
626
|
+
* @remarks
|
|
627
|
+
* Defines the current version, source directory, archive, hooks, and version switcher behavior.
|
|
628
|
+
*
|
|
629
|
+
* @see VersionsConfigInterface
|
|
630
|
+
* @since 2.0.0
|
|
631
|
+
*/
|
|
632
|
+
versionsConfig: VersionsConfigInterface;
|
|
633
|
+
}
|
|
2014
634
|
/**
|
|
2015
|
-
*
|
|
2016
|
-
*
|
|
2017
|
-
* @param navs - The navigation configurations mapped by locale keys.
|
|
2018
|
-
* @param key - The locale key to retrieve navigation for (e.g., 'root', 'fr', 'fr/v1.0.0').
|
|
2019
|
-
* @returns The navigation configuration for the locale, falling back to parent locale or root.
|
|
635
|
+
* Represents a deeply partial version of the `ConfigurationInterface`.
|
|
2020
636
|
*
|
|
2021
637
|
* @remarks
|
|
2022
|
-
* This
|
|
2023
|
-
*
|
|
2024
|
-
* 2. If the key contains '/' (versioned locale), extract the base locale and try that
|
|
2025
|
-
* 3. If no base locale exists, fall back to 'root'
|
|
2026
|
-
*
|
|
2027
|
-
* This allows versioned locales (e.g., 'fr/v1.0.0', 'de/v2.0') to inherit navigation
|
|
2028
|
-
* from their base locale ('fr', 'de') without duplicating configuration.
|
|
638
|
+
* This type allows any property of `ConfigurationInterface` to be optional,
|
|
639
|
+
* including all nested properties. It is based on the `DeepPartialType` utility type.
|
|
2029
640
|
*
|
|
2030
|
-
*
|
|
2031
|
-
*
|
|
2032
|
-
* - `'fr/v1.0.0'` → No direct match → Checks `'fr'` → Returns `navs.fr`
|
|
2033
|
-
* - `'es/v1.0.0'` → No direct match → Checks `'es'` (doesn't exist) → Returns `navs.root`
|
|
2034
|
-
* - `'root'` → Direct match, returns `navs.root`
|
|
641
|
+
* Useful for scenarios where you want to provide only a subset of the configuration,
|
|
642
|
+
* for example, when overriding default settings or merging user-provided options.
|
|
2035
643
|
*
|
|
2036
644
|
* @example
|
|
2037
645
|
* ```ts
|
|
2038
|
-
* const
|
|
2039
|
-
*
|
|
2040
|
-
*
|
|
2041
|
-
*
|
|
646
|
+
* const partialConfig: PartialConfigurationType = {
|
|
647
|
+
* locales: {
|
|
648
|
+
* en: { label: "English" }
|
|
649
|
+
* },
|
|
650
|
+
* versionsConfig: {
|
|
651
|
+
* versionSwitcher: { text: "Version" }
|
|
652
|
+
* }
|
|
2042
653
|
* };
|
|
2043
|
-
*
|
|
2044
|
-
* // Exact match
|
|
2045
|
-
* getNavForLocale(navs, 'fr'); // Returns fr nav
|
|
2046
|
-
*
|
|
2047
|
-
* // Versioned locale - inherits from base
|
|
2048
|
-
* getNavForLocale(navs, 'fr/v1.0.0'); // Returns fr nav
|
|
2049
|
-
* getNavForLocale(navs, 'de/v2.0'); // Returns de nav
|
|
2050
|
-
*
|
|
2051
|
-
* // No base locale exists - falls back to root
|
|
2052
|
-
* getNavForLocale(navs, 'es/v1.0.0'); // Returns root nav
|
|
2053
|
-
*
|
|
2054
|
-
* // Root locale
|
|
2055
|
-
* getNavForLocale(navs, 'root'); // Returns root nav
|
|
2056
654
|
* ```
|
|
2057
655
|
*
|
|
2058
|
-
* @
|
|
2059
|
-
* @see {@link NavItemType} - The navigation item type structure
|
|
2060
|
-
*
|
|
2061
|
-
* @since 2.0.5
|
|
656
|
+
* @since 2.0.0
|
|
2062
657
|
*/
|
|
2063
|
-
|
|
658
|
+
type PartialConfigurationType = DeepPartialType<ConfigurationInterface>;
|
|
2064
659
|
/**
|
|
2065
|
-
*
|
|
660
|
+
* A strongly typed VitePress configuration where specific keys are required.
|
|
2066
661
|
*
|
|
2067
662
|
* @remarks
|
|
2068
|
-
*
|
|
2069
|
-
*
|
|
2070
|
-
* -
|
|
2071
|
-
*
|
|
2072
|
-
*
|
|
2073
|
-
* - Populates the locale’s `themeConfig.nav` using {@link populateNav}, applying versioning where applicable.
|
|
663
|
+
* This type uses {@link RequireKeysType} to ensure that the following properties
|
|
664
|
+
* of `UserConfig<DefaultTheme.Config>` are always present:
|
|
665
|
+
* - `locales`
|
|
666
|
+
* - `rewrites`
|
|
667
|
+
* - `themeConfig`
|
|
2074
668
|
*
|
|
2075
|
-
*
|
|
669
|
+
* All other properties remain optional, preserving the flexibility of the standard
|
|
670
|
+
* VitePress configuration type.
|
|
2076
671
|
*
|
|
2077
672
|
* @example
|
|
2078
673
|
* ```ts
|
|
2079
|
-
*
|
|
2080
|
-
*
|
|
674
|
+
* const config: VitepressConfigType = {
|
|
675
|
+
* locales: { en: { link: "/en/", label: "English" } },
|
|
676
|
+
* rewrites: { "/old-path": "/new-path" },
|
|
677
|
+
* themeConfig: { nav: [], sidebar: {} }
|
|
678
|
+
* };
|
|
2081
679
|
* ```
|
|
2082
680
|
*
|
|
2083
681
|
* @since 2.0.0
|
|
2084
682
|
*/
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
/**
|
|
2088
|
-
* Imports
|
|
2089
|
-
*/
|
|
683
|
+
type VitepressConfigType = RequireKeysType<UserConfig<DefaultTheme.Config>, 'locales' | 'rewrites' | 'themeConfig'>;
|
|
2090
684
|
/**
|
|
2091
|
-
*
|
|
2092
|
-
*
|
|
2093
|
-
* @param themeConfig - The {@link VersionsConfigInterface} configuration object.
|
|
2094
|
-
* @param versions - An array of available version strings.
|
|
2095
|
-
* @param current - The current version label, defaults to `"Latest"`.
|
|
2096
|
-
*
|
|
2097
|
-
* @returns A {@link NavItemWithChildrenType} representing the version switcher,
|
|
2098
|
-
* or `undefined` if the switcher is disabled in the configuration.
|
|
685
|
+
* Strongly typed VitePress configuration interface with custom locales support.
|
|
2099
686
|
*
|
|
2100
687
|
* @remarks
|
|
2101
|
-
*
|
|
2102
|
-
*
|
|
2103
|
-
* - If `includeCurrentVersion` is enabled, adds a link to the root (`"/"`)
|
|
2104
|
-
* for the currently active version, displayed as `"Latest"` or
|
|
2105
|
-
* `"vX.Y.Z (latest)"`.
|
|
2106
|
-
* - All version links have `skipVersioning: true` to prevent further prefixing.
|
|
688
|
+
* Extends {@link VitepressConfigType} but overrides the `locales` property
|
|
689
|
+
* to use a strongly typed {@link LocalesInterface}.
|
|
2107
690
|
*
|
|
2108
|
-
* This
|
|
2109
|
-
*
|
|
691
|
+
* This ensures:
|
|
692
|
+
* - `locales` are fully typed with per-locale configurations.
|
|
693
|
+
* - Other required properties from `VitepressConfigType` (`rewrites`, `themeConfig`) remain enforced.
|
|
694
|
+
* - Remaining properties from `UserConfig<DefaultTheme.Config>` retain their optionality.
|
|
2110
695
|
*
|
|
2111
696
|
* @example
|
|
2112
697
|
* ```ts
|
|
2113
|
-
* const
|
|
2114
|
-
*
|
|
698
|
+
* const config: VitepressConfigInterface = {
|
|
699
|
+
* locales: {
|
|
700
|
+
* en: { link: "/en/", label: "English" },
|
|
701
|
+
* de: { link: "/de/", label: "Deutsch" }
|
|
702
|
+
* },
|
|
703
|
+
* rewrites: { "/old-path": "/new-path" },
|
|
704
|
+
* themeConfig: { nav: [], sidebar: {} }
|
|
2115
705
|
* };
|
|
2116
|
-
*
|
|
2117
|
-
* const versions = ["v2.0.0", "v1.5.0"];
|
|
2118
|
-
* const navItem = versionSwitcher(themeConfig, versions, "v2.0.0");
|
|
2119
|
-
*
|
|
2120
|
-
* // → {
|
|
2121
|
-
* // text: "Versions",
|
|
2122
|
-
* // items: [
|
|
2123
|
-
* // { link: "/", text: "v2.0.0 (latest)", skipVersioning: true },
|
|
2124
|
-
* // { link: "/v2.0.0/", text: "v2.0.0", skipVersioning: true },
|
|
2125
|
-
* // { link: "/v1.5.0/", text: "v1.5.0", skipVersioning: true }
|
|
2126
|
-
* // ]
|
|
2127
|
-
* // }
|
|
2128
706
|
* ```
|
|
2129
707
|
*
|
|
2130
708
|
* @since 2.0.0
|
|
2131
709
|
*/
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
710
|
+
interface VitepressConfigInterface extends Omit<VitepressConfigType, 'locales'> {
|
|
711
|
+
/**
|
|
712
|
+
* Locale-specific configuration for the site.
|
|
713
|
+
*
|
|
714
|
+
* @remarks
|
|
715
|
+
* Uses {@link LocalesInterface} to strongly type each locale's settings.
|
|
716
|
+
*
|
|
717
|
+
* @since 2.0.0
|
|
718
|
+
*/
|
|
719
|
+
locales: LocalesInterface;
|
|
720
|
+
}
|
|
2137
721
|
/**
|
|
2138
|
-
*
|
|
2139
|
-
*
|
|
2140
|
-
* @typeParam T - The type of the first object.
|
|
2141
|
-
* @typeParam U - The type of the second object.
|
|
2142
|
-
*
|
|
2143
|
-
* @param obj1 - The base object whose properties will be merged.
|
|
2144
|
-
* @param obj2 - The object whose properties will overwrite or merge into `obj1`.
|
|
2145
|
-
* @returns A new object containing the deeply merged properties of both `obj1` and `obj2`.
|
|
722
|
+
* A generic type representing a function with any arguments and any return type.
|
|
2146
723
|
*
|
|
2147
724
|
* @remarks
|
|
2148
|
-
*
|
|
2149
|
-
*
|
|
2150
|
-
* - If both values are plain objects, they are merged recursively.
|
|
2151
|
-
* - Otherwise, the value from `obj2` overwrites the value from `obj1`.
|
|
2152
|
-
* - Arrays are **not** merged; if a property is an array in `obj2`, it will replace
|
|
2153
|
-
* the corresponding property in `obj1`.
|
|
725
|
+
* This type is a very flexible function type, allowing any arguments of any type
|
|
726
|
+
* and returning any type. Use with caution, as it bypasses TypeScript's type safety.
|
|
2154
727
|
*
|
|
2155
728
|
* @example
|
|
2156
729
|
* ```ts
|
|
2157
|
-
* const
|
|
2158
|
-
* const obj2 = { b: { c: 42 }, e: 99 };
|
|
730
|
+
* const exampleFn: FunctionType = (a, b, c) => a + b + c;
|
|
2159
731
|
*
|
|
2160
|
-
* const
|
|
2161
|
-
* // Result: { a: 1, b: { c: 42, d: 3 }, e: 99 }
|
|
732
|
+
* const anotherFn: FunctionType = (...args) => args.length;
|
|
2162
733
|
* ```
|
|
2163
734
|
*
|
|
2164
735
|
* @since 2.0.0
|
|
2165
736
|
*/
|
|
2166
|
-
|
|
737
|
+
type FunctionType = (...args: Array<any>) => any;
|
|
2167
738
|
/**
|
|
2168
|
-
*
|
|
2169
|
-
* returning their paths relative to a specified root directory.
|
|
2170
|
-
*
|
|
2171
|
-
* @param rootDir - The root directory used as the base for relative paths.
|
|
2172
|
-
* @param currentDir - The current directory to scan. Defaults to `rootDir`.
|
|
2173
|
-
* @returns An array of relative file paths to Markdown files.
|
|
739
|
+
* Represents a generic constructor type.
|
|
2174
740
|
*
|
|
2175
741
|
* @remarks
|
|
2176
|
-
*
|
|
2177
|
-
*
|
|
2178
|
-
* - Returned paths are **relative to `rootDir`**, regardless of how deep the files are nested.
|
|
2179
|
-
* - Uses Node.js `fs.readdirSync` with `withFileTypes: true` for efficient directory traversal.
|
|
742
|
+
* This utility type describes a class constructor that accepts any number of arguments
|
|
743
|
+
* and returns any instance type. Useful for mixins or generic factory functions.
|
|
2180
744
|
*
|
|
2181
745
|
* @example
|
|
2182
746
|
* ```ts
|
|
2183
|
-
*
|
|
2184
|
-
*
|
|
2185
|
-
*
|
|
2186
|
-
*
|
|
2187
|
-
*
|
|
2188
|
-
* // "README.md",
|
|
2189
|
-
* // "guide/intro.md",
|
|
2190
|
-
* // "tutorial/setup.md"
|
|
2191
|
-
* // ]
|
|
747
|
+
* function WithTimestamp<TBase extends ConstructorType>(Base: TBase) {
|
|
748
|
+
* return class extends Base {
|
|
749
|
+
* timestamp = Date.now();
|
|
750
|
+
* };
|
|
751
|
+
* }
|
|
2192
752
|
* ```
|
|
2193
753
|
*
|
|
2194
754
|
* @since 2.0.0
|
|
2195
755
|
*/
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
/**
|
|
2199
|
-
* Import will remove at compile time
|
|
2200
|
-
*/
|
|
756
|
+
type ConstructorType = new (...args: Array<any>) => any;
|
|
2201
757
|
/**
|
|
2202
|
-
*
|
|
758
|
+
* A type representing a function with a specific return type, arguments, and optional context.
|
|
2203
759
|
*
|
|
2204
|
-
* @
|
|
2205
|
-
* @
|
|
2206
|
-
* @
|
|
760
|
+
* @typeParam Return - The type returned by the function. Defaults to `unknown`.
|
|
761
|
+
* @typeParam Args - A tuple of argument types for the function. Defaults to an empty array `[]`.
|
|
762
|
+
* @typeParam Context - The type of `this` context for the function. Defaults to `unknown`.
|
|
2207
763
|
*
|
|
2208
764
|
* @remarks
|
|
2209
|
-
* This
|
|
2210
|
-
* multi-version documentation navigation. It processes each sidebar item according to
|
|
2211
|
-
* specific rules:
|
|
2212
|
-
*
|
|
2213
|
-
* **Skipped items** (returned unchanged):
|
|
2214
|
-
* - Items with `skipVersioning: true` flag
|
|
2215
|
-
* - Items with external links (starting with 'http')
|
|
2216
|
-
* - Items without links or nested items
|
|
2217
|
-
* - Items when a version is empty or 'root'
|
|
2218
|
-
*
|
|
2219
|
-
* **Processed items**:
|
|
2220
|
-
* - The base path is prepended with a version: `/{version}/{base}/`
|
|
2221
|
-
* - Original item properties are preserved via spread operator
|
|
2222
|
-
* - The normalized version replaces 'root' with empty string
|
|
2223
|
-
*
|
|
2224
|
-
* The base path structure follows the pattern: `/{version}/{originalBase}/`
|
|
2225
|
-
* using {@link join} from path/posix for consistent URL formatting across platforms.
|
|
765
|
+
* This type allows you to strongly type functions with a specific `this` context and arguments.
|
|
2226
766
|
*
|
|
2227
767
|
* @example
|
|
2228
768
|
* ```ts
|
|
2229
|
-
* const
|
|
2230
|
-
*
|
|
2231
|
-
*
|
|
2232
|
-
* { text: 'External', link: 'https://example.com' },
|
|
2233
|
-
* { text: 'Skip', link: '/skip/', skipVersioning: true }
|
|
2234
|
-
* ];
|
|
2235
|
-
*
|
|
2236
|
-
* const versioned = populateSidebar(sidebar, 'v2.0');
|
|
2237
|
-
* // [
|
|
2238
|
-
* // { text: 'Guide', link: '/guide/', base: '/v2.0/docs/' },
|
|
2239
|
-
* // { text: 'API', link: '/api/', base: '/v2.0/reference/' },
|
|
2240
|
-
* // { text: 'External', link: 'https://example.com' },
|
|
2241
|
-
* // { text: 'Skip', link: '/skip/', skipVersioning: true }
|
|
2242
|
-
* // ]
|
|
2243
|
-
*
|
|
2244
|
-
* // Root version (no prefix)
|
|
2245
|
-
* const rootVersioned = populateSidebar(sidebar, 'root');
|
|
2246
|
-
* // Base paths remain unchanged
|
|
2247
|
-
*
|
|
2248
|
-
* // Use case: Version-specific sidebar configuration
|
|
2249
|
-
* const versions = ['v1.0', 'v2.0', 'latest'];
|
|
2250
|
-
* const sidebarConfigs = versions.map(version => ({
|
|
2251
|
-
* version,
|
|
2252
|
-
* items: populateSidebar(baseSidebar, version)
|
|
2253
|
-
* }));
|
|
769
|
+
* const fn: FunctionLikeType<number, [string, string], { prefix: string }> = function(this, a, b) {
|
|
770
|
+
* return (this.prefix + a + b).length;
|
|
771
|
+
* }
|
|
2254
772
|
* ```
|
|
2255
773
|
*
|
|
2256
|
-
* @
|
|
2257
|
-
* @since 2.0.5
|
|
774
|
+
* @since 2.0.0
|
|
2258
775
|
*/
|
|
2259
|
-
|
|
776
|
+
type FunctionLikeType<Return = unknown, Args extends Array<unknown> = [
|
|
777
|
+
], Context = unknown> = (this: Context, ...args: Args) => Return;
|
|
2260
778
|
/**
|
|
2261
|
-
*
|
|
779
|
+
* A type representing a constructor with specific arguments and return type.
|
|
2262
780
|
*
|
|
2263
|
-
* @
|
|
2264
|
-
* @
|
|
2265
|
-
* @param versionsList - List of valid version identifiers for matching.
|
|
2266
|
-
* @returns An object containing extracted language and version {@link PathSegmentsInterface}.
|
|
781
|
+
* @typeParam Return - The instance type returned by the constructor. Defaults to `unknown`.
|
|
782
|
+
* @typeParam Args - A tuple of argument types for the constructor. Defaults to an empty array `[]`.
|
|
2267
783
|
*
|
|
2268
784
|
* @remarks
|
|
2269
|
-
* This
|
|
2270
|
-
* information, supporting both version-first and locale-first URL structures. The
|
|
2271
|
-
* function operates on the segment array destructively, removing matched elements
|
|
2272
|
-
* via {@link Array.shift}.
|
|
2273
|
-
*
|
|
2274
|
-
* **Parsing logic**:
|
|
2275
|
-
* 1. If the first segment matches a version → return `{ lang: '', version }` (version-first pattern)
|
|
2276
|
-
* 2. If the first segment matches a locale → extract it as `lang` (locale-first pattern)
|
|
2277
|
-
* 3. If the second segment matches a version → extract it as `version`
|
|
2278
|
-
* 4. Return both extracted values (empty strings if not found)
|
|
2279
|
-
*
|
|
2280
|
-
* **URL patterns supported**:
|
|
2281
|
-
* - `/v2.0/guide/` → `{ lang: '', version: 'v2.0' }`
|
|
2282
|
-
* - `/fr/v2.0/guide/` → `{ lang: 'fr', version: 'v2.0' }`
|
|
2283
|
-
* - `/fr/guide/` → `{ lang: 'fr', version: '' }`
|
|
2284
|
-
* - `/guide/` → `{ lang: '', version: '' }`
|
|
2285
|
-
*
|
|
2286
|
-
* The segment array is mutated during extraction, with matched segments removed
|
|
2287
|
-
* from the beginning. This allows the following processing to work with the remaining
|
|
2288
|
-
* path components.
|
|
785
|
+
* This type allows strong typing of class constructors with defined argument types.
|
|
2289
786
|
*
|
|
2290
787
|
* @example
|
|
2291
788
|
* ```ts
|
|
2292
|
-
*
|
|
2293
|
-
*
|
|
2294
|
-
*
|
|
2295
|
-
*
|
|
2296
|
-
* const
|
|
2297
|
-
* const
|
|
2298
|
-
* console.log(result1); // { lang: '', version: 'v2.0' }
|
|
2299
|
-
* console.log(segments1); // ['guide', 'intro']
|
|
2300
|
-
*
|
|
2301
|
-
* // Locale-first pattern
|
|
2302
|
-
* const segments2 = ['fr', 'v2.0', 'api', 'reference'];
|
|
2303
|
-
* const result2 = extractLocale(segments2, localesList, versionsList);
|
|
2304
|
-
* console.log(result2); // { lang: 'fr', version: 'v2.0' }
|
|
2305
|
-
* console.log(segments2); // ['api', 'reference']
|
|
2306
|
-
*
|
|
2307
|
-
* // No locale or version
|
|
2308
|
-
* const segments3 = ['docs', 'getting-started'];
|
|
2309
|
-
* const result3 = extractLocale(segments3, localesList, versionsList);
|
|
2310
|
-
* console.log(result3); // { lang: '', version: '' }
|
|
2311
|
-
* console.log(segments3); // ['docs', 'getting-started']
|
|
2312
|
-
*
|
|
2313
|
-
* // Use case: URL parsing for routing
|
|
2314
|
-
* const url = '/de/latest/guide/installation';
|
|
2315
|
-
* const segments = url.split('/').filter(Boolean);
|
|
2316
|
-
* const { lang, version } = extractLocale(
|
|
2317
|
-
* segments,
|
|
2318
|
-
* ['en', 'de', 'fr'],
|
|
2319
|
-
* ['latest', 'v1', 'v2']
|
|
2320
|
-
* );
|
|
2321
|
-
* const route = segments.join('/');
|
|
2322
|
-
* console.log({ lang, version, route });
|
|
2323
|
-
* // { lang: 'de', version: 'latest', route: 'guide/installation' }
|
|
789
|
+
* class MyClass {
|
|
790
|
+
* constructor(public name: string) {}
|
|
791
|
+
* }
|
|
792
|
+
*
|
|
793
|
+
* const ctor: ConstructorLikeType<MyClass, [string]> = MyClass;
|
|
794
|
+
* const instance = new ctor("Hello");
|
|
2324
795
|
* ```
|
|
2325
796
|
*
|
|
2326
|
-
* @
|
|
2327
|
-
* @since 2.0.5
|
|
797
|
+
* @since 2.0.0
|
|
2328
798
|
*/
|
|
2329
|
-
|
|
799
|
+
type ConstructorLikeType<Return = unknown, Args extends Array<unknown> = [
|
|
800
|
+
]> = new (...args: Args) => Return;
|
|
2330
801
|
/**
|
|
2331
|
-
*
|
|
802
|
+
* Recursively makes all properties of a type optional.
|
|
2332
803
|
*
|
|
2333
|
-
* @
|
|
2334
|
-
* @param results - Accumulator object to store normalized sidebar entries {@link SidebarObjectType}.
|
|
2335
|
-
* @param sidebar - The sidebar configuration to normalize {@link SidebarType}.
|
|
2336
|
-
* @param prefix - Locale prefix for the sidebar (e.g., 'root', 'fr', 'de').
|
|
804
|
+
* @typeParam T - The type to transform into a deeply partial type.
|
|
2337
805
|
*
|
|
2338
806
|
* @remarks
|
|
2339
|
-
* This
|
|
2340
|
-
*
|
|
2341
|
-
* handles both array-based and object-based sidebar definitions.
|
|
2342
|
-
*
|
|
2343
|
-
* **Input formats supported**:
|
|
2344
|
-
* - **Array format**: Simple list of sidebar items for a single path
|
|
2345
|
-
* - **Object format**: Key-value pairs where keys are paths and values are sidebar items
|
|
2346
|
-
* - **Undefined**: Gracefully handles missing sidebar configuration
|
|
2347
|
-
*
|
|
2348
|
-
* **Normalization process**:
|
|
2349
|
-
* 1. Early return if the sidebar is undefined
|
|
2350
|
-
* 2. Convert the 'root' prefix to an empty string for URL normalization
|
|
2351
|
-
* 3. For array format: Store items under the normalized path
|
|
2352
|
-
* 4. For object format: Parse each key to extract locale/version using {@link extractLocale}
|
|
2353
|
-
* 5. Filter entries that don't match the current locale prefix
|
|
2354
|
-
* 6. Construct versioned paths and store items in the result accumulator
|
|
2355
|
-
*
|
|
2356
|
-
* **Results structure**:
|
|
2357
|
-
* ```ts
|
|
2358
|
-
* {
|
|
2359
|
-
* 'root': { '/': [...items], '/guide/': [...items] },
|
|
2360
|
-
* 'fr': { '/fr/': [...items], '/fr/guide/': [...items] },
|
|
2361
|
-
* 'fr/v2.0': { '/fr/v2.0/': [...items] }
|
|
2362
|
-
* }
|
|
2363
|
-
* ```
|
|
807
|
+
* This type is similar to TypeScript's built-in `Partial<T>`, but it applies recursively
|
|
808
|
+
* to all nested objects. Arrays and other non-object types are left unchanged.
|
|
2364
809
|
*
|
|
2365
|
-
*
|
|
2366
|
-
*
|
|
2367
|
-
* - {@link StateModel.versionsList} for valid version identifiers
|
|
810
|
+
* Use `DeepPartialType` when you need to work with objects where only some properties,
|
|
811
|
+
* including nested properties, may be provided.
|
|
2368
812
|
*
|
|
2369
813
|
* @example
|
|
2370
814
|
* ```ts
|
|
2371
|
-
*
|
|
2372
|
-
*
|
|
815
|
+
* interface User {
|
|
816
|
+
* name: string;
|
|
817
|
+
* address: {
|
|
818
|
+
* street: string;
|
|
819
|
+
* city: string;
|
|
820
|
+
* };
|
|
821
|
+
* }
|
|
2373
822
|
*
|
|
2374
|
-
*
|
|
2375
|
-
*
|
|
2376
|
-
*
|
|
2377
|
-
* { text: 'API', link: '/api/' }
|
|
2378
|
-
* ];
|
|
2379
|
-
* normalizeSidebar(state, results, arraySidebar, 'root');
|
|
2380
|
-
* // results = { 'root': { '/': [{ text: 'Guide', ... }, { text: 'API', ... }] } }
|
|
2381
|
-
*
|
|
2382
|
-
* // Object format sidebar
|
|
2383
|
-
* const objectSidebar = {
|
|
2384
|
-
* '/': [{ text: 'Home', link: '/' }],
|
|
2385
|
-
* '/guide/': [{ text: 'Getting Started', link: '/guide/start' }],
|
|
2386
|
-
* '/fr/guide/': [{ text: 'Commencer', link: '/fr/guide/start' }]
|
|
823
|
+
* const partialUser: DeepPartialType<User> = {
|
|
824
|
+
* name: "Alice",
|
|
825
|
+
* address: { city: "Wonderland" }
|
|
2387
826
|
* };
|
|
2388
|
-
* normalizeSidebar(state, results, objectSidebar, 'root');
|
|
2389
|
-
*
|
|
2390
|
-
* // With locale prefix
|
|
2391
|
-
* normalizeSidebar(state, results, objectSidebar, 'fr');
|
|
2392
|
-
* // Only '/fr/guide/' entries are processed
|
|
2393
|
-
*
|
|
2394
|
-
* // Use case: Multi-locale sidebar processing
|
|
2395
|
-
* const results = {};
|
|
2396
|
-
* const locales = ['root', 'fr', 'de'];
|
|
2397
|
-
* for (const locale of locales) {
|
|
2398
|
-
* const sidebar = getLocaleSidebar(locale);
|
|
2399
|
-
* normalizeSidebar(state, results, sidebar, locale);
|
|
2400
|
-
* }
|
|
2401
827
|
* ```
|
|
2402
828
|
*
|
|
2403
|
-
* @
|
|
2404
|
-
* @see SidebarType
|
|
2405
|
-
* @see extractLocale
|
|
2406
|
-
* @see SidebarObjectType
|
|
2407
|
-
*
|
|
2408
|
-
* @since 2.0.5
|
|
829
|
+
* @since 2.0.0
|
|
2409
830
|
*/
|
|
2410
|
-
|
|
831
|
+
type DeepPartialType<T> = T extends object ? {
|
|
832
|
+
[P in keyof T]?: DeepPartialType<T[P]>;
|
|
833
|
+
} : T;
|
|
2411
834
|
/**
|
|
2412
|
-
*
|
|
835
|
+
* Makes specific keys of a type required while leaving the rest unchanged.
|
|
2413
836
|
*
|
|
2414
|
-
* @
|
|
2415
|
-
* @
|
|
837
|
+
* @typeParam T - The base type.
|
|
838
|
+
* @typeParam K - The subset of keys from `T` that should be required.
|
|
2416
839
|
*
|
|
2417
840
|
* @remarks
|
|
2418
|
-
* This
|
|
2419
|
-
*
|
|
2420
|
-
*
|
|
2421
|
-
*
|
|
2422
|
-
*
|
|
2423
|
-
* **Processing stages**:
|
|
2424
|
-
* 1. **Initial Normalization**: Process sidebars from global theme config and each locale's
|
|
2425
|
-
* theme config using {@link normalizeSidebar}
|
|
2426
|
-
* 2. **Version Propagation**: For each locale entry in {@link StateModel.vitepressConfig},
|
|
2427
|
-
* if it lacks a normalized sidebar, inherit from its parent locale
|
|
2428
|
-
* 3. **Path Adjustment**: Adjust inherited paths to include the version/locale prefix
|
|
2429
|
-
*
|
|
2430
|
-
* **Data sources processed**:
|
|
2431
|
-
* - {@link StateModel.configuration.themeConfig.sidebar}: Global sidebar configuration
|
|
2432
|
-
* - Each locale's `themeConfig.sidebar`: Locale-specific sidebar configuration
|
|
2433
|
-
*
|
|
2434
|
-
* **Output structure**:
|
|
2435
|
-
* ```ts
|
|
2436
|
-
* {
|
|
2437
|
-
* 'root': { '/': [...], '/guide/': [...] },
|
|
2438
|
-
* 'v2.0': { '/v2.0/': [...], '/v2.0/guide/': [...] },
|
|
2439
|
-
* 'fr': { '/fr/': [...], '/fr/guide/': [...] },
|
|
2440
|
-
* 'fr/v2.0': { '/fr/v2.0/': [...], '/fr/v2.0/guide/': [...] }
|
|
2441
|
-
* }
|
|
2442
|
-
* ```
|
|
2443
|
-
*
|
|
2444
|
-
* The function ensures that every locale entry in the VitePress configuration has
|
|
2445
|
-
* appropriate sidebar items, either directly defined or inherited from parent locales.
|
|
2446
|
-
* This enables consistent navigation across all versions and locales.
|
|
841
|
+
* This utility type is useful when you want to enforce that certain properties
|
|
842
|
+
* of a type are mandatory, without affecting the optionality of other properties.
|
|
843
|
+
* It works by combining:
|
|
844
|
+
* - `Omit<T, K>` to remove the keys that will become required.
|
|
845
|
+
* - `Required<Pick<T, K>>` to mark the specified keys as required.
|
|
2447
846
|
*
|
|
2448
847
|
* @example
|
|
2449
848
|
* ```ts
|
|
2450
|
-
*
|
|
2451
|
-
*
|
|
2452
|
-
*
|
|
2453
|
-
*
|
|
2454
|
-
* '/guide/': [{ text: 'Guide', link: '/guide/' }]
|
|
2455
|
-
* }
|
|
2456
|
-
* },
|
|
2457
|
-
* locales: {
|
|
2458
|
-
* root: { lang: 'en-US' },
|
|
2459
|
-
* '/fr/': {
|
|
2460
|
-
* lang: 'fr-FR',
|
|
2461
|
-
* themeConfig: {
|
|
2462
|
-
* sidebar: {
|
|
2463
|
-
* '/fr/guide/': [{ text: 'Guide', link: '/fr/guide/' }]
|
|
2464
|
-
* }
|
|
2465
|
-
* }
|
|
2466
|
-
* }
|
|
2467
|
-
* },
|
|
2468
|
-
* versionsConfig: {
|
|
2469
|
-
* sources: 'src',
|
|
2470
|
-
* archive: 'versions'
|
|
2471
|
-
* }
|
|
2472
|
-
* }).init();
|
|
2473
|
-
*
|
|
2474
|
-
* const normalized = normalizeSidebars(state);
|
|
2475
|
-
*
|
|
2476
|
-
* console.log(Object.keys(normalized));
|
|
2477
|
-
* // ['root', 'v1.0', 'v2.0', 'fr', 'fr/v1.0', 'fr/v2.0']
|
|
2478
|
-
*
|
|
2479
|
-
* console.log(normalized['v2.0']);
|
|
2480
|
-
* // { '/v2.0/': [...], '/v2.0/guide/': [...] }
|
|
2481
|
-
*
|
|
2482
|
-
* console.log(normalized['fr/v2.0']);
|
|
2483
|
-
* // { '/fr/v2.0/': [...], '/fr/v2.0/guide/': [...] }
|
|
2484
|
-
*
|
|
2485
|
-
* // Use case: Building a complete sidebar structure
|
|
2486
|
-
* const state = inject(StateModel);
|
|
2487
|
-
* const sidebars = normalizeSidebars(state);
|
|
2488
|
-
*
|
|
2489
|
-
* // Apply to VitePress config
|
|
2490
|
-
* for (const [locale, paths] of Object.entries(sidebars)) {
|
|
2491
|
-
* vitepressConfig.locales[locale].themeConfig.sidebar = paths;
|
|
849
|
+
* interface User {
|
|
850
|
+
* id?: number;
|
|
851
|
+
* name?: string;
|
|
852
|
+
* email?: string;
|
|
2492
853
|
* }
|
|
2493
|
-
* ```
|
|
2494
|
-
*
|
|
2495
|
-
* @see StateModel
|
|
2496
|
-
* @see extractLocale
|
|
2497
|
-
* @see normalizeSidebar
|
|
2498
|
-
* @see SidebarObjectType
|
|
2499
|
-
*
|
|
2500
|
-
* @since 2.0.5
|
|
2501
|
-
*/
|
|
2502
|
-
declare function normalizeSidebars(state: StateModel): Record<string, SidebarObjectType>;
|
|
2503
|
-
/**
|
|
2504
|
-
* Parses and applies sidebar configurations to all locales in the VitePress configuration.
|
|
2505
854
|
*
|
|
2506
|
-
*
|
|
2507
|
-
*
|
|
2508
|
-
* multi-locale documentation system. It coordinates the complete sidebar normalization
|
|
2509
|
-
* and population workflow by:
|
|
2510
|
-
*
|
|
2511
|
-
* 1. **Injecting State**: Retrieves the {@link StateModel} singleton instance
|
|
2512
|
-
* 2. **Normalizing**: Calls {@link normalizeSidebars} to process all sidebar configurations
|
|
2513
|
-
* 3. **Applying**: Iterates through each locale in {@link StateModel.vitepressConfig.locales}
|
|
2514
|
-
* 4. **Populating**: Uses {@link populateSidebar} to add version-specific base paths
|
|
2515
|
-
* 5. **Merging**: Assigns processed sidebars to each locale's theme configuration
|
|
2516
|
-
*
|
|
2517
|
-
* **Sidebar structure handling**:
|
|
2518
|
-
* - Initializes `themeConfig` if it doesn't exist
|
|
2519
|
-
* - Converts array-based sidebars to object format for consistent processing
|
|
2520
|
-
* - Preserves existing sidebar structure when no normalized version exists
|
|
2521
|
-
* - Ensures sidebar is always in object format after processing
|
|
2522
|
-
*
|
|
2523
|
-
* The function modifies the VitePress configuration in place, updating each locale's
|
|
2524
|
-
* `themeConfig.sidebar` with the normalized and versioned sidebar items. This ensures
|
|
2525
|
-
* that all routes have appropriate navigation structures.
|
|
2526
|
-
*
|
|
2527
|
-
* **Processing flow**:
|
|
2528
|
-
* ```
|
|
2529
|
-
* User Config → normalizeSidebars() → Normalized Structure
|
|
2530
|
-
* ↓
|
|
2531
|
-
* VitePress Config ← populateSidebar() ← Per-Locale Items
|
|
2532
|
-
* ```
|
|
855
|
+
* // Make 'id' and 'name' required, 'email' remains optional
|
|
856
|
+
* type UserWithRequiredIdName = RequireKeysType<User, 'id' | 'name'>;
|
|
2533
857
|
*
|
|
2534
|
-
*
|
|
2535
|
-
*
|
|
2536
|
-
*
|
|
2537
|
-
* const config = {
|
|
2538
|
-
* themeConfig: {
|
|
2539
|
-
* sidebar: {
|
|
2540
|
-
* '/': [{ text: 'Home', link: '/' }],
|
|
2541
|
-
* '/guide/': [{ text: 'Getting Started', link: '/guide/start' }]
|
|
2542
|
-
* }
|
|
2543
|
-
* },
|
|
2544
|
-
* locales: {
|
|
2545
|
-
* root: { lang: 'en-US', label: 'English' },
|
|
2546
|
-
* '/fr/': {
|
|
2547
|
-
* lang: 'fr-FR',
|
|
2548
|
-
* label: 'Français',
|
|
2549
|
-
* themeConfig: {
|
|
2550
|
-
* sidebar: {
|
|
2551
|
-
* '/fr/guide/': [{ text: 'Commencer', link: '/fr/guide/start' }]
|
|
2552
|
-
* }
|
|
2553
|
-
* }
|
|
2554
|
-
* }
|
|
2555
|
-
* }
|
|
858
|
+
* const user: UserWithRequiredIdName = {
|
|
859
|
+
* id: 1,
|
|
860
|
+
* name: "Alice"
|
|
2556
861
|
* };
|
|
2557
|
-
*
|
|
2558
|
-
* const state = new StateModel(config).init();
|
|
2559
|
-
* provide(StateModel, state);
|
|
2560
|
-
*
|
|
2561
|
-
* // Parse and apply sidebars
|
|
2562
|
-
* parseSidebars();
|
|
2563
|
-
*
|
|
2564
|
-
* // Result: Each locale now has versioned sidebars
|
|
2565
|
-
* console.log(state.vitepressConfig.locales['v2.0'].themeConfig.sidebar);
|
|
2566
|
-
* // {
|
|
2567
|
-
* // '/v2.0/': [{ text: 'Home', link: '/', base: '/v2.0/' }],
|
|
2568
|
-
* // '/v2.0/guide/': [{ text: 'Getting Started', link: '/guide/start', base: '/v2.0/guide/' }]
|
|
2569
|
-
* // }
|
|
2570
|
-
*
|
|
2571
|
-
* console.log(state.vitepressConfig.locales['fr/v2.0'].themeConfig.sidebar);
|
|
2572
|
-
* // {
|
|
2573
|
-
* // '/fr/v2.0/guide/': [{ text: 'Commencer', link: '/fr/guide/start', base: '/fr/v2.0/guide/' }]
|
|
2574
|
-
* // }
|
|
2575
|
-
*
|
|
2576
|
-
* // Use case: Integration in VitePress config hook
|
|
2577
|
-
* export default defineConfig({
|
|
2578
|
-
* async buildStart() {
|
|
2579
|
-
* parseSidebars();
|
|
2580
|
-
* },
|
|
2581
|
-
* // ... rest of config
|
|
2582
|
-
* });
|
|
2583
862
|
* ```
|
|
2584
863
|
*
|
|
2585
|
-
* @
|
|
2586
|
-
* @see populateSidebar
|
|
2587
|
-
* @see normalizeSidebars
|
|
2588
|
-
*
|
|
2589
|
-
* @since 2.0.5
|
|
864
|
+
* @since 2.0.0
|
|
2590
865
|
*/
|
|
2591
|
-
|
|
866
|
+
type RequireKeysType<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
867
|
+
declare function defineVersionedConfig(userConfiguration: PartialConfigurationType): UserConfig;
|
|
868
|
+
|
|
869
|
+
export {
|
|
870
|
+
ConfigurationInterface,
|
|
871
|
+
LocaleInterface,
|
|
872
|
+
LocalesInterface,
|
|
873
|
+
NavItemComponentType,
|
|
874
|
+
NavItemType,
|
|
875
|
+
NavItemWithChildrenType,
|
|
876
|
+
NavItemWithLinkType,
|
|
877
|
+
NavObjectType,
|
|
878
|
+
NavType,
|
|
879
|
+
PartialConfigurationType,
|
|
880
|
+
PathSidebarInterface,
|
|
881
|
+
SidebarGroupInterface,
|
|
882
|
+
SidebarItemType,
|
|
883
|
+
SidebarObjectType,
|
|
884
|
+
SidebarType,
|
|
885
|
+
ThemeInterface,
|
|
886
|
+
VersionsConfigInterface,
|
|
887
|
+
VersionsHooksInterface,
|
|
888
|
+
VersionsSwitcherInterface,
|
|
889
|
+
VitepressConfigInterface,
|
|
890
|
+
VitepressConfigType,
|
|
891
|
+
defineVersionedConfig
|
|
892
|
+
};
|