@viteplus/versions 1.0.0 → 2.0.1
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 +136 -106
- package/components/version-switcher.component.vue +128 -108
- package/dist/index.d.ts +1763 -214
- package/dist/index.js +2 -2
- package/dist/index.js.map +5 -5
- package/package.json +19 -6
package/dist/index.d.ts
CHANGED
|
@@ -4,410 +4,1959 @@
|
|
|
4
4
|
* DO NOT EDIT MANUALLY.
|
|
5
5
|
*/
|
|
6
6
|
import type { UserConfig } from 'vitepress';
|
|
7
|
+
export type * from 'vitepress';
|
|
7
8
|
import type { DefaultTheme, UserConfig } from 'vitepress';
|
|
8
9
|
import type { DefaultTheme } from 'vitepress';
|
|
10
|
+
import type { LocaleSpecificConfig } from 'vitepress';
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* Import will remove at compile time
|
|
12
14
|
*/
|
|
13
15
|
/**
|
|
14
|
-
*
|
|
16
|
+
* Export interfaces
|
|
15
17
|
*/
|
|
18
|
+
export declare function defineVersionedConfig(userConfiguration: PartialConfigurationType): UserConfig;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Import will remove at compile time
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* Defines hooks for version- and locale-specific behavior.
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* The `rewritesHook` function allows you to programmatically rewrite
|
|
28
|
+
* paths or content based on the documentation version and locale being served.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const hooks: VersionsHooksInterface = {
|
|
33
|
+
* rewritesHook: (source, version, locale) =>
|
|
34
|
+
* `${version}/${locale}/${source}`
|
|
35
|
+
* };
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @since 2.0.0
|
|
39
|
+
*/
|
|
40
|
+
export interface VersionsHooksInterface {
|
|
41
|
+
/**
|
|
42
|
+
* A function that rewrites a source path based on version and locale.
|
|
43
|
+
*
|
|
44
|
+
* @param source - The original file path or source string.
|
|
45
|
+
* @param version - The current documentation version (e.g., "2.0").
|
|
46
|
+
* @param locale - The locale code or folder name (e.g., "en", "de").
|
|
47
|
+
*
|
|
48
|
+
* @returns The rewritten path string, which can be used for routing or file organization.
|
|
49
|
+
*
|
|
50
|
+
* @remarks
|
|
51
|
+
* This hook is invoked whenever paths need to be version- and locale-aware,
|
|
52
|
+
* allowing complete control over URL or file structure.
|
|
53
|
+
*
|
|
54
|
+
* @since 2.0.0
|
|
55
|
+
*/
|
|
56
|
+
rewritesHook(source: string, version: string, locale: string): string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Configuration for a version switcher component.
|
|
60
|
+
*
|
|
61
|
+
* @remarks
|
|
62
|
+
* - `text` is the display label for the version switcher.
|
|
63
|
+
* - `includeCurrentVersion` determines whether the currently active version
|
|
64
|
+
* should appear in the switcher dropdown.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* const switcher: VersionsSwitcherInterface = {
|
|
69
|
+
* text: "Version",
|
|
70
|
+
* includeCurrentVersion: true
|
|
71
|
+
* };
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @since 2.0.0
|
|
75
|
+
*/
|
|
76
|
+
export interface VersionsSwitcherInterface {
|
|
77
|
+
/**
|
|
78
|
+
* The display label for the version switcher component.
|
|
79
|
+
*
|
|
80
|
+
* @remarks
|
|
81
|
+
* This text is shown in the UI as the version selector label.
|
|
82
|
+
*
|
|
83
|
+
* @since 2.0.0
|
|
84
|
+
*/
|
|
85
|
+
text: string;
|
|
86
|
+
/**
|
|
87
|
+
* Determines whether the currently active version should appear in the switcher dropdown.
|
|
88
|
+
*
|
|
89
|
+
* @remarks
|
|
90
|
+
* If `true`, the current version will be included; if `false`, it will be omitted.
|
|
91
|
+
*
|
|
92
|
+
* @since 2.0.0
|
|
93
|
+
*/
|
|
94
|
+
includeCurrentVersion: boolean;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Configuration for documentation versions.
|
|
98
|
+
*
|
|
99
|
+
* @remarks
|
|
100
|
+
* - `current` specifies the currently active version.
|
|
101
|
+
* - `sources` is the folder or path where current versioned sources reside.
|
|
102
|
+
* - `archive` is the folder or path for archived versions.
|
|
103
|
+
* - `hooks` allows for custom rewriting logic per version.
|
|
104
|
+
* - `versionSwitcher` enables or disables the version switcher, or provides its configuration.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* const versionsConfig: VersionsConfigInterface = {
|
|
109
|
+
* current: "2.0",
|
|
110
|
+
* sources: "src",
|
|
111
|
+
* archive: "archive",
|
|
112
|
+
* hooks: {
|
|
113
|
+
* rewritesHook: (source, version) => `/v${version}/${source}`
|
|
114
|
+
* },
|
|
115
|
+
* versionSwitcher: { text: "Version", includeCurrentVersion: true }
|
|
116
|
+
* };
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* @since 2.0.0
|
|
120
|
+
*/
|
|
121
|
+
export interface VersionsConfigInterface {
|
|
122
|
+
/**
|
|
123
|
+
* The currently active documentation version.
|
|
124
|
+
*
|
|
125
|
+
* @remarks
|
|
126
|
+
* Used to determine which version to serve by default and which version
|
|
127
|
+
* should be highlighted in the version switcher.
|
|
128
|
+
*
|
|
129
|
+
* @since 2.0.0
|
|
130
|
+
*/
|
|
131
|
+
current: string;
|
|
132
|
+
/**
|
|
133
|
+
* The folder or path where the current versioned sources reside.
|
|
134
|
+
*
|
|
135
|
+
* @since 2.0.0
|
|
136
|
+
*/
|
|
137
|
+
sources: string;
|
|
138
|
+
/**
|
|
139
|
+
* The folder or path where archived versions are stored.
|
|
140
|
+
*
|
|
141
|
+
* @since 2.0.0
|
|
142
|
+
*/
|
|
143
|
+
archive: string;
|
|
144
|
+
/**
|
|
145
|
+
* Hooks for custom behavior when working with versioned content.
|
|
146
|
+
*
|
|
147
|
+
* @remarks
|
|
148
|
+
* Currently, supports `rewritesHook`, which can programmatically rewrite
|
|
149
|
+
* paths based on version and locale.
|
|
150
|
+
*
|
|
151
|
+
* @see VersionsHooksInterface
|
|
152
|
+
* @since 2.0.0
|
|
153
|
+
*/
|
|
154
|
+
hooks: VersionsHooksInterface;
|
|
155
|
+
/**
|
|
156
|
+
* Configuration for the version switcher or `false` to disable it.
|
|
157
|
+
*
|
|
158
|
+
* @remarks
|
|
159
|
+
* If enabled, this object defines the switcher text and whether the
|
|
160
|
+
* current version is included in the switcher options.
|
|
161
|
+
*
|
|
162
|
+
* @see VersionsSwitcherInterface
|
|
163
|
+
* @since 2.0.0
|
|
164
|
+
*/
|
|
165
|
+
versionSwitcher: false | VersionsSwitcherInterface;
|
|
166
|
+
}
|
|
16
167
|
/**
|
|
17
|
-
*
|
|
168
|
+
* Main configuration interface for a VitePress site with extended features.
|
|
18
169
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
170
|
+
* @remarks
|
|
171
|
+
* Extends VitePress's `UserConfig` but overrides:
|
|
172
|
+
* - `locales` to use a strongly typed `LocalesInterface`.
|
|
173
|
+
* - `rewrites` to define path rewrites for the site.
|
|
174
|
+
* - `versionsConfig` to manage documentation versions and the version switcher.
|
|
22
175
|
*
|
|
23
|
-
* @
|
|
176
|
+
* @example
|
|
177
|
+
* ```ts
|
|
178
|
+
* const config: ConfigurationInterface = {
|
|
179
|
+
* locales: {
|
|
180
|
+
* en: { link: "/en/", label: "English" },
|
|
181
|
+
* de: { link: "/de/", label: "Deutsch" }
|
|
182
|
+
* },
|
|
183
|
+
* rewrites: {
|
|
184
|
+
* "/old-path": "/new-path"
|
|
185
|
+
* },
|
|
186
|
+
* versionsConfig: {
|
|
187
|
+
* current: "2.0",
|
|
188
|
+
* sources: "src",
|
|
189
|
+
* archive: "archive",
|
|
190
|
+
* hooks: { rewritesHook: (src, ver) => `/v${ver}/${src}` },
|
|
191
|
+
* versionSwitcher: { text: "Version", includeCurrentVersion: true }
|
|
192
|
+
* }
|
|
193
|
+
* };
|
|
194
|
+
* ```
|
|
195
|
+
*
|
|
196
|
+
* @since 2.0.0
|
|
197
|
+
*/
|
|
198
|
+
export interface ConfigurationInterface extends Omit<UserConfig<ThemeInterface>, 'rewrites' | 'locales'> {
|
|
199
|
+
/**
|
|
200
|
+
* Locale-specific configuration for the site.
|
|
201
|
+
*
|
|
202
|
+
* @remarks
|
|
203
|
+
* Uses {@link LocalesInterface} to strongly type each locale's settings.
|
|
204
|
+
*
|
|
205
|
+
* @since 2.0.0
|
|
206
|
+
*/
|
|
207
|
+
locales: LocalesInterface;
|
|
208
|
+
/**
|
|
209
|
+
* Path rewrites for the site.
|
|
210
|
+
*
|
|
211
|
+
* @remarks
|
|
212
|
+
* Maps old paths to new paths, enabling URL restructuring without breaking links.
|
|
213
|
+
*
|
|
214
|
+
* @since 2.0.0
|
|
215
|
+
*/
|
|
216
|
+
rewrites: Record<string, string>;
|
|
217
|
+
/**
|
|
218
|
+
* Versioning configuration for documentation.
|
|
219
|
+
*
|
|
220
|
+
* @remarks
|
|
221
|
+
* Defines the current version, source directory, archive, hooks, and version switcher behavior.
|
|
222
|
+
*
|
|
223
|
+
* @see VersionsConfigInterface
|
|
224
|
+
* @since 2.0.0
|
|
225
|
+
*/
|
|
226
|
+
versionsConfig: VersionsConfigInterface;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Represents a deeply partial version of the `ConfigurationInterface`.
|
|
230
|
+
*
|
|
231
|
+
* @remarks
|
|
232
|
+
* This type allows any property of `ConfigurationInterface` to be optional,
|
|
233
|
+
* including all nested properties. It is based on the `DeepPartialType` utility type.
|
|
234
|
+
*
|
|
235
|
+
* Useful for scenarios where you want to provide only a subset of the configuration,
|
|
236
|
+
* for example, when overriding default settings or merging user-provided options.
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* ```ts
|
|
240
|
+
* const partialConfig: PartialConfigurationType = {
|
|
241
|
+
* locales: {
|
|
242
|
+
* en: { label: "English" }
|
|
243
|
+
* },
|
|
244
|
+
* versionsConfig: {
|
|
245
|
+
* versionSwitcher: { text: "Version" }
|
|
246
|
+
* }
|
|
247
|
+
* };
|
|
248
|
+
* ```
|
|
249
|
+
*
|
|
250
|
+
* @since 2.0.0
|
|
251
|
+
*/
|
|
252
|
+
export type PartialConfigurationType = DeepPartialType<ConfigurationInterface>;
|
|
253
|
+
/**
|
|
254
|
+
* A strongly typed VitePress configuration where specific keys are required.
|
|
255
|
+
*
|
|
256
|
+
* @remarks
|
|
257
|
+
* This type uses {@link RequireKeysType} to ensure that the following properties
|
|
258
|
+
* of `UserConfig<DefaultTheme.Config>` are always present:
|
|
259
|
+
* - `locales`
|
|
260
|
+
* - `rewrites`
|
|
261
|
+
* - `themeConfig`
|
|
262
|
+
*
|
|
263
|
+
* All other properties remain optional, preserving the flexibility of the standard
|
|
264
|
+
* VitePress configuration type.
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* ```ts
|
|
268
|
+
* const config: VitepressConfigType = {
|
|
269
|
+
* locales: { en: { link: "/en/", label: "English" } },
|
|
270
|
+
* rewrites: { "/old-path": "/new-path" },
|
|
271
|
+
* themeConfig: { nav: [], sidebar: {} }
|
|
272
|
+
* };
|
|
273
|
+
* ```
|
|
24
274
|
*
|
|
25
|
-
* @
|
|
26
|
-
|
|
275
|
+
* @since 2.0.0
|
|
276
|
+
*/
|
|
277
|
+
export type VitepressConfigType = RequireKeysType<UserConfig<DefaultTheme.Config>, 'locales' | 'rewrites' | 'themeConfig'>;
|
|
278
|
+
/**
|
|
279
|
+
* Strongly typed VitePress configuration interface with custom locales support.
|
|
27
280
|
*
|
|
28
281
|
* @remarks
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
282
|
+
* Extends {@link VitepressConfigType} but overrides the `locales` property
|
|
283
|
+
* to use a strongly typed {@link LocalesInterface}.
|
|
284
|
+
*
|
|
285
|
+
* This ensures:
|
|
286
|
+
* - `locales` are fully typed with per-locale configurations.
|
|
287
|
+
* - Other required properties from `VitepressConfigType` (`rewrites`, `themeConfig`) remain enforced.
|
|
288
|
+
* - Remaining properties from `UserConfig<DefaultTheme.Config>` retain their optionality.
|
|
36
289
|
*
|
|
37
290
|
* @example
|
|
38
291
|
* ```ts
|
|
39
|
-
*
|
|
292
|
+
* const config: VitepressConfigInterface = {
|
|
293
|
+
* locales: {
|
|
294
|
+
* en: { link: "/en/", label: "English" },
|
|
295
|
+
* de: { link: "/de/", label: "Deutsch" }
|
|
296
|
+
* },
|
|
297
|
+
* rewrites: { "/old-path": "/new-path" },
|
|
298
|
+
* themeConfig: { nav: [], sidebar: {} }
|
|
299
|
+
* };
|
|
300
|
+
* ```
|
|
301
|
+
*
|
|
302
|
+
* @since 2.0.0
|
|
303
|
+
*/
|
|
304
|
+
export interface VitepressConfigInterface extends Omit<VitepressConfigType, 'locales'> {
|
|
305
|
+
/**
|
|
306
|
+
* Locale-specific configuration for the site.
|
|
307
|
+
*
|
|
308
|
+
* @remarks
|
|
309
|
+
* Uses {@link LocalesInterface} to strongly type each locale's settings.
|
|
310
|
+
*
|
|
311
|
+
* @since 2.0.0
|
|
312
|
+
*/
|
|
313
|
+
locales: LocalesInterface;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Import will remove at compile time
|
|
318
|
+
*/
|
|
319
|
+
/**
|
|
320
|
+
* Represents the configuration interface for a VitePress theme.
|
|
321
|
+
*
|
|
322
|
+
* @remarks
|
|
323
|
+
* Extends VitePress's {@link DefaultTheme.Config} type but overrides the
|
|
324
|
+
* `nav` and `sidebar` properties to use custom, strongly typed interfaces
|
|
325
|
+
* ({@link NavType} and {@link SidebarType}).
|
|
40
326
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
327
|
+
* This allows for enhanced type safety and additional functionality such as
|
|
328
|
+
* versioning control in navigation and sidebar items.
|
|
329
|
+
*
|
|
330
|
+
* @example
|
|
331
|
+
* ```ts
|
|
332
|
+
* const themeConfig: ThemeInterface = {
|
|
333
|
+
* nav: [
|
|
334
|
+
* { text: "Home", link: "/" },
|
|
335
|
+
* { text: "Docs", items: [{ text: "Guide", link: "/guide/" }] }
|
|
336
|
+
* ],
|
|
337
|
+
* sidebar: {
|
|
338
|
+
* guide: [
|
|
339
|
+
* { text: "Introduction", link: "/guide/introduction" },
|
|
340
|
+
* { text: "Setup", link: "/guide/setup" }
|
|
341
|
+
* ]
|
|
342
|
+
* },
|
|
343
|
+
* lastUpdated: true
|
|
344
|
+
* };
|
|
47
345
|
* ```
|
|
48
346
|
*
|
|
49
|
-
* @since
|
|
347
|
+
* @since 2.0.0
|
|
50
348
|
*/
|
|
51
|
-
export
|
|
349
|
+
export interface ThemeInterface extends Omit<DefaultTheme.Config, 'nav' | 'sidebar'> {
|
|
350
|
+
/**
|
|
351
|
+
* Navigation structure of the site.
|
|
352
|
+
*
|
|
353
|
+
* @remarks
|
|
354
|
+
* Typed as {@link NavType}, which allows versioning-aware navigation items.
|
|
355
|
+
*
|
|
356
|
+
* @since 2.0.0
|
|
357
|
+
*/
|
|
358
|
+
nav?: NavType;
|
|
359
|
+
/**
|
|
360
|
+
* Sidebar structure of the site.
|
|
361
|
+
*
|
|
362
|
+
* @remarks
|
|
363
|
+
* Typed as {@link SidebarType}, which allows versioning-aware sidebar items.
|
|
364
|
+
*
|
|
365
|
+
* @since 2.0.0
|
|
366
|
+
*/
|
|
367
|
+
sidebar?: SidebarType;
|
|
368
|
+
}
|
|
52
369
|
|
|
53
370
|
/**
|
|
54
371
|
* Import will remove at compile time
|
|
55
372
|
*/
|
|
56
|
-
|
|
373
|
+
/**
|
|
374
|
+
* Represents a component-based navigation item from VitePress.
|
|
375
|
+
*
|
|
376
|
+
* @remarks
|
|
377
|
+
* This type is directly imported from VitePress and allows using custom
|
|
378
|
+
* Vue components as navigation items.
|
|
379
|
+
*
|
|
380
|
+
* @since 2.0.0
|
|
381
|
+
*/
|
|
382
|
+
export type NavItemComponentType = DefaultTheme.NavItemComponent;
|
|
383
|
+
/**
|
|
384
|
+
* Represents a navigation item with a link.
|
|
385
|
+
*
|
|
386
|
+
* @remarks
|
|
387
|
+
* Extends VitePress's {@link DefaultTheme.NavItemWithLink} with an optional
|
|
388
|
+
* `skipVersioning` flag. Use `skipVersioning` to indicate that this
|
|
389
|
+
* navigation item should not be automatically versioned in multi-version
|
|
390
|
+
* documentation setups.
|
|
391
|
+
*
|
|
392
|
+
* @example
|
|
393
|
+
* ```ts
|
|
394
|
+
* const navItem: NavItemWithLinkType = {
|
|
395
|
+
* text: "Home",
|
|
396
|
+
* link: "/",
|
|
397
|
+
* skipVersioning: true
|
|
398
|
+
* };
|
|
399
|
+
* ```
|
|
400
|
+
*
|
|
401
|
+
* @since 2.0.0
|
|
402
|
+
*/
|
|
403
|
+
export type NavItemWithLinkType = DefaultTheme.NavItemWithLink & {
|
|
404
|
+
/**
|
|
405
|
+
* Indicates whether this navigation item should be excluded from automatic versioning.
|
|
406
|
+
*
|
|
407
|
+
* @default false
|
|
408
|
+
* @remarks
|
|
409
|
+
* When set to `true`, this item will remain the same across all documentation versions.
|
|
410
|
+
*
|
|
411
|
+
* @since 2.0.0
|
|
412
|
+
*/
|
|
57
413
|
skipVersioning?: boolean;
|
|
414
|
+
};
|
|
415
|
+
/**
|
|
416
|
+
* Represents a navigation item with children.
|
|
417
|
+
*
|
|
418
|
+
* @remarks
|
|
419
|
+
* Extends VitePress's {@link DefaultTheme.NavItemWithChildren} but requires
|
|
420
|
+
* `items` to be an array of navigation items of various types:
|
|
421
|
+
* - {@link NavItemComponentType}
|
|
422
|
+
* - {@link NavItemWithLinkType}
|
|
423
|
+
* - Recursively, {@link NavItemWithChildrenType}
|
|
424
|
+
*
|
|
425
|
+
* Supports the optional `skipVersioning` flag to exclude the item from automatic
|
|
426
|
+
* versioning in multi-version documentation setups.
|
|
427
|
+
*
|
|
428
|
+
* @example
|
|
429
|
+
* ```ts
|
|
430
|
+
* const nav: NavItemWithChildrenType = {
|
|
431
|
+
* text: "Docs",
|
|
432
|
+
* items: [
|
|
433
|
+
* { text: "Guide", link: "/guide/" },
|
|
434
|
+
* {
|
|
435
|
+
* text: "API",
|
|
436
|
+
* items: [
|
|
437
|
+
* { text: "Functions", link: "/api/functions" }
|
|
438
|
+
* ]
|
|
439
|
+
* }
|
|
440
|
+
* ],
|
|
441
|
+
* skipVersioning: true
|
|
442
|
+
* };
|
|
443
|
+
* ```
|
|
444
|
+
*
|
|
445
|
+
* @since 2.0.0
|
|
446
|
+
*/
|
|
447
|
+
export type NavItemWithChildrenType = Omit<DefaultTheme.NavItemWithChildren, 'items'> & {
|
|
448
|
+
/**
|
|
449
|
+
* Child navigation items for this item.
|
|
450
|
+
*
|
|
451
|
+
* @remarks
|
|
452
|
+
* Can include standard components, link items, or nested child items.
|
|
453
|
+
*
|
|
454
|
+
* @since 2.0.0
|
|
455
|
+
*/
|
|
456
|
+
items: Array<NavItemComponentType | NavItemWithChildrenType | NavItemWithLinkType>;
|
|
457
|
+
/**
|
|
458
|
+
* Indicates whether this navigation item should be excluded from automatic versioning.
|
|
459
|
+
*
|
|
460
|
+
* @default false
|
|
461
|
+
* @remarks
|
|
462
|
+
* When set to `true`, this item and all its children remain unchanged across versions.
|
|
463
|
+
*
|
|
464
|
+
* @since 2.0.0
|
|
465
|
+
*/
|
|
466
|
+
skipVersioning?: boolean;
|
|
467
|
+
};
|
|
468
|
+
/**
|
|
469
|
+
* Represents a single navigation item of any type.
|
|
470
|
+
*
|
|
471
|
+
* @remarks
|
|
472
|
+
* Can be a component, a link, or a navigation item with children.
|
|
473
|
+
*
|
|
474
|
+
* @since 2.0.0
|
|
475
|
+
*/
|
|
476
|
+
export type NavItemType = NavItemComponentType | NavItemWithLinkType | NavItemWithChildrenType;
|
|
477
|
+
/**
|
|
478
|
+
* Represents a record of named navigation groups.
|
|
479
|
+
*
|
|
480
|
+
* @remarks
|
|
481
|
+
* - Each key in the record is a group identifier (commonly a section name or locale).
|
|
482
|
+
* - Each value is an array of {@link NavItemType}, which can include links, components,
|
|
483
|
+
* or nested navigation structures.
|
|
484
|
+
* - Useful for organizing navigation into multiple top-level groups instead of a single array.
|
|
485
|
+
*
|
|
486
|
+
* @example
|
|
487
|
+
* ```ts
|
|
488
|
+
* const nav: NavObjectType = {
|
|
489
|
+
* root: [
|
|
490
|
+
* { text: "Home", link: "/" },
|
|
491
|
+
* { text: "Guide", link: "/guide/" }
|
|
492
|
+
* ],
|
|
493
|
+
* 'v1.0.0': [
|
|
494
|
+
* { text: "Functions", link: "/api/functions" },
|
|
495
|
+
* { text: "Classes", link: "/api/classes" }
|
|
496
|
+
* ]
|
|
497
|
+
* };
|
|
498
|
+
* ```
|
|
499
|
+
*
|
|
500
|
+
* @since 2.0.0
|
|
501
|
+
*/
|
|
502
|
+
export type NavObjectType = Record<string, Array<NavItemType>>;
|
|
503
|
+
/**
|
|
504
|
+
* Represents the navigation structure.
|
|
505
|
+
*
|
|
506
|
+
* @remarks
|
|
507
|
+
* Can be either:
|
|
508
|
+
* - An array of navigation items (`NavItemType[]`), or
|
|
509
|
+
* - A record mapping strings (e.g., section names) to arrays of navigation items.
|
|
510
|
+
*
|
|
511
|
+
* @since 2.0.0
|
|
512
|
+
*/
|
|
513
|
+
export type NavType = Array<NavItemType> | NavObjectType;
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Import will remove at compile time
|
|
517
|
+
*/
|
|
518
|
+
/**
|
|
519
|
+
* Represents a sidebar item from VitePress with optional versioning control.
|
|
520
|
+
*
|
|
521
|
+
* @remarks
|
|
522
|
+
* Extends VitePress's {@link DefaultTheme.SidebarItem} type by adding an optional
|
|
523
|
+
* `skipVersioning` flag. Use this flag to indicate that the item should not be
|
|
524
|
+
* automatically versioned in multi-version documentation setups.
|
|
525
|
+
*
|
|
526
|
+
* @example
|
|
527
|
+
* ```ts
|
|
528
|
+
* const item: SidebarItemType = {
|
|
529
|
+
* text: "Introduction",
|
|
530
|
+
* link: "/guide/introduction",
|
|
531
|
+
* skipVersioning: true
|
|
532
|
+
* };
|
|
533
|
+
* ```
|
|
534
|
+
*
|
|
535
|
+
* @since 2.0.0
|
|
536
|
+
*/
|
|
537
|
+
export type SidebarItemType = DefaultTheme.SidebarItem & {
|
|
538
|
+
/**
|
|
539
|
+
* Determines whether this sidebar item should be excluded from automatic versioning.
|
|
540
|
+
*
|
|
541
|
+
* @default false
|
|
542
|
+
* @remarks
|
|
543
|
+
* When `true`, this sidebar item will remain consistent across all documentation versions.
|
|
544
|
+
*
|
|
545
|
+
* @since 2.0.0
|
|
546
|
+
*/
|
|
547
|
+
skipVersioning?: boolean;
|
|
548
|
+
};
|
|
549
|
+
/**
|
|
550
|
+
* Represents a sidebar group containing multiple sidebar items.
|
|
551
|
+
*
|
|
552
|
+
* @remarks
|
|
553
|
+
* Each group has a `base` path and an array of sidebar items.
|
|
554
|
+
* Useful for organizing related pages under a common path prefix.
|
|
555
|
+
*
|
|
556
|
+
* @example
|
|
557
|
+
* ```ts
|
|
558
|
+
* const group: SidebarGroupInterface = {
|
|
559
|
+
* base: "/guide/",
|
|
560
|
+
* items: [
|
|
561
|
+
* { text: "Introduction", link: "/guide/introduction" },
|
|
562
|
+
* { text: "Setup", link: "/guide/setup" }
|
|
563
|
+
* ]
|
|
564
|
+
* };
|
|
565
|
+
* ```
|
|
566
|
+
*
|
|
567
|
+
* @see SidebarItemType
|
|
568
|
+
* @since 2.0.0
|
|
569
|
+
*/
|
|
570
|
+
export interface SidebarGroupInterface {
|
|
571
|
+
/**
|
|
572
|
+
* The base path for the sidebar group.
|
|
573
|
+
*
|
|
574
|
+
* @remarks
|
|
575
|
+
* This path is prepended to all child sidebar items within the group.
|
|
576
|
+
* Typically corresponds to the folder containing the group’s pages, e.g., `"en"`.
|
|
577
|
+
*
|
|
578
|
+
* @since 2.0.0
|
|
579
|
+
*/
|
|
580
|
+
base: string;
|
|
581
|
+
/**
|
|
582
|
+
* The list of sidebar items within this group.
|
|
583
|
+
*
|
|
584
|
+
* @remarks
|
|
585
|
+
* Each item is typed as {@link SidebarItemType}, which may include links,
|
|
586
|
+
* collapsible sections, or other sidebar elements.
|
|
587
|
+
*
|
|
588
|
+
* @since 2.0.0
|
|
589
|
+
*/
|
|
590
|
+
items: Array<SidebarItemType>;
|
|
58
591
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
592
|
+
/**
|
|
593
|
+
* Represents a mapping of paths to sidebar items or groups.
|
|
594
|
+
*
|
|
595
|
+
* @remarks
|
|
596
|
+
* The keys are path strings, and the values can be either:
|
|
597
|
+
* - An array of sidebar items (`SidebarItemType[]`), or
|
|
598
|
+
* - A sidebar group (`SidebarGroupInterface`).
|
|
599
|
+
*
|
|
600
|
+
* @example
|
|
601
|
+
* ```ts
|
|
602
|
+
* const sidebar: PathSidebarInterface = {
|
|
603
|
+
* guide: [
|
|
604
|
+
* { text: "Intro", link: "/guide/intro" },
|
|
605
|
+
* { text: "Setup", link: "/guide/setup" }
|
|
606
|
+
* ],
|
|
607
|
+
* api: { base: "/api/", items: [ { text: "Functions", link: "/api/functions" } ] }
|
|
608
|
+
* };
|
|
609
|
+
* ```
|
|
610
|
+
*
|
|
611
|
+
* @see SidebarItemType
|
|
612
|
+
* @see SidebarGroupInterface
|
|
613
|
+
*
|
|
614
|
+
* @since 2.0.0
|
|
615
|
+
*/
|
|
616
|
+
export interface PathSidebarInterface {
|
|
617
|
+
[path: string]: Array<SidebarItemType> | SidebarGroupInterface;
|
|
69
618
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
619
|
+
/**
|
|
620
|
+
* Represents the overall sidebar configuration.
|
|
621
|
+
*
|
|
622
|
+
* @remarks
|
|
623
|
+
* Can be defined in one of two ways:
|
|
624
|
+
* - As a flat array of {@link SidebarItemType}, or
|
|
625
|
+
* - As a path-based mapping using {@link PathSidebarInterface}.
|
|
626
|
+
*
|
|
627
|
+
* This flexibility allows defining either a single global sidebar
|
|
628
|
+
* or multiple sidebars scoped to different route prefixes.
|
|
629
|
+
*
|
|
630
|
+
* @example
|
|
631
|
+
* Flat sidebar:
|
|
632
|
+
* ```ts
|
|
633
|
+
* const sidebar: SidebarType = [
|
|
634
|
+
* { text: "Home", link: "/" },
|
|
635
|
+
* { text: "Guide", link: "/guide/" }
|
|
636
|
+
* ];
|
|
637
|
+
* ```
|
|
638
|
+
*
|
|
639
|
+
* @example
|
|
640
|
+
* Path-based sidebars:
|
|
641
|
+
* ```ts
|
|
642
|
+
* const sidebar: SidebarType = {
|
|
643
|
+
* "/guide/": [
|
|
644
|
+
* { text: "Introduction", link: "/guide/introduction" }
|
|
645
|
+
* ],
|
|
646
|
+
* "/api/": [
|
|
647
|
+
* { text: "API Reference", link: "/api/" }
|
|
648
|
+
* ]
|
|
649
|
+
* };
|
|
650
|
+
* ```
|
|
651
|
+
*
|
|
652
|
+
* @see SidebarItemType
|
|
653
|
+
* @see PathSidebarInterface
|
|
654
|
+
*
|
|
655
|
+
* @since 2.0.0
|
|
656
|
+
*/
|
|
657
|
+
export type SidebarType = Array<SidebarItemType> | PathSidebarInterface;
|
|
658
|
+
/**
|
|
659
|
+
* Represents a mapping of paths to sidebar item arrays.
|
|
660
|
+
*
|
|
661
|
+
* @remarks
|
|
662
|
+
* This structure allows defining sidebars on a per-path basis,
|
|
663
|
+
* where each key is a route prefix (e.g., `"/guide/"`) and its value
|
|
664
|
+
* is an array of {@link SidebarItemType}.
|
|
665
|
+
*
|
|
666
|
+
* @example
|
|
667
|
+
* ```ts
|
|
668
|
+
* const sidebars: SidebarObjectType = {
|
|
669
|
+
* "/guide/": [
|
|
670
|
+
* { text: "Introduction", link: "/guide/introduction" },
|
|
671
|
+
* { text: "Setup", link: "/guide/setup" }
|
|
672
|
+
* ],
|
|
673
|
+
* "/api/": [
|
|
674
|
+
* { text: "API Reference", link: "/api/" }
|
|
675
|
+
* ]
|
|
676
|
+
* };
|
|
677
|
+
* ```
|
|
678
|
+
*
|
|
679
|
+
* @see SidebarItemType
|
|
680
|
+
* @since 2.0.0
|
|
681
|
+
*/
|
|
682
|
+
export type SidebarObjectType = Record<string, Array<SidebarItemType>>;
|
|
683
|
+
|
|
684
|
+
/**
|
|
685
|
+
* Import will remove at compile time
|
|
686
|
+
*/
|
|
687
|
+
/**
|
|
688
|
+
* Represents a locale-specific configuration for a VitePress site.
|
|
689
|
+
*
|
|
690
|
+
* @remarks
|
|
691
|
+
* Extends VitePress's `LocaleSpecificConfig` with a custom {@link ThemeInterface}.
|
|
692
|
+
* Adds optional properties:
|
|
693
|
+
* - `link` — the base URL or path for this locale.
|
|
694
|
+
* - `label` — a human-readable label for the locale (e.g., "English", "Deutsch").
|
|
695
|
+
*
|
|
696
|
+
* This interface allows configuring per-locale theme settings, navigation,
|
|
697
|
+
* sidebar, and other locale-specific behavior.
|
|
698
|
+
*
|
|
699
|
+
* @example
|
|
700
|
+
* ```ts
|
|
701
|
+
* const enLocale: LocaleInterface = {
|
|
702
|
+
* link: "/en/",
|
|
703
|
+
* label: "English",
|
|
704
|
+
* themeConfig: {
|
|
705
|
+
* nav: [{ text: "Home", link: "/en/" }],
|
|
706
|
+
* sidebar: { "/en/guide/": [{ text: "Intro", link: "/en/guide/" }] }
|
|
707
|
+
* }
|
|
708
|
+
* };
|
|
709
|
+
* ```
|
|
710
|
+
*
|
|
711
|
+
* @since 2.0.0
|
|
712
|
+
*/
|
|
713
|
+
export interface LocaleInterface extends LocaleSpecificConfig<ThemeInterface> {
|
|
714
|
+
/**
|
|
715
|
+
* The base path for the locale.
|
|
716
|
+
*
|
|
717
|
+
* @default undefined
|
|
718
|
+
* @since 2.0.0
|
|
719
|
+
*/
|
|
720
|
+
link?: string;
|
|
721
|
+
/**
|
|
722
|
+
* A human-readable label for the locale.
|
|
723
|
+
*
|
|
724
|
+
* @default undefined
|
|
725
|
+
* @since 2.0.0
|
|
726
|
+
*/
|
|
727
|
+
label?: string;
|
|
76
728
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
729
|
+
/**
|
|
730
|
+
* Represents a mapping of locale codes to their corresponding locale configurations.
|
|
731
|
+
*
|
|
732
|
+
* @remarks
|
|
733
|
+
* The keys are locale codes (e.g., `"en"`, `"de"`), and the values are `LocaleInterface` objects.
|
|
734
|
+
* Useful for multi-language or localized documentation setups in VitePress.
|
|
735
|
+
*
|
|
736
|
+
* @example
|
|
737
|
+
* ```ts
|
|
738
|
+
* const locales: LocalesInterface = {
|
|
739
|
+
* en: { link: "/en/", label: "English" },
|
|
740
|
+
* de: { link: "/de/", label: "Deutsch" }
|
|
741
|
+
* };
|
|
742
|
+
* ```
|
|
743
|
+
*
|
|
744
|
+
* @see LocaleInterface
|
|
745
|
+
* @since 2.0.0
|
|
746
|
+
*/
|
|
747
|
+
export interface LocalesInterface {
|
|
748
|
+
[key: string]: LocaleInterface;
|
|
82
749
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* A generic type representing a function with any arguments and any return type.
|
|
753
|
+
*
|
|
754
|
+
* @remarks
|
|
755
|
+
* This type is a very flexible function type, allowing any arguments of any type
|
|
756
|
+
* and returning any type. Use with caution, as it bypasses TypeScript's type safety.
|
|
757
|
+
*
|
|
758
|
+
* @example
|
|
759
|
+
* ```ts
|
|
760
|
+
* const exampleFn: FunctionType = (a, b, c) => a + b + c;
|
|
761
|
+
*
|
|
762
|
+
* const anotherFn: FunctionType = (...args) => args.length;
|
|
763
|
+
* ```
|
|
764
|
+
*
|
|
765
|
+
* @since 2.0.0
|
|
766
|
+
*/
|
|
767
|
+
type FunctionType = (...args: Array<any>) => any;
|
|
768
|
+
/**
|
|
769
|
+
* Represents a generic constructor type.
|
|
770
|
+
*
|
|
771
|
+
* @remarks
|
|
772
|
+
* This utility type describes a class constructor that accepts any number of arguments
|
|
773
|
+
* and returns any instance type. Useful for mixins or generic factory functions.
|
|
774
|
+
*
|
|
775
|
+
* @example
|
|
776
|
+
* ```ts
|
|
777
|
+
* function WithTimestamp<TBase extends ConstructorType>(Base: TBase) {
|
|
778
|
+
* return class extends Base {
|
|
779
|
+
* timestamp = Date.now();
|
|
780
|
+
* };
|
|
781
|
+
* }
|
|
782
|
+
* ```
|
|
783
|
+
*
|
|
784
|
+
* @since 2.0.0
|
|
785
|
+
*/
|
|
786
|
+
type ConstructorType = new (...args: Array<any>) => any;
|
|
787
|
+
/**
|
|
788
|
+
* A type representing a function with a specific return type, arguments, and optional context.
|
|
789
|
+
*
|
|
790
|
+
* @typeParam Return - The type returned by the function. Defaults to `unknown`.
|
|
791
|
+
* @typeParam Args - A tuple of argument types for the function. Defaults to an empty array `[]`.
|
|
792
|
+
* @typeParam Context - The type of `this` context for the function. Defaults to `unknown`.
|
|
793
|
+
*
|
|
794
|
+
* @remarks
|
|
795
|
+
* This type allows you to strongly type functions with a specific `this` context and arguments.
|
|
796
|
+
*
|
|
797
|
+
* @example
|
|
798
|
+
* ```ts
|
|
799
|
+
* const fn: FunctionLikeType<number, [string, string], { prefix: string }> = function(this, a, b) {
|
|
800
|
+
* return (this.prefix + a + b).length;
|
|
801
|
+
* }
|
|
802
|
+
* ```
|
|
803
|
+
*
|
|
804
|
+
* @since 2.0.0
|
|
805
|
+
*/
|
|
806
|
+
type FunctionLikeType<Return = unknown, Args extends Array<unknown> = [], Context = unknown> = (this: Context, ...args: Args) => Return;
|
|
807
|
+
/**
|
|
808
|
+
* A type representing a constructor with specific arguments and return type.
|
|
809
|
+
*
|
|
810
|
+
* @typeParam Return - The instance type returned by the constructor. Defaults to `unknown`.
|
|
811
|
+
* @typeParam Args - A tuple of argument types for the constructor. Defaults to an empty array `[]`.
|
|
812
|
+
*
|
|
813
|
+
* @remarks
|
|
814
|
+
* This type allows strong typing of class constructors with defined argument types.
|
|
815
|
+
*
|
|
816
|
+
* @example
|
|
817
|
+
* ```ts
|
|
818
|
+
* class MyClass {
|
|
819
|
+
* constructor(public name: string) {}
|
|
820
|
+
* }
|
|
821
|
+
*
|
|
822
|
+
* const ctor: ConstructorLikeType<MyClass, [string]> = MyClass;
|
|
823
|
+
* const instance = new ctor("Hello");
|
|
824
|
+
* ```
|
|
825
|
+
*
|
|
826
|
+
* @since 2.0.0
|
|
827
|
+
*/
|
|
828
|
+
type ConstructorLikeType<Return = unknown, Args extends Array<unknown> = []> = new (...args: Args) => Return;
|
|
829
|
+
/**
|
|
830
|
+
* Recursively makes all properties of a type optional.
|
|
831
|
+
*
|
|
832
|
+
* @typeParam T - The type to transform into a deeply partial type.
|
|
833
|
+
*
|
|
834
|
+
* @remarks
|
|
835
|
+
* This type is similar to TypeScript's built-in `Partial<T>`, but it applies recursively
|
|
836
|
+
* to all nested objects. Arrays and other non-object types are left unchanged.
|
|
837
|
+
*
|
|
838
|
+
* Use `DeepPartialType` when you need to work with objects where only some properties,
|
|
839
|
+
* including nested properties, may be provided.
|
|
840
|
+
*
|
|
841
|
+
* @example
|
|
842
|
+
* ```ts
|
|
843
|
+
* interface User {
|
|
844
|
+
* name: string;
|
|
845
|
+
* address: {
|
|
846
|
+
* street: string;
|
|
847
|
+
* city: string;
|
|
848
|
+
* };
|
|
849
|
+
* }
|
|
850
|
+
*
|
|
851
|
+
* const partialUser: DeepPartialType<User> = {
|
|
852
|
+
* name: "Alice",
|
|
853
|
+
* address: { city: "Wonderland" }
|
|
854
|
+
* };
|
|
855
|
+
* ```
|
|
856
|
+
*
|
|
857
|
+
* @since 2.0.0
|
|
858
|
+
*/
|
|
859
|
+
type DeepPartialType<T> = T extends object ? {
|
|
860
|
+
[P in keyof T]?: DeepPartialType<T[P]>;
|
|
861
|
+
} : T;
|
|
862
|
+
/**
|
|
863
|
+
* Makes specific keys of a type required while leaving the rest unchanged.
|
|
864
|
+
*
|
|
865
|
+
* @typeParam T - The base type.
|
|
866
|
+
* @typeParam K - The subset of keys from `T` that should be required.
|
|
867
|
+
*
|
|
868
|
+
* @remarks
|
|
869
|
+
* This utility type is useful when you want to enforce that certain properties
|
|
870
|
+
* of a type are mandatory, without affecting the optionality of other properties.
|
|
871
|
+
* It works by combining:
|
|
872
|
+
* - `Omit<T, K>` to remove the keys that will become required.
|
|
873
|
+
* - `Required<Pick<T, K>>` to mark the specified keys as required.
|
|
874
|
+
*
|
|
875
|
+
* @example
|
|
876
|
+
* ```ts
|
|
877
|
+
* interface User {
|
|
878
|
+
* id?: number;
|
|
879
|
+
* name?: string;
|
|
880
|
+
* email?: string;
|
|
881
|
+
* }
|
|
882
|
+
*
|
|
883
|
+
* // Make 'id' and 'name' required, 'email' remains optional
|
|
884
|
+
* type UserWithRequiredIdName = RequireKeysType<User, 'id' | 'name'>;
|
|
885
|
+
*
|
|
886
|
+
* const user: UserWithRequiredIdName = {
|
|
887
|
+
* id: 1,
|
|
888
|
+
* name: "Alice"
|
|
889
|
+
* };
|
|
890
|
+
* ```
|
|
891
|
+
*
|
|
892
|
+
* @since 2.0.0
|
|
893
|
+
*/
|
|
894
|
+
type RequireKeysType<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
895
|
+
|
|
896
|
+
/**
|
|
897
|
+
* Import will remove at compile time
|
|
898
|
+
*/
|
|
899
|
+
/**
|
|
900
|
+
* Manages the state of a versioned VitePress documentation project.
|
|
901
|
+
*
|
|
902
|
+
* @remarks
|
|
903
|
+
* The `StateModel` class is responsible for:
|
|
904
|
+
* - Managing source and archive directories for versioned documentation.
|
|
905
|
+
* - Initializing the VitePress configuration (`VitepressConfigInterface`) from
|
|
906
|
+
* a provided {@link ConfigurationInterface}.
|
|
907
|
+
* - Maintaining a list of documentation versions and a map of Markdown files per version.
|
|
908
|
+
* - Ensuring the necessary directories exist and are initialized.
|
|
909
|
+
*
|
|
910
|
+
* This service is designed as a singleton, making it safe to inject across
|
|
911
|
+
* your application using `@Injectable({ scope: 'singleton' })`.
|
|
912
|
+
*
|
|
913
|
+
* @example
|
|
914
|
+
* ```ts
|
|
915
|
+
* import { StateModel } from "@models/state.model";
|
|
916
|
+
*
|
|
917
|
+
* const state = new StateModel(config).init();
|
|
918
|
+
* console.log(state.versionsList);
|
|
919
|
+
* console.log(state.fileMap);
|
|
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.
|
|
961
|
+
*
|
|
962
|
+
* @remarks
|
|
963
|
+
* This property holds the currently active versions configuration
|
|
964
|
+
* as defined in {@link VersionsConfigInterface}. It includes settings
|
|
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}.
|
|
979
|
+
*
|
|
980
|
+
* @see VitepressConfigInterface
|
|
981
|
+
* @since 2.0.0
|
|
982
|
+
*/
|
|
983
|
+
readonly vitepressConfig: VitepressConfigInterface;
|
|
984
|
+
/**
|
|
985
|
+
* List of all available documentation versions.
|
|
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"`).
|
|
990
|
+
*
|
|
991
|
+
* @since 2.0.0
|
|
992
|
+
*/
|
|
993
|
+
readonly versionsList: Array<string>;
|
|
994
|
+
/**
|
|
995
|
+
* Maps locale keys to their effective base paths.
|
|
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
|
+
* ```
|
|
1014
|
+
*
|
|
1015
|
+
* @since 2.0.0
|
|
1016
|
+
*/
|
|
1017
|
+
readonly localesMap: Record<string, string>;
|
|
1018
|
+
/**
|
|
1019
|
+
* A map of version names to arrays of Markdown file paths relative to the sources directory.
|
|
1020
|
+
*
|
|
1021
|
+
* @remarks
|
|
1022
|
+
* - The key is the version name (or `''` for the root/source version).
|
|
1023
|
+
* - The value is an array of file paths (strings) for that version.
|
|
1024
|
+
*
|
|
1025
|
+
* This structure is built during initialization to facilitate generating versioned
|
|
1026
|
+
* documentation and navigation.
|
|
1027
|
+
*
|
|
1028
|
+
* @since 2.0.0
|
|
1029
|
+
*/
|
|
1030
|
+
readonly fileMap: Record<string, Array<string>>;
|
|
1031
|
+
/**
|
|
1032
|
+
* Creates an instance of `StateModel`.
|
|
1033
|
+
*
|
|
1034
|
+
* @param configuration - Optional configuration object; defaults to {@link defaultConfiguration}.
|
|
1035
|
+
*
|
|
1036
|
+
* @throws Will throw an error if the sources directory does not exist.
|
|
1037
|
+
*
|
|
1038
|
+
* @remarks
|
|
1039
|
+
* Initializes the state of the documentation project by:
|
|
1040
|
+
* - Extracting `sources` and `archive` from the provided configuration.
|
|
1041
|
+
* - Constructing full paths for `root`, `sourcesPath`, and `archivePath`.
|
|
1042
|
+
* - Validating that the sources directory exists.
|
|
1043
|
+
* - Ensuring the archive directory exists and creating a `.gitkeep` file if necessary.
|
|
1044
|
+
* - Creating a VitePress configuration object with versioning support.
|
|
1045
|
+
*
|
|
1046
|
+
* @since 2.0.0
|
|
1047
|
+
*/
|
|
1048
|
+
constructor(configuration?: ConfigurationInterface);
|
|
1049
|
+
/**
|
|
1050
|
+
* Initializes the state by reading archive subfolders and building file maps.
|
|
1051
|
+
*
|
|
1052
|
+
* @returns The instance itself (`this`) to allow method chaining.
|
|
1053
|
+
*
|
|
1054
|
+
* @remarks
|
|
1055
|
+
* This method performs the following steps:
|
|
1056
|
+
* - Reads all subdirectories in the archive directory.
|
|
1057
|
+
* - Populates `fileMap` with all Markdown files relative to the sources directory.
|
|
1058
|
+
* - The root source files are stored under the `''` key.
|
|
1059
|
+
* - Archive subfolders are stored under their folder names.
|
|
1060
|
+
* - Initializes `vitepressConfig.locales` for each folder with an empty `themeConfig`.
|
|
1061
|
+
* - Populates `versionsList` with all version keys derived from `fileMap`.
|
|
1062
|
+
*
|
|
1063
|
+
* @since 2.0.0
|
|
1064
|
+
*/
|
|
1065
|
+
init(): this;
|
|
1066
|
+
/**
|
|
1067
|
+
* Initializes the locale entries in the VitePress configuration and builds a mapping
|
|
1068
|
+
* of locales to their links for all versions.
|
|
1069
|
+
*
|
|
1070
|
+
* @remarks
|
|
1071
|
+
* - Adds a `root` locale entry.
|
|
1072
|
+
* - Copies all user-defined locales into the VitePress config.
|
|
1073
|
+
* - Populates `localesMap` with locale keys and their corresponding links (or folder names).
|
|
1074
|
+
* - Ensures that for each documentation version, a locale entry exists in the VitePress config.
|
|
1075
|
+
* - Handles both root and non-root locales, creating versioned paths automatically.
|
|
1076
|
+
*
|
|
1077
|
+
* @since 2.0.0
|
|
1078
|
+
*/
|
|
1079
|
+
private initializeLocalesMap;
|
|
1080
|
+
/**
|
|
1081
|
+
* Ensures that the archive directory exists.
|
|
1082
|
+
*
|
|
1083
|
+
* @param path - The path to the archive directory.
|
|
1084
|
+
*
|
|
1085
|
+
* @remarks
|
|
1086
|
+
* - If the directory does not exist, it is created.
|
|
1087
|
+
* - A `.gitkeep` file is also added to ensure the directory is tracked by Git.
|
|
1088
|
+
*
|
|
1089
|
+
* @since 2.0.0
|
|
1090
|
+
*/
|
|
1091
|
+
private makeArchiveDirectory;
|
|
1092
|
+
/**
|
|
1093
|
+
* Creates a VitePress configuration object from the user-provided configuration.
|
|
1094
|
+
*
|
|
1095
|
+
* @returns A `VitepressConfigInterface` object with versioning support added.
|
|
1096
|
+
*
|
|
1097
|
+
* @remarks
|
|
1098
|
+
* - Copies all configuration properties except for `locales`, `rewrites`, `themeConfig`, and `versionsConfig`.
|
|
1099
|
+
* - Initializes excluded properties (except `versionsConfig`) with empty objects.
|
|
1100
|
+
* - Returns a configuration object typed as {@link VitepressConfigInterface}, ready for VitePress usage.
|
|
1101
|
+
*
|
|
1102
|
+
* @see VitepressConfigInterface
|
|
1103
|
+
* @since 2.0.0
|
|
1104
|
+
*/
|
|
1105
|
+
private createVitepressConfig;
|
|
90
1106
|
}
|
|
91
1107
|
|
|
92
1108
|
/**
|
|
93
1109
|
* Import will remove at compile time
|
|
94
1110
|
*/
|
|
95
1111
|
/**
|
|
96
|
-
*
|
|
1112
|
+
* A collection of singleton instances for injectable classes.
|
|
1113
|
+
*
|
|
1114
|
+
* @remarks
|
|
1115
|
+
* This map stores instances of classes marked as `singleton` in `@Injectable` metadata.
|
|
1116
|
+
* It ensures that only one instance exists for the lifetime of the application.
|
|
1117
|
+
*
|
|
1118
|
+
* @see ConstructorType
|
|
1119
|
+
* @since 2.0.0
|
|
1120
|
+
*/
|
|
1121
|
+
declare const SINGLETONS: Map<ConstructorType, unknown>;
|
|
1122
|
+
/**
|
|
1123
|
+
* Stores metadata for all classes marked with the `@Injectable` decorator.
|
|
97
1124
|
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
1125
|
+
* @remarks
|
|
1126
|
+
* The metadata includes scope, factory function, and provider dependencies.
|
|
100
1127
|
*
|
|
101
|
-
* @
|
|
1128
|
+
* @see Injectable
|
|
1129
|
+
* @since 2.0.0
|
|
1130
|
+
*/
|
|
1131
|
+
declare const INJECTABLES: Map<ConstructorType, InjectableOptionsInterface<ConstructorType>>;
|
|
1132
|
+
/**
|
|
1133
|
+
* Type guard to check if a provider uses a class.
|
|
102
1134
|
*
|
|
103
|
-
* @param
|
|
104
|
-
* @
|
|
105
|
-
*
|
|
1135
|
+
* @param provider - The provider to check.
|
|
1136
|
+
* @returns True if the provider is a {@link ProviderUseClassInterface}.
|
|
1137
|
+
*
|
|
1138
|
+
* @see ProviderUseClassInterface
|
|
1139
|
+
* @since 2.0.0
|
|
1140
|
+
*/
|
|
1141
|
+
declare function isProviderUseClass(provider: unknown): provider is ProviderUseClassInterface;
|
|
1142
|
+
/**
|
|
1143
|
+
* Type guard to check if a provider uses a factory function.
|
|
1144
|
+
*
|
|
1145
|
+
* @param provider - The provider to check.
|
|
1146
|
+
* @returns True if the provider is a {@link ProviderUseFactoryInterface}.
|
|
1147
|
+
*
|
|
1148
|
+
* @see ProviderUseFactoryInterface
|
|
1149
|
+
* @since 2.0.0
|
|
1150
|
+
*/
|
|
1151
|
+
declare function isProviderUseFactory(provider: unknown): provider is ProviderUseFactoryInterface;
|
|
1152
|
+
/**
|
|
1153
|
+
* Type guard to check if a provider uses a value.
|
|
1154
|
+
*
|
|
1155
|
+
* @param provider - The provider to check.
|
|
1156
|
+
* @returns True if the provider is a {@link ProviderUseValueInterface}.
|
|
1157
|
+
*
|
|
1158
|
+
* @see ProviderUseValueInterface
|
|
1159
|
+
* @since 2.0.0
|
|
1160
|
+
*/
|
|
1161
|
+
declare function isProviderUseValue(provider: unknown): provider is ProviderUseValueInterface;
|
|
1162
|
+
/**
|
|
1163
|
+
* Marks a class as injectable, optionally providing metadata.
|
|
1164
|
+
*
|
|
1165
|
+
* @param options - Optional configuration for the injectable class.
|
|
106
1166
|
*
|
|
107
1167
|
* @remarks
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
* 2. Updates the navigation menu using {@link versioningNav}.
|
|
111
|
-
* 3. Validates the sidebar configuration:
|
|
112
|
-
* - If the sidebar is an array, logs an error recommending a `DefaultTheme.MultiSidebar` object instead.
|
|
113
|
-
* - Otherwise, merges versioned sidebar options via {@link versioningSidebar}.
|
|
1168
|
+
* The `@Injectable` decorator allows classes to be automatically instantiated
|
|
1169
|
+
* and injected with dependencies using the `inject` function.
|
|
114
1170
|
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
1171
|
+
* @example
|
|
1172
|
+
* ```ts
|
|
1173
|
+
* @Injectable({ scope: 'singleton' })
|
|
1174
|
+
* class MyService {}
|
|
1175
|
+
*
|
|
1176
|
+
* const instance = inject(MyService);
|
|
1177
|
+
* ```
|
|
1178
|
+
*
|
|
1179
|
+
* @see InjectableOptionsInterface
|
|
1180
|
+
* @since 2.0.0
|
|
1181
|
+
*/
|
|
1182
|
+
declare function Injectable<T extends ConstructorType = ConstructorType>(options?: InjectableOptionsInterface<T>): (target: T) => void;
|
|
1183
|
+
/**
|
|
1184
|
+
* Converts an array of providers into constructor arguments for injection.
|
|
1185
|
+
*
|
|
1186
|
+
* @param providers - An optional array of providers to resolve.
|
|
1187
|
+
* @param args - Optional initial arguments to prepend before resolving providers.
|
|
1188
|
+
* @returns An array of resolved arguments including the results from providers.
|
|
1189
|
+
*
|
|
1190
|
+
* @remarks
|
|
1191
|
+
* This function iterates over the provided `ProvidersType` array and converts each provider
|
|
1192
|
+
* into its resolved value. It supports class providers, factory providers, value providers,
|
|
1193
|
+
* and direct constructor functions. The returned array can be used to construct instances
|
|
1194
|
+
* with dependencies injected in the correct order.
|
|
117
1195
|
*
|
|
118
1196
|
* @example
|
|
119
1197
|
* ```ts
|
|
120
|
-
*
|
|
1198
|
+
* const args = providersIntoArgs([{ useValue: 42 }, { useFactory: () => 'hello' }]);
|
|
1199
|
+
* // args = [42, 'hello']
|
|
1200
|
+
* ```
|
|
1201
|
+
*
|
|
1202
|
+
* @see isProviderUseClass
|
|
1203
|
+
* @see isProviderUseValue
|
|
1204
|
+
* @see isProviderUseFactory
|
|
121
1205
|
*
|
|
122
|
-
*
|
|
1206
|
+
* @since 2.0.0
|
|
1207
|
+
*/
|
|
1208
|
+
declare function providersIntoArgs(providers?: ProvidersType, args?: Array<unknown>): Array<unknown>;
|
|
1209
|
+
/**
|
|
1210
|
+
* Resolves and instantiates a class with its dependencies.
|
|
1211
|
+
*
|
|
1212
|
+
* @param token - The constructor function or class to instantiate.
|
|
1213
|
+
* @param args - Optional arguments to pass to the constructor, which can override
|
|
1214
|
+
* or supplement provider-resolved values.
|
|
1215
|
+
* @returns An instance of the class with all dependencies injected.
|
|
1216
|
+
*
|
|
1217
|
+
* @remarks
|
|
1218
|
+
* The `inject` function looks up metadata for the class marked with `@Injectable`.
|
|
1219
|
+
* It resolves all providers recursively using `providersIntoArgs`. If the class is
|
|
1220
|
+
* marked as a `singleton`, the same instance will be returned on further calls.
|
|
1221
|
+
*
|
|
1222
|
+
* @example
|
|
1223
|
+
* ```ts
|
|
1224
|
+
* @Injectable({ scope: 'singleton' })
|
|
1225
|
+
* class MyService {}
|
|
1226
|
+
*
|
|
1227
|
+
* const instance = inject(MyService);
|
|
1228
|
+
* ```
|
|
1229
|
+
*
|
|
1230
|
+
* @see Injectable
|
|
1231
|
+
* @see providersIntoArgs
|
|
1232
|
+
*
|
|
1233
|
+
* @since 2.0.0
|
|
1234
|
+
*/
|
|
1235
|
+
declare function inject<T, Args extends Array<unknown>>(token: ConstructorLikeType<T, Args>, ...args: Partial<Args>): T;
|
|
1236
|
+
/**
|
|
1237
|
+
* Forces the instantiation of a class, bypassing any existing singleton instance.
|
|
1238
|
+
*
|
|
1239
|
+
* @param token - The constructor function or class to instantiate.
|
|
1240
|
+
* @param args - Optional arguments to pass to the constructor, which can override
|
|
1241
|
+
* or supplement provider-resolved values.
|
|
1242
|
+
* @returns A new instance of the class, even if a singleton instance already exists.
|
|
1243
|
+
*
|
|
1244
|
+
* @remarks
|
|
1245
|
+
* Unlike the `inject` function, `forceInject` will delete any existing singleton
|
|
1246
|
+
* instance for the given class before creating a new one. This is useful when you
|
|
1247
|
+
* need a fresh instance regardless of the singleton scope.
|
|
1248
|
+
*
|
|
1249
|
+
* @example
|
|
1250
|
+
* ```ts
|
|
1251
|
+
* @Injectable({ scope: 'singleton' })
|
|
1252
|
+
* class MyService {}
|
|
1253
|
+
*
|
|
1254
|
+
* const freshInstance = forceInject(MyService);
|
|
123
1255
|
* ```
|
|
124
1256
|
*
|
|
125
|
-
* @
|
|
1257
|
+
* @see inject
|
|
1258
|
+
* @since 2.0.0
|
|
126
1259
|
*/
|
|
127
|
-
declare function
|
|
1260
|
+
declare function forceInject<T, Args extends Array<unknown>>(token: ConstructorLikeType<T, Args>, ...args: Partial<Args>): T;
|
|
128
1261
|
|
|
129
1262
|
/**
|
|
130
1263
|
* Import will remove at compile time
|
|
131
1264
|
*/
|
|
132
1265
|
/**
|
|
133
|
-
*
|
|
1266
|
+
* Represents a provider that uses a factory function to generate a value.
|
|
134
1267
|
*
|
|
135
|
-
* @
|
|
136
|
-
*
|
|
137
|
-
*
|
|
1268
|
+
* @remarks
|
|
1269
|
+
* A factory provider can also declare dependencies through `providers`, which
|
|
1270
|
+
* will be resolved and passed to the factory function.
|
|
138
1271
|
*
|
|
139
|
-
* @
|
|
1272
|
+
* @example
|
|
1273
|
+
* ```ts
|
|
1274
|
+
* const factoryProvider: ProviderUseFactoryInterface = {
|
|
1275
|
+
* useFactory: (dep: MyService) => new AnotherService(dep),
|
|
1276
|
+
* providers: [MyService]
|
|
1277
|
+
* };
|
|
1278
|
+
* ```
|
|
1279
|
+
*
|
|
1280
|
+
* @see ProvidersType
|
|
1281
|
+
* @since 2.0.0
|
|
1282
|
+
*/
|
|
1283
|
+
interface ProviderUseFactoryInterface {
|
|
1284
|
+
useFactory: FunctionType;
|
|
1285
|
+
providers?: ProvidersType;
|
|
1286
|
+
}
|
|
1287
|
+
/**
|
|
1288
|
+
* Represents a provider that uses a class constructor to generate a value.
|
|
140
1289
|
*
|
|
141
1290
|
* @remarks
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
* containing `versions` and `latestVersion`.
|
|
1291
|
+
* Class providers can also declare dependencies through `providers`, which
|
|
1292
|
+
* will be injected when the class is instantiated.
|
|
145
1293
|
*
|
|
146
1294
|
* @example
|
|
147
1295
|
* ```ts
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
1296
|
+
* const classProvider: ProviderUseClassInterface = {
|
|
1297
|
+
* useClass: MyService,
|
|
1298
|
+
* providers: [DependencyService]
|
|
1299
|
+
* };
|
|
151
1300
|
* ```
|
|
152
1301
|
*
|
|
153
|
-
* @
|
|
1302
|
+
* @see ProvidersType
|
|
1303
|
+
* @since 2.0.0
|
|
154
1304
|
*/
|
|
155
|
-
|
|
1305
|
+
interface ProviderUseClassInterface {
|
|
1306
|
+
useClass: ConstructorType;
|
|
1307
|
+
providers?: ProvidersType;
|
|
1308
|
+
}
|
|
156
1309
|
/**
|
|
157
|
-
*
|
|
1310
|
+
* Represents a provider that uses a static value.
|
|
158
1311
|
*
|
|
159
|
-
* @
|
|
160
|
-
*
|
|
161
|
-
*
|
|
1312
|
+
* @remarks
|
|
1313
|
+
* Value providers do not have dependencies and are injected as-is.
|
|
1314
|
+
*
|
|
1315
|
+
* @example
|
|
1316
|
+
* ```ts
|
|
1317
|
+
* const valueProvider: ProviderUseValueInterface = {
|
|
1318
|
+
* useValue: 42
|
|
1319
|
+
* };
|
|
1320
|
+
* ```
|
|
162
1321
|
*
|
|
163
|
-
* @
|
|
1322
|
+
* @see ProvidersType
|
|
1323
|
+
* @since 2.0.0
|
|
1324
|
+
*/
|
|
1325
|
+
interface ProviderUseValueInterface {
|
|
1326
|
+
useValue: unknown;
|
|
1327
|
+
}
|
|
1328
|
+
/**
|
|
1329
|
+
* Type for all possible providers that can be injected.
|
|
164
1330
|
*
|
|
165
1331
|
* @remarks
|
|
166
|
-
*
|
|
167
|
-
* -
|
|
1332
|
+
* Providers can be:
|
|
1333
|
+
* - A class constructor (`ConstructorType`)
|
|
1334
|
+
* - A factory provider (`ProviderUseFactoryInterface`)
|
|
1335
|
+
* - A class provider (`ProviderUseClassInterface`)
|
|
1336
|
+
* - A value provider (`ProviderUseValueInterface`)
|
|
168
1337
|
*
|
|
169
1338
|
* @example
|
|
170
1339
|
* ```ts
|
|
171
|
-
*
|
|
1340
|
+
* const providers: ProvidersType = [
|
|
1341
|
+
* MyService,
|
|
1342
|
+
* { useFactory: () => new AnotherService() },
|
|
1343
|
+
* { useValue: 42 }
|
|
1344
|
+
* ];
|
|
1345
|
+
* ```
|
|
1346
|
+
*
|
|
1347
|
+
* @see ProviderUseClassInterface
|
|
1348
|
+
* @see ProviderUseValueInterface
|
|
1349
|
+
* @see ProviderUseFactoryInterface
|
|
172
1350
|
*
|
|
173
|
-
*
|
|
1351
|
+
* @since 2.0.0
|
|
1352
|
+
*/
|
|
1353
|
+
type ProvidersType = Array<ConstructorType | ProviderUseFactoryInterface | ProviderUseClassInterface | ProviderUseValueInterface>;
|
|
1354
|
+
/**
|
|
1355
|
+
* Options for configuring an injectable class.
|
|
1356
|
+
*
|
|
1357
|
+
* @remarks
|
|
1358
|
+
* - `scope`: Determines whether the class should behave as a singleton or transient.
|
|
1359
|
+
* - `factory`: Optional factory function to instantiate the class.
|
|
1360
|
+
* - `providers`: Optional dependencies to inject when creating the instance.
|
|
1361
|
+
*
|
|
1362
|
+
* @example
|
|
1363
|
+
* ```ts
|
|
1364
|
+
* @Injectable({ scope: 'singleton', providers: [DepService] })
|
|
1365
|
+
* class MyService {}
|
|
174
1366
|
* ```
|
|
175
1367
|
*
|
|
176
|
-
* @
|
|
1368
|
+
* @see ProvidersType
|
|
1369
|
+
* @since 2.0.0
|
|
177
1370
|
*/
|
|
178
|
-
|
|
1371
|
+
interface InjectableOptionsInterface<T extends ConstructorType = ConstructorType> {
|
|
1372
|
+
scope?: 'singleton' | 'transient';
|
|
1373
|
+
factory?: FunctionLikeType<InstanceType<T>, ConstructorParameters<T>>;
|
|
1374
|
+
providers?: ProvidersType;
|
|
1375
|
+
}
|
|
179
1376
|
|
|
180
1377
|
/**
|
|
181
1378
|
* Import will remove at compile time
|
|
182
1379
|
*/
|
|
183
1380
|
/**
|
|
184
|
-
*
|
|
1381
|
+
* Default configuration object for the `versions` system.
|
|
185
1382
|
*
|
|
186
1383
|
* @remarks
|
|
187
|
-
*
|
|
188
|
-
*
|
|
1384
|
+
* Provides a baseline implementation of {@link ConfigurationInterface}.
|
|
1385
|
+
* This includes:
|
|
1386
|
+
* - Empty `locales` and `rewrites` mappings.
|
|
1387
|
+
* - A `versionsConfig` with:
|
|
1388
|
+
* - `current` set to `"latest"`.
|
|
1389
|
+
* - `sources` pointing to `"src"`.
|
|
1390
|
+
* - `archive` pointing to `"archive"`.
|
|
1391
|
+
* - `hooks.rewritesHook` bound to the default {@link rewritesHook}.
|
|
1392
|
+
* - A `versionSwitcher` enabled with label `"Switch Version"` and
|
|
1393
|
+
* `includeCurrentVersion` set to `true`.
|
|
1394
|
+
*
|
|
1395
|
+
* This default setup can be extended or overridden as needed when
|
|
1396
|
+
* customizing your documentation site.
|
|
1397
|
+
*
|
|
1398
|
+
* @example
|
|
1399
|
+
* ```ts
|
|
1400
|
+
* import { defaultConfiguration } from "@config/default.configuration";
|
|
1401
|
+
*
|
|
1402
|
+
* export default {
|
|
1403
|
+
* ...defaultConfiguration,
|
|
1404
|
+
* locales: {
|
|
1405
|
+
* en: { link: "/en/", label: "English" }
|
|
1406
|
+
* }
|
|
1407
|
+
* };
|
|
1408
|
+
* ```
|
|
1409
|
+
*
|
|
1410
|
+
* @since 2.0.0
|
|
1411
|
+
*/
|
|
1412
|
+
declare const defaultConfiguration: ConfigurationInterface;
|
|
1413
|
+
|
|
1414
|
+
/**
|
|
1415
|
+
* imports
|
|
1416
|
+
*/
|
|
1417
|
+
/**
|
|
1418
|
+
* Rewrites a documentation source path using version and locale.
|
|
1419
|
+
*
|
|
1420
|
+
* @remarks
|
|
1421
|
+
* This implementation joins the `version`, `locale`, and original `source`
|
|
1422
|
+
* into a normalized POSIX-style path. It is commonly used to generate
|
|
1423
|
+
* consistent URLs or filesystem paths for versioned and localized docs.
|
|
1424
|
+
*
|
|
1425
|
+
* @param source - The original file path or content identifier.
|
|
1426
|
+
* @param version - The version string of the documentation (e.g., `"1.2.0"`).
|
|
1427
|
+
* @param locale - The locale code (e.g., `"en"`, `"de"`).
|
|
1428
|
+
*
|
|
1429
|
+
* @returns The rewritten path string in the format `version/locale/source`.
|
|
1430
|
+
*
|
|
1431
|
+
* @example
|
|
1432
|
+
* ```ts
|
|
1433
|
+
* rewritesHook("guide/intro.md", "v2.0.0", "en");
|
|
1434
|
+
* // → "en/v2.0.0/guide/intro.md"
|
|
1435
|
+
* ```
|
|
189
1436
|
*
|
|
190
|
-
*
|
|
191
|
-
|
|
1437
|
+
* @since 2.0.0
|
|
1438
|
+
*/
|
|
1439
|
+
declare function rewritesHook(source: string, version: string, locale: string): string;
|
|
1440
|
+
/**
|
|
1441
|
+
* Parses all documentation routes and generates rewritten paths for versioned and localized files.
|
|
192
1442
|
*
|
|
193
|
-
* @
|
|
194
|
-
*
|
|
195
|
-
*
|
|
1443
|
+
* @remarks
|
|
1444
|
+
* - Iterates through the `fileMap` of the `StateModel` to process all Markdown files.
|
|
1445
|
+
* - Determines the correct locale for each file using `localesMap`.
|
|
1446
|
+
* - Uses the `rewritesHook` from `versionsConfig.hooks` to generate the versioned and localized path.
|
|
1447
|
+
* - Populates the `vitepressConfig.rewrites` object with the mapping of original paths to rewritten paths.
|
|
196
1448
|
*
|
|
197
1449
|
* @example
|
|
198
1450
|
* ```ts
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
* // →
|
|
202
|
-
*
|
|
203
|
-
*
|
|
1451
|
+
* parseRoutesComponent();
|
|
1452
|
+
* console.log(state.vitepressConfig.rewrites);
|
|
1453
|
+
* // → {
|
|
1454
|
+
* "src/en/index.md": "en/index.md",
|
|
1455
|
+
* "src/de/index.md": "index.md",
|
|
1456
|
+
* "archive/x0.0.1/en/index.md": "x0.0.1/en/index.md"
|
|
1457
|
+
* ...
|
|
1458
|
+
* }
|
|
204
1459
|
* ```
|
|
205
1460
|
*
|
|
206
|
-
* @since
|
|
1461
|
+
* @since 2.0.0
|
|
207
1462
|
*/
|
|
208
|
-
declare function
|
|
1463
|
+
declare function parseRoutesComponent(): void;
|
|
209
1464
|
|
|
210
1465
|
/**
|
|
211
|
-
*
|
|
1466
|
+
* Imports
|
|
1467
|
+
*/
|
|
1468
|
+
/**
|
|
1469
|
+
* Deeply merges two object types into a single object.
|
|
212
1470
|
*
|
|
213
|
-
* @
|
|
214
|
-
* @
|
|
1471
|
+
* @typeParam T - The type of the first object.
|
|
1472
|
+
* @typeParam U - The type of the second object.
|
|
215
1473
|
*
|
|
216
|
-
* @
|
|
1474
|
+
* @param obj1 - The base object whose properties will be merged.
|
|
1475
|
+
* @param obj2 - The object whose properties will overwrite or merge into `obj1`.
|
|
1476
|
+
* @returns A new object containing the deeply merged properties of both `obj1` and `obj2`.
|
|
217
1477
|
*
|
|
218
1478
|
* @remarks
|
|
219
|
-
* -
|
|
220
|
-
* - If
|
|
221
|
-
*
|
|
1479
|
+
* - This function performs a deep merge, recursively merging nested objects.
|
|
1480
|
+
* - If a property exists in both `obj1` and `obj2`:
|
|
1481
|
+
* - If both values are plain objects, they are merged recursively.
|
|
1482
|
+
* - Otherwise, the value from `obj2` overwrites the value from `obj1`.
|
|
1483
|
+
* - Arrays are **not** merged; if a property is an array in `obj2`, it will replace
|
|
1484
|
+
* the corresponding property in `obj1`.
|
|
222
1485
|
*
|
|
223
1486
|
* @example
|
|
224
1487
|
* ```ts
|
|
225
|
-
* const
|
|
226
|
-
* const
|
|
1488
|
+
* const obj1 = { a: 1, b: { c: 2, d: 3 } };
|
|
1489
|
+
* const obj2 = { b: { c: 42 }, e: 99 };
|
|
227
1490
|
*
|
|
228
|
-
*
|
|
229
|
-
* // Result: { a: 1, b: {
|
|
1491
|
+
* const merged = deepMerge(obj1, obj2);
|
|
1492
|
+
* // Result: { a: 1, b: { c: 42, d: 3 }, e: 99 }
|
|
230
1493
|
* ```
|
|
231
1494
|
*
|
|
232
|
-
* @since
|
|
1495
|
+
* @since 2.0.0
|
|
233
1496
|
*/
|
|
234
|
-
declare function
|
|
1497
|
+
declare function deepMerge<T extends object, U extends object>(obj1: T, obj2: U): T & U;
|
|
1498
|
+
/**
|
|
1499
|
+
* Recursively collects all Markdown (`.md`) files within a given directory,
|
|
1500
|
+
* returning their paths relative to a specified root directory.
|
|
1501
|
+
*
|
|
1502
|
+
* @param rootDir - The root directory used as the base for relative paths.
|
|
1503
|
+
* @param currentDir - The current directory to scan. Defaults to `rootDir`.
|
|
1504
|
+
* @returns An array of relative file paths to Markdown files.
|
|
1505
|
+
*
|
|
1506
|
+
* @remarks
|
|
1507
|
+
* - This function traverses directories recursively.
|
|
1508
|
+
* - Only files with a `.md` extension are included in the results.
|
|
1509
|
+
* - Returned paths are **relative to `rootDir`**, regardless of how deep the files are nested.
|
|
1510
|
+
* - Uses Node.js `fs.readdirSync` with `withFileTypes: true` for efficient directory traversal.
|
|
1511
|
+
*
|
|
1512
|
+
* @example
|
|
1513
|
+
* ```ts
|
|
1514
|
+
* const markdownFiles = getAllMarkdownFilesRelative("/project/docs");
|
|
1515
|
+
*
|
|
1516
|
+
* console.log(markdownFiles);
|
|
1517
|
+
* // Example output:
|
|
1518
|
+
* // [
|
|
1519
|
+
* // "README.md",
|
|
1520
|
+
* // "guide/intro.md",
|
|
1521
|
+
* // "tutorial/setup.md"
|
|
1522
|
+
* // ]
|
|
1523
|
+
* ```
|
|
1524
|
+
*
|
|
1525
|
+
* @since 2.0.0
|
|
1526
|
+
*/
|
|
1527
|
+
declare function getAllMarkdownFilesRelative(rootDir: string, currentDir?: string): Array<string>;
|
|
235
1528
|
|
|
236
1529
|
/**
|
|
237
1530
|
* Import will remove at compile time
|
|
238
1531
|
*/
|
|
239
1532
|
/**
|
|
240
|
-
*
|
|
1533
|
+
* Type guard to check if a navigation item has children.
|
|
1534
|
+
*
|
|
1535
|
+
* @param item - The navigation item to test.
|
|
1536
|
+
* @returns `true` if the item is a {@link NavItemWithChildrenType}, `false` otherwise.
|
|
1537
|
+
*
|
|
1538
|
+
* @remarks
|
|
1539
|
+
* - This function checks for the presence of an `item` property that is an array.
|
|
1540
|
+
* - Use this type guard to safely access child navigation items when iterating
|
|
1541
|
+
* or transforming navigation trees.
|
|
1542
|
+
*
|
|
1543
|
+
* @example
|
|
1544
|
+
* ```ts
|
|
1545
|
+
* const item: NavItemType = { text: "Docs", items: [{ text: "Guide", link: "/guide/" }] };
|
|
1546
|
+
* if (isNavItemWithChildren(item)) {
|
|
1547
|
+
* console.log(item.items); // Safe to access
|
|
1548
|
+
* }
|
|
1549
|
+
* ```
|
|
241
1550
|
*
|
|
242
|
-
* @
|
|
243
|
-
|
|
244
|
-
|
|
1551
|
+
* @since 2.0.0
|
|
1552
|
+
*/
|
|
1553
|
+
declare function isNavItemWithChildren(item: NavItemType): item is NavItemWithChildrenType;
|
|
1554
|
+
/**
|
|
1555
|
+
* Type guard to check if a navigation item has a link.
|
|
245
1556
|
*
|
|
246
|
-
* @
|
|
1557
|
+
* @param item - The navigation item to test.
|
|
1558
|
+
* @returns `true` if the item is a {@link NavItemWithLinkType}, `false` otherwise.
|
|
247
1559
|
*
|
|
248
1560
|
* @remarks
|
|
249
|
-
* -
|
|
250
|
-
* -
|
|
1561
|
+
* - This function checks for the presence of a `link` property.
|
|
1562
|
+
* - Use this type guard to safely access the `link` property when iterating
|
|
1563
|
+
* or transforming navigation trees.
|
|
251
1564
|
*
|
|
252
1565
|
* @example
|
|
253
1566
|
* ```ts
|
|
254
|
-
* const
|
|
1567
|
+
* const item: NavItemType = { text: "Home", link: "/" };
|
|
1568
|
+
* if (isNavItemWithLink(item)) {
|
|
1569
|
+
* console.log(item.link); // Safe to access
|
|
1570
|
+
* }
|
|
255
1571
|
* ```
|
|
256
1572
|
*
|
|
257
|
-
* @since
|
|
1573
|
+
* @since 2.0.0
|
|
258
1574
|
*/
|
|
259
|
-
declare function
|
|
1575
|
+
declare function isNavItemWithLink(item: NavItemType): item is NavItemWithLinkType;
|
|
260
1576
|
/**
|
|
261
|
-
*
|
|
1577
|
+
* Recursively prepends a version prefix to navigation item links.
|
|
262
1578
|
*
|
|
263
|
-
* @param
|
|
264
|
-
* @param
|
|
265
|
-
* @
|
|
266
|
-
* @param rootPath - Absolute path to the project root.
|
|
1579
|
+
* @param version - The version string to prefix (e.g., `"v2.0.0"`).
|
|
1580
|
+
* @param item - The navigation item to process, which can be a link, a group with children, or a component.
|
|
1581
|
+
* @returns A new navigation item with updated `link` values where applicable.
|
|
267
1582
|
*
|
|
268
|
-
* @
|
|
1583
|
+
* @remarks
|
|
1584
|
+
* - For {@link NavItemWithLinkType}, prepends the given `version` to the `link`
|
|
1585
|
+
* unless `skipVersioning` is `true`.
|
|
1586
|
+
* - For {@link NavItemWithChildrenType}, recursively traverses all children and applies
|
|
1587
|
+
* the same transformation.
|
|
1588
|
+
* - Component-based navigation items ({@link NavItemComponentType}) are returned as-is.
|
|
1589
|
+
* - Preserves other properties of the navigation items.
|
|
1590
|
+
*
|
|
1591
|
+
* @example
|
|
1592
|
+
* ```ts
|
|
1593
|
+
* const navItem: NavItemWithLinkType = { text: "Guide", link: "/guide/" };
|
|
1594
|
+
* const result = replaceLinksRecursive("v2.0.0", navItem);
|
|
1595
|
+
* // → { text: "Guide", link: "/v2.0.0/guide/" }
|
|
1596
|
+
*
|
|
1597
|
+
* const navGroup: NavItemWithChildrenType = {
|
|
1598
|
+
* text: "Docs",
|
|
1599
|
+
* items: [{ text: "Intro", link: "/intro/" }]
|
|
1600
|
+
* };
|
|
1601
|
+
* const groupResult = replaceLinksRecursive("v2.0.0", navGroup);
|
|
1602
|
+
* // → { text: "Docs", items: [{ text: "Intro", link: "/v2.0.0/intro/" }] }
|
|
1603
|
+
* ```
|
|
1604
|
+
*
|
|
1605
|
+
* @since 2.0.0
|
|
1606
|
+
*/
|
|
1607
|
+
declare function replaceLinksRecursive(version: string, item: NavItemType): NavItemType;
|
|
1608
|
+
/**
|
|
1609
|
+
* Applies version prefixes to an array of navigation items.
|
|
1610
|
+
*
|
|
1611
|
+
* @param items - An array of navigation items to process.
|
|
1612
|
+
* @param version - The version string to prepend to links (e.g., `"v2.0.0"`).
|
|
1613
|
+
* - If `"root"` is provided, no version prefix is added.
|
|
1614
|
+
* @returns A new array of navigation items with versioned links applied.
|
|
269
1615
|
*
|
|
270
1616
|
* @remarks
|
|
271
|
-
* -
|
|
272
|
-
* -
|
|
273
|
-
* -
|
|
1617
|
+
* - Uses {@link replaceLinksRecursive} to traverse each navigation item.
|
|
1618
|
+
* - Only items that are link-based or have children are modified; component items remain unchanged.
|
|
1619
|
+
* - Preserves other properties of the navigation items.
|
|
274
1620
|
*
|
|
275
1621
|
* @example
|
|
276
1622
|
* ```ts
|
|
277
|
-
* const
|
|
1623
|
+
* const navItems: NavItemType[] = [
|
|
1624
|
+
* { text: "Guide", link: "/guide/" },
|
|
1625
|
+
* { text: "Docs", items: [{ text: "Intro", link: "/intro/" }] }
|
|
1626
|
+
* ];
|
|
1627
|
+
* const versionedNav = populateNav(navItems, "v2.0.0");
|
|
1628
|
+
* // → [
|
|
1629
|
+
* // { text: "Guide", link: "/v2.0.0/guide/" },
|
|
1630
|
+
* // { text: "Docs", items: [{ text: "Intro", link: "/v2.0.0/intro/" }] }
|
|
1631
|
+
* // ]
|
|
278
1632
|
* ```
|
|
279
1633
|
*
|
|
280
|
-
* @since
|
|
1634
|
+
* @since 2.0.0
|
|
281
1635
|
*/
|
|
282
|
-
declare function
|
|
1636
|
+
declare function populateNav(items: Array<NavItemType>, version: string): Array<NavItemType>;
|
|
283
1637
|
/**
|
|
284
|
-
*
|
|
1638
|
+
* Normalizes a navigation structure into a flat, prefixed record.
|
|
285
1639
|
*
|
|
286
|
-
* @param
|
|
287
|
-
* @param
|
|
288
|
-
*
|
|
289
|
-
*
|
|
1640
|
+
* @param results - The target {@link NavObjectType} to populate with normalized items.
|
|
1641
|
+
* @param nav - The navigation structure to normalize. Can be:
|
|
1642
|
+
* - An array of navigation items (`NavItemType[]`), or
|
|
1643
|
+
* - A record mapping strings to arrays of navigation items (`NavObjectType`).
|
|
1644
|
+
* @param prefix - Optional prefix for keys when processing nested navigation objects.
|
|
1645
|
+
* Defaults to an empty string.
|
|
1646
|
+
* @param root - Optional root-level navigation items to include in all normalized entries.
|
|
290
1647
|
*
|
|
291
|
-
* @
|
|
1648
|
+
* @remarks
|
|
1649
|
+
* - If `nav` is an array, it merges it with the root items (if any) and appends to `results.root`.
|
|
1650
|
+
* - If `nav` is a record:
|
|
1651
|
+
* - Each key is prefixed with `prefix` unless it is `'root'`.
|
|
1652
|
+
* - Items from `root` or `root.root` are merged into each key.
|
|
1653
|
+
* - All items are accumulated in the `results` object, preserving the hierarchy as flat keys.
|
|
1654
|
+
*
|
|
1655
|
+
* @example
|
|
1656
|
+
* ```ts
|
|
1657
|
+
* const nav: NavObjectType = {
|
|
1658
|
+
* root: [{ text: "Home", link: "/" }],
|
|
1659
|
+
* guide: [{ text: "Intro", link: "/intro/" }]
|
|
1660
|
+
* };
|
|
1661
|
+
* const results: NavObjectType = { root: [] };
|
|
1662
|
+
* normalizeNav(results, nav, "v2.0.0");
|
|
1663
|
+
* // results → {
|
|
1664
|
+
* // root: [{ text: "Home", link: "/" }],
|
|
1665
|
+
* // "v2.0.0/guide": [{ text: "Intro", link: "/intro/" }]
|
|
1666
|
+
* // }
|
|
1667
|
+
* ```
|
|
1668
|
+
*
|
|
1669
|
+
* @since 2.0.0
|
|
1670
|
+
*/
|
|
1671
|
+
declare function normalizeNav(results: NavObjectType, nav: NavType, prefix?: string, root?: NavObjectType): void;
|
|
1672
|
+
/**
|
|
1673
|
+
* Normalizes all navigation structures across the global and locale-specific configurations.
|
|
1674
|
+
*
|
|
1675
|
+
* @param state - The current {@link StateModel} providing configuration data:
|
|
1676
|
+
* - `configuration.themeConfig.nav` — global navigation configuration.
|
|
1677
|
+
* - `configuration.locales` — locale-specific configurations with optional `nav`.
|
|
1678
|
+
*
|
|
1679
|
+
* @returns A flat record of navigation items keyed by locale or `'root'`, suitable for further processing.
|
|
1680
|
+
*
|
|
1681
|
+
* @remarks
|
|
1682
|
+
* - First, global navigation items are normalized into `globalResults`.
|
|
1683
|
+
* - If no locales are defined, `globalResults` is returned directly.
|
|
1684
|
+
* - Otherwise, iterates through all locale keys:
|
|
1685
|
+
* - Normalizes each locale’s `nav` configuration.
|
|
1686
|
+
* - Merges in global navigation items as fallback where necessary.
|
|
1687
|
+
* - Ensures that all navigation entries are flattened and ready for versioning or rendering.
|
|
1688
|
+
*
|
|
1689
|
+
* @example
|
|
1690
|
+
* ```ts
|
|
1691
|
+
* const state = inject(StateModel);
|
|
1692
|
+
* const normalizedNavs = normalizeNavs(state);
|
|
1693
|
+
* // normalizedNavs → {
|
|
1694
|
+
* // root: [...global items],
|
|
1695
|
+
* // en: [...English locale items including global fallback],
|
|
1696
|
+
* // de: [...German locale items including global fallback]
|
|
1697
|
+
* // }
|
|
1698
|
+
* ```
|
|
1699
|
+
*
|
|
1700
|
+
* @since 2.0.0
|
|
1701
|
+
*/
|
|
1702
|
+
declare function normalizeNavs(state: StateModel): Record<string, Array<NavItemType>>;
|
|
1703
|
+
/**
|
|
1704
|
+
* Parses and populates the navigation structure for all locales.
|
|
292
1705
|
*
|
|
293
1706
|
* @remarks
|
|
294
|
-
* -
|
|
295
|
-
* -
|
|
296
|
-
* -
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
1707
|
+
* - Retrieves normalized navigation items using {@link normalizeNavs}.
|
|
1708
|
+
* - Iterates through all locales defined in `vitepressConfig.locales`.
|
|
1709
|
+
* - For each locale:
|
|
1710
|
+
* - Falls back to global navigation (`navs.root`) if locale-specific navigation is not defined.
|
|
1711
|
+
* - Ensures the locale’s `themeConfig` exists.
|
|
1712
|
+
* - Populates the locale’s `themeConfig.nav` using {@link populateNav}, applying versioning where applicable.
|
|
1713
|
+
*
|
|
1714
|
+
* This function ensures that all locales have a fully initialized and version-aware navigation structure.
|
|
300
1715
|
*
|
|
301
1716
|
* @example
|
|
302
1717
|
* ```ts
|
|
303
|
-
*
|
|
304
|
-
* //
|
|
305
|
-
* // sidebars['/en/1.0.0/'] → sidebar for 'en' locale, version 1.0.0
|
|
1718
|
+
* parseNavs();
|
|
1719
|
+
* // state.vitepressConfig.locales → each locale has `themeConfig.nav` populated
|
|
306
1720
|
* ```
|
|
307
1721
|
*
|
|
308
|
-
* @since
|
|
1722
|
+
* @since 2.0.0
|
|
309
1723
|
*/
|
|
310
|
-
declare function
|
|
1724
|
+
declare function parseNavs(): void;
|
|
311
1725
|
|
|
312
1726
|
/**
|
|
313
|
-
*
|
|
1727
|
+
* Imports
|
|
314
1728
|
*/
|
|
315
1729
|
/**
|
|
316
|
-
*
|
|
1730
|
+
* Builds a version switcher navigation item for the documentation site.
|
|
1731
|
+
*
|
|
1732
|
+
* @param themeConfig - The {@link VersionsConfigInterface} configuration object.
|
|
1733
|
+
* @param versions - An array of available version strings.
|
|
1734
|
+
* @param current - The current version label, defaults to `"Latest"`.
|
|
1735
|
+
*
|
|
1736
|
+
* @returns A {@link NavItemWithChildrenType} representing the version switcher,
|
|
1737
|
+
* or `undefined` if the switcher is disabled in the configuration.
|
|
317
1738
|
*
|
|
318
1739
|
* @remarks
|
|
319
|
-
*
|
|
320
|
-
*
|
|
1740
|
+
* - If `themeConfig.versionSwitcher === false`, no switcher is created.
|
|
1741
|
+
* - The returned navigation item contains child links for each version in `versions`.
|
|
1742
|
+
* - If `includeCurrentVersion` is enabled, adds a link to the root (`"/"`)
|
|
1743
|
+
* for the currently active version, displayed as `"Latest"` or
|
|
1744
|
+
* `"vX.Y.Z (latest)"`.
|
|
1745
|
+
* - All version links have `skipVersioning: true` to prevent further prefixing.
|
|
321
1746
|
*
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
* - `localePrefix`: Prefix for locale-specific URLs.
|
|
325
|
-
* - `rewriteProcessor`: Processes file paths for versioned URLs.
|
|
326
|
-
* - `localeRewriteProcessor`: Processes locale-specific versioned URLs.
|
|
327
|
-
* - `sidebarOptions`: Configuration for generating versioned sidebars.
|
|
328
|
-
* - `processSidebarURLs`: Whether sidebar URLs should be processed.
|
|
329
|
-
* - `sidebarPathResolver`: Resolves the path to the sidebar JSON file for a given version.
|
|
330
|
-
* - `sidebarUrlProcessor`: Processes sidebar item URLs to include the version prefix.
|
|
1747
|
+
* This utility allows users to quickly switch between documentation versions
|
|
1748
|
+
* from the navigation bar.
|
|
331
1749
|
*
|
|
332
1750
|
* @example
|
|
333
1751
|
* ```ts
|
|
334
|
-
*
|
|
1752
|
+
* const themeConfig: VersionsConfigInterface = {
|
|
1753
|
+
* versionSwitcher: { text: "Versions", includeCurrentVersion: true }
|
|
1754
|
+
* };
|
|
1755
|
+
*
|
|
1756
|
+
* const versions = ["v2.0.0", "v1.5.0"];
|
|
1757
|
+
* const navItem = versionSwitcher(themeConfig, versions, "v2.0.0");
|
|
1758
|
+
*
|
|
1759
|
+
* // → {
|
|
1760
|
+
* // text: "Versions",
|
|
1761
|
+
* // items: [
|
|
1762
|
+
* // { link: "/", text: "v2.0.0 (latest)", skipVersioning: true },
|
|
1763
|
+
* // { link: "/v2.0.0/", text: "v2.0.0", skipVersioning: true },
|
|
1764
|
+
* // { link: "/v1.5.0/", text: "v1.5.0", skipVersioning: true }
|
|
1765
|
+
* // ]
|
|
1766
|
+
* // }
|
|
1767
|
+
* ```
|
|
1768
|
+
*
|
|
1769
|
+
* @since 2.0.0
|
|
1770
|
+
*/
|
|
1771
|
+
declare function versionSwitcher(themeConfig: VersionsConfigInterface, versions: Array<string>, current?: string): undefined | NavItemWithChildrenType;
|
|
1772
|
+
|
|
1773
|
+
/**
|
|
1774
|
+
* Imports
|
|
1775
|
+
*/
|
|
1776
|
+
/**
|
|
1777
|
+
* Populates locale information in the VitePress configuration for all versions.
|
|
335
1778
|
*
|
|
336
|
-
*
|
|
337
|
-
*
|
|
1779
|
+
* @remarks
|
|
1780
|
+
* - Reads the `localesMap` from the `StateModel` to identify each user-defined locale.
|
|
1781
|
+
* - Copies `lang` and `label` from the user configuration into `vitepressConfig.locales`.
|
|
1782
|
+
* - For each version in `versionsList`, creates a versioned locale entry in `vitepressConfig.locales`.
|
|
1783
|
+
* - Ensures that both the root locale and versioned locales have proper `lang` and `label` settings.
|
|
338
1784
|
*
|
|
339
|
-
*
|
|
340
|
-
*
|
|
1785
|
+
* @example
|
|
1786
|
+
* ```ts
|
|
1787
|
+
* parseLocale();
|
|
1788
|
+
* console.log(state.vitepressConfig.locales);
|
|
1789
|
+
* // → { root: { lang: "en", label: "English" }, "1.0/en": { lang: "en" }, ... }
|
|
341
1790
|
* ```
|
|
342
1791
|
*
|
|
343
|
-
* @since
|
|
1792
|
+
* @since 2.0.0
|
|
344
1793
|
*/
|
|
345
|
-
declare
|
|
1794
|
+
declare function parseLocale(): void;
|
|
346
1795
|
|
|
347
1796
|
/**
|
|
348
1797
|
* Import will remove at compile time
|
|
349
1798
|
*/
|
|
350
1799
|
/**
|
|
351
|
-
*
|
|
1800
|
+
* Populates sidebar items with versioned base paths.
|
|
352
1801
|
*
|
|
353
|
-
* @param
|
|
354
|
-
* @param
|
|
1802
|
+
* @param sidebar - The list of sidebar {@link SidebarItemType} items to transform.
|
|
1803
|
+
* @param version - The version key (e.g., `"en"`, `"v1.0"`, `"root"`).
|
|
355
1804
|
*
|
|
356
|
-
* @returns
|
|
1805
|
+
* @returns A new sidebar array with versioned `base` properties applied.
|
|
357
1806
|
*
|
|
358
1807
|
* @remarks
|
|
359
|
-
* -
|
|
360
|
-
* -
|
|
1808
|
+
* - If the provided `version` is `"root"`, it is normalized to an empty prefix (`""`).
|
|
1809
|
+
* - Items marked with `skipVersioning` are returned unchanged.
|
|
1810
|
+
* - When an item has a `link` or nested `items`, its `base` property is updated with the version prefix.
|
|
1811
|
+
* - Recursively processes child `items` to ensure consistent versioning throughout the sidebar tree.
|
|
361
1812
|
*
|
|
362
1813
|
* @example
|
|
363
1814
|
* ```ts
|
|
364
|
-
* const
|
|
1815
|
+
* const sidebar: SidebarItemType[] = [
|
|
1816
|
+
* { text: "Introduction", link: "/intro" },
|
|
1817
|
+
* {
|
|
1818
|
+
* text: "Guide",
|
|
1819
|
+
* items: [
|
|
1820
|
+
* { text: "Setup", link: "/setup" }
|
|
1821
|
+
* ]
|
|
1822
|
+
* }
|
|
1823
|
+
* ];
|
|
1824
|
+
*
|
|
1825
|
+
* // Applying version "v1"
|
|
1826
|
+
* const result = populateSidebar(sidebar, "v1");
|
|
1827
|
+
*
|
|
1828
|
+
* // Result:
|
|
1829
|
+
* [
|
|
1830
|
+
* { text: "Introduction", link: "/intro", base: "/v1/" },
|
|
1831
|
+
* {
|
|
1832
|
+
* text: "Guide",
|
|
1833
|
+
* base: "/v1/",
|
|
1834
|
+
* items: [
|
|
1835
|
+
* { text: "Setup", link: "/setup", base: "/v1/" }
|
|
1836
|
+
* ]
|
|
1837
|
+
* }
|
|
1838
|
+
* ]
|
|
365
1839
|
* ```
|
|
366
1840
|
*
|
|
367
|
-
* @
|
|
1841
|
+
* @see SidebarItemType
|
|
1842
|
+
* @since 2.0.0
|
|
368
1843
|
*/
|
|
369
|
-
declare function
|
|
1844
|
+
declare function populateSidebar(sidebar: Array<SidebarItemType>, version: string): Array<SidebarItemType>;
|
|
370
1845
|
/**
|
|
371
|
-
*
|
|
1846
|
+
* Normalizes a sidebar definition into a flat {@link SidebarObjectType} structure.
|
|
372
1847
|
*
|
|
373
|
-
* @param
|
|
374
|
-
* @param
|
|
375
|
-
* @param
|
|
376
|
-
* @param
|
|
1848
|
+
* @param results - The target results object where normalized sidebar items will be accumulated.
|
|
1849
|
+
* @param sidebar - The sidebar definition to normalize, which can be an array of items or a path-based mapping.
|
|
1850
|
+
* @param prefix - The optional path prefix used for nested sidebar entries (defaults to `""`).
|
|
1851
|
+
* @param root - A root-level sidebar object used as a fallback when merging items (defaults to `{}`).
|
|
377
1852
|
*
|
|
378
|
-
* @returns
|
|
1853
|
+
* @returns void — Mutates the `results` object directly by appending normalized sidebar items.
|
|
379
1854
|
*
|
|
380
1855
|
* @remarks
|
|
381
|
-
* -
|
|
382
|
-
* -
|
|
383
|
-
* -
|
|
1856
|
+
* - If the `sidebar` is an array, it is stored under the `prefix` key (or `"root"` if no prefix is given).
|
|
1857
|
+
* - If the `sidebar` is an object, each key is resolved into a full index path using the `prefix`.
|
|
1858
|
+
* - When merging items, entries from `root` (matching key or `"root"`) are prepended to the results.
|
|
1859
|
+
* - Ensures all sidebar values are normalized into arrays, even if a single item is provided.
|
|
1860
|
+
*
|
|
1861
|
+
* @example
|
|
1862
|
+
* ```ts
|
|
1863
|
+
* const results: SidebarObjectType = {};
|
|
1864
|
+
* normalizeSidebar(results, [
|
|
1865
|
+
* { text: "Intro", link: "/intro" }
|
|
1866
|
+
* ]);
|
|
1867
|
+
*
|
|
1868
|
+
* // Result:
|
|
1869
|
+
* {
|
|
1870
|
+
* root: [
|
|
1871
|
+
* { text: "Intro", link: "/intro" }
|
|
1872
|
+
* ]
|
|
1873
|
+
* }
|
|
1874
|
+
* ```
|
|
384
1875
|
*
|
|
385
1876
|
* @example
|
|
386
1877
|
* ```ts
|
|
387
|
-
* const
|
|
1878
|
+
* const results: SidebarObjectType = {};
|
|
1879
|
+
* normalizeSidebar(results, {
|
|
1880
|
+
* guide: [
|
|
1881
|
+
* { text: "Getting Started", link: "/guide/start" }
|
|
1882
|
+
* ]
|
|
1883
|
+
* }, "en");
|
|
1884
|
+
*
|
|
1885
|
+
* // Result:
|
|
1886
|
+
* {
|
|
1887
|
+
* "en/guide": [
|
|
1888
|
+
* { text: "Getting Started", link: "/guide/start" }
|
|
1889
|
+
* ]
|
|
1890
|
+
* }
|
|
388
1891
|
* ```
|
|
389
1892
|
*
|
|
390
|
-
* @
|
|
1893
|
+
* @see SidebarType
|
|
1894
|
+
* @see SidebarObjectType
|
|
1895
|
+
*
|
|
1896
|
+
* @since 2.0.0
|
|
391
1897
|
*/
|
|
392
|
-
declare function
|
|
1898
|
+
declare function normalizeSidebar(results: SidebarObjectType, sidebar: SidebarType, prefix?: string, root?: SidebarObjectType): void;
|
|
393
1899
|
/**
|
|
394
|
-
*
|
|
1900
|
+
* Normalizes all sidebar structures across global and locale-specific configurations.
|
|
1901
|
+
*
|
|
1902
|
+
* @param state - The current {@link StateModel} providing configuration data:
|
|
1903
|
+
* - `configuration.themeConfig.sidebar` — global sidebar configuration.
|
|
1904
|
+
* - `configuration.locales` — locale-specific configurations with optional `sidebar`.
|
|
1905
|
+
* - `localesMap` — maps locale keys to normalized paths for root fallback.
|
|
1906
|
+
*
|
|
1907
|
+
* @returns A flat {@link SidebarObjectType} where each key corresponds to a locale
|
|
1908
|
+
* or `"root"` and contains an array of normalized sidebar items.
|
|
1909
|
+
*
|
|
1910
|
+
* @remarks
|
|
1911
|
+
* - Global sidebar items are first normalized into `globalResults`.
|
|
1912
|
+
* - If no locales are defined, `globalResults` is returned directly.
|
|
1913
|
+
* - For each locale:
|
|
1914
|
+
* - Computes a `prefix` key for the locale (falling back to `"root"` if necessary).
|
|
1915
|
+
* - Normalizes the locale’s sidebar using {@link normalizeSidebar}, merging in global items as fallback.
|
|
1916
|
+
* - Ensures that all sidebar entries are flattened and ready for versioning or rendering.
|
|
1917
|
+
*
|
|
1918
|
+
* @example
|
|
1919
|
+
* ```ts
|
|
1920
|
+
* const state = inject(StateModel);
|
|
1921
|
+
* const sidebars = normalizeSidebars(state);
|
|
1922
|
+
* // sidebars → {
|
|
1923
|
+
* // root: [...global items],
|
|
1924
|
+
* // en: [...English locale items including global fallback],
|
|
1925
|
+
* // fr: [...French locale items including global fallback]
|
|
1926
|
+
* // }
|
|
1927
|
+
* ```
|
|
395
1928
|
*
|
|
396
|
-
* @
|
|
397
|
-
* @
|
|
398
|
-
* @
|
|
1929
|
+
* @see SidebarType
|
|
1930
|
+
* @see normalizeSidebar
|
|
1931
|
+
* @see SidebarObjectType
|
|
399
1932
|
*
|
|
400
|
-
* @
|
|
1933
|
+
* @since 2.0.0
|
|
1934
|
+
*/
|
|
1935
|
+
declare function normalizeSidebars(state: StateModel): SidebarObjectType;
|
|
1936
|
+
/**
|
|
1937
|
+
* Parses and populates the sidebar structure for all locales.
|
|
401
1938
|
*
|
|
402
1939
|
* @remarks
|
|
403
|
-
* -
|
|
404
|
-
* -
|
|
1940
|
+
* - Retrieves normalized sidebar items using {@link normalizeSidebars}.
|
|
1941
|
+
* - Iterates through all locales defined in `vitepressConfig.locales`.
|
|
1942
|
+
* - For each locale:
|
|
1943
|
+
* - Falls back to global sidebar (`sidebars.root`) if locale-specific sidebar is not defined.
|
|
1944
|
+
* - Ensures the locale’s `themeConfig` exists.
|
|
1945
|
+
* - Populates the locale’s `themeConfig.sidebar` using {@link populateSidebar}, applying versioning where applicable.
|
|
1946
|
+
*
|
|
1947
|
+
* This function ensures that all locales have a fully initialized and version-aware sidebar structure.
|
|
405
1948
|
*
|
|
406
1949
|
* @example
|
|
407
1950
|
* ```ts
|
|
408
|
-
*
|
|
1951
|
+
* parseSidebar();
|
|
1952
|
+
* // state.vitepressConfig.locales → each locale has `themeConfig.sidebar` populated
|
|
409
1953
|
* ```
|
|
410
1954
|
*
|
|
411
|
-
* @
|
|
1955
|
+
* @see SidebarType
|
|
1956
|
+
* @see populateSidebar
|
|
1957
|
+
* @see SidebarObjectType
|
|
1958
|
+
* @see normalizeSidebars
|
|
1959
|
+
*
|
|
1960
|
+
* @since 2.0.0
|
|
412
1961
|
*/
|
|
413
|
-
declare function
|
|
1962
|
+
declare function parseSidebar(): void;
|