@viteplus/versions 2.0.4 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -8,6 +8,7 @@ export type * from 'vitepress';
8
8
  import type { DefaultTheme, UserConfig } from 'vitepress';
9
9
  import type { DefaultTheme } from 'vitepress';
10
10
  import type { LocaleSpecificConfig } from 'vitepress';
11
+ import type { SidebarItemType } from '@viteplus/versions';
11
12
 
12
13
  /**
13
14
  * Import will remove at compile time
@@ -679,7 +680,7 @@ export type SidebarType = Array<SidebarItemType> | PathSidebarInterface;
679
680
  * @see SidebarItemType
680
681
  * @since 2.0.0
681
682
  */
682
- export type SidebarObjectType = Record<string, Array<SidebarItemType>>;
683
+ export type SidebarObjectType = Record<string, Array<SidebarItemType | SidebarGroupInterface>>;
683
684
 
684
685
  /**
685
686
  * Import will remove at compile time
@@ -916,7 +917,6 @@ type RequireKeysType<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
916
917
  *
917
918
  * const state = new StateModel(config).init();
918
919
  * console.log(state.versionsList);
919
- * console.log(state.fileMap);
920
920
  * ```
921
921
  *
922
922
  * @since 2.0.0
@@ -1015,19 +1015,6 @@ declare class StateModel {
1015
1015
  * @since 2.0.0
1016
1016
  */
1017
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
1018
  /**
1032
1019
  * Creates an instance of `StateModel`.
1033
1020
  *
@@ -1047,18 +1034,101 @@ declare class StateModel {
1047
1034
  */
1048
1035
  constructor(configuration?: ConfigurationInterface);
1049
1036
  /**
1050
- * Initializes the state by reading archive subfolders and building file maps.
1037
+ * Initializes the state model by scanning archive directory and setting up locale configuration.
1051
1038
  *
1052
- * @returns The instance itself (`this`) to allow method chaining.
1039
+ * @returns The current instance for method chaining.
1053
1040
  *
1054
1041
  * @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`.
1042
+ * This method performs the initial setup sequence for a multi-version documentation system
1043
+ * by discovering available versions and preparing the locale infrastructure. It executes
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
1062
1132
  *
1063
1133
  * @since 2.0.0
1064
1134
  */
@@ -1105,6 +1175,156 @@ declare class StateModel {
1105
1175
  private createVitepressConfig;
1106
1176
  }
1107
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
+
1108
1328
  /**
1109
1329
  * Import will remove at compile time
1110
1330
  */
@@ -1462,70 +1682,6 @@ declare function rewritesHook(source: string, version: string, locale: string):
1462
1682
  */
1463
1683
  declare function parseRoutesComponent(): void;
1464
1684
 
1465
- /**
1466
- * Imports
1467
- */
1468
- /**
1469
- * Deeply merges two object types into a single object.
1470
- *
1471
- * @typeParam T - The type of the first object.
1472
- * @typeParam U - The type of the second object.
1473
- *
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`.
1477
- *
1478
- * @remarks
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`.
1485
- *
1486
- * @example
1487
- * ```ts
1488
- * const obj1 = { a: 1, b: { c: 2, d: 3 } };
1489
- * const obj2 = { b: { c: 42 }, e: 99 };
1490
- *
1491
- * const merged = deepMerge(obj1, obj2);
1492
- * // Result: { a: 1, b: { c: 42, d: 3 }, e: 99 }
1493
- * ```
1494
- *
1495
- * @since 2.0.0
1496
- */
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>;
1528
-
1529
1685
  /**
1530
1686
  * Import will remove at compile time
1531
1687
  */
@@ -1700,6 +1856,56 @@ declare function normalizeNav(results: NavObjectType, nav: NavType, prefix?: str
1700
1856
  * @since 2.0.0
1701
1857
  */
1702
1858
  declare function normalizeNavs(state: StateModel): Record<string, Array<NavItemType>>;
1859
+ /**
1860
+ * Retrieves the appropriate navigation configuration for a given locale key.
1861
+ *
1862
+ * @param navs - The navigation configurations mapped by locale keys.
1863
+ * @param key - The locale key to retrieve navigation for (e.g., 'root', 'fr', 'fr/v1.0.0').
1864
+ * @returns The navigation configuration for the locale, falling back to parent locale or root.
1865
+ *
1866
+ * @remarks
1867
+ * This function implements a fallback strategy for finding navigation configurations:
1868
+ * 1. If an exact match exists for the key, return it
1869
+ * 2. If the key contains '/' (versioned locale), extract the base locale and try that
1870
+ * 3. If no base locale exists, fall back to 'root'
1871
+ *
1872
+ * This allows versioned locales (e.g., 'fr/v1.0.0', 'de/v2.0') to inherit navigation
1873
+ * from their base locale ('fr', 'de') without duplicating configuration.
1874
+ *
1875
+ * Fallback hierarchy examples:
1876
+ * - `'fr'` → Direct match, returns `navs.fr`
1877
+ * - `'fr/v1.0.0'` → No direct match → Checks `'fr'` → Returns `navs.fr`
1878
+ * - `'es/v1.0.0'` → No direct match → Checks `'es'` (doesn't exist) → Returns `navs.root`
1879
+ * - `'root'` → Direct match, returns `navs.root`
1880
+ *
1881
+ * @example
1882
+ * ```ts
1883
+ * const navs = {
1884
+ * root: [{ text: 'Home', link: '/' }],
1885
+ * fr: [{ text: 'Accueil', link: '/fr/' }],
1886
+ * de: [{ text: 'Startseite', link: '/de/' }]
1887
+ * };
1888
+ *
1889
+ * // Exact match
1890
+ * getNavForLocale(navs, 'fr'); // Returns fr nav
1891
+ *
1892
+ * // Versioned locale - inherits from base
1893
+ * getNavForLocale(navs, 'fr/v1.0.0'); // Returns fr nav
1894
+ * getNavForLocale(navs, 'de/v2.0'); // Returns de nav
1895
+ *
1896
+ * // No base locale exists - falls back to root
1897
+ * getNavForLocale(navs, 'es/v1.0.0'); // Returns root nav
1898
+ *
1899
+ * // Root locale
1900
+ * getNavForLocale(navs, 'root'); // Returns root nav
1901
+ * ```
1902
+ *
1903
+ * @see {@link parseNavs} - Uses this function to populate navigation for all locales
1904
+ * @see {@link NavItemType} - The navigation item type structure
1905
+ *
1906
+ * @since 2.0.5
1907
+ */
1908
+ declare function getNavForLocale(navs: Record<string, Array<NavItemType>>, key: string): Array<NavItemType>;
1703
1909
  /**
1704
1910
  * Parses and populates the navigation structure for all locales.
1705
1911
  *
@@ -1774,189 +1980,543 @@ declare function versionSwitcher(themeConfig: VersionsConfigInterface, versions:
1774
1980
  * Imports
1775
1981
  */
1776
1982
  /**
1777
- * Populates locale information in the VitePress configuration for all versions.
1983
+ * Deeply merges two object types into a single object.
1984
+ *
1985
+ * @typeParam T - The type of the first object.
1986
+ * @typeParam U - The type of the second object.
1987
+ *
1988
+ * @param obj1 - The base object whose properties will be merged.
1989
+ * @param obj2 - The object whose properties will overwrite or merge into `obj1`.
1990
+ * @returns A new object containing the deeply merged properties of both `obj1` and `obj2`.
1991
+ *
1992
+ * @remarks
1993
+ * - This function performs a deep merge, recursively merging nested objects.
1994
+ * - If a property exists in both `obj1` and `obj2`:
1995
+ * - If both values are plain objects, they are merged recursively.
1996
+ * - Otherwise, the value from `obj2` overwrites the value from `obj1`.
1997
+ * - Arrays are **not** merged; if a property is an array in `obj2`, it will replace
1998
+ * the corresponding property in `obj1`.
1999
+ *
2000
+ * @example
2001
+ * ```ts
2002
+ * const obj1 = { a: 1, b: { c: 2, d: 3 } };
2003
+ * const obj2 = { b: { c: 42 }, e: 99 };
2004
+ *
2005
+ * const merged = deepMerge(obj1, obj2);
2006
+ * // Result: { a: 1, b: { c: 42, d: 3 }, e: 99 }
2007
+ * ```
2008
+ *
2009
+ * @since 2.0.0
2010
+ */
2011
+ declare function deepMerge<T extends object, U extends object>(obj1: T, obj2: U): T & U;
2012
+ /**
2013
+ * Recursively collects all Markdown (`.md`) files within a given directory,
2014
+ * returning their paths relative to a specified root directory.
2015
+ *
2016
+ * @param rootDir - The root directory used as the base for relative paths.
2017
+ * @param currentDir - The current directory to scan. Defaults to `rootDir`.
2018
+ * @returns An array of relative file paths to Markdown files.
1778
2019
  *
1779
2020
  * @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.
2021
+ * - This function traverses directories recursively.
2022
+ * - Only files with a `.md` extension are included in the results.
2023
+ * - Returned paths are **relative to `rootDir`**, regardless of how deep the files are nested.
2024
+ * - Uses Node.js `fs.readdirSync` with `withFileTypes: true` for efficient directory traversal.
1784
2025
  *
1785
2026
  * @example
1786
2027
  * ```ts
1787
- * parseLocale();
1788
- * console.log(state.vitepressConfig.locales);
1789
- * // → { root: { lang: "en", label: "English" }, "1.0/en": { lang: "en" }, ... }
2028
+ * const markdownFiles = getAllMarkdownFilesRelative("/project/docs");
2029
+ *
2030
+ * console.log(markdownFiles);
2031
+ * // Example output:
2032
+ * // [
2033
+ * // "README.md",
2034
+ * // "guide/intro.md",
2035
+ * // "tutorial/setup.md"
2036
+ * // ]
1790
2037
  * ```
1791
2038
  *
1792
2039
  * @since 2.0.0
1793
2040
  */
1794
- declare function parseLocale(): void;
2041
+ declare function getAllMarkdownFilesRelative(rootDir: string, currentDir?: string): Array<string>;
1795
2042
 
1796
2043
  /**
1797
2044
  * Import will remove at compile time
1798
2045
  */
1799
2046
  /**
1800
- * Populates sidebar items with versioned base paths.
1801
- *
1802
- * @param sidebar - The list of sidebar {@link SidebarItemType} items to transform.
1803
- * @param version - The version key (e.g., `"en"`, `"v1.0"`, `"root"`).
2047
+ * Populates sidebar items with version-specific base paths.
1804
2048
  *
1805
- * @returns A new sidebar array with versioned `base` properties applied.
2049
+ * @param sidebar - Array of sidebar items to process {@link SidebarItemType}.
2050
+ * @param version - The version string to apply to base paths, or 'root' for the default version.
2051
+ * @returns A new array of sidebar items with updated base paths.
1806
2052
  *
1807
2053
  * @remarks
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.
2054
+ * This function transforms sidebar items by adding version-specific base paths to enable
2055
+ * multi-version documentation navigation. It processes each sidebar item according to
2056
+ * specific rules:
2057
+ *
2058
+ * **Skipped items** (returned unchanged):
2059
+ * - Items with `skipVersioning: true` flag
2060
+ * - Items with external links (starting with 'http')
2061
+ * - Items without links or nested items
2062
+ * - Items when a version is empty or 'root'
2063
+ *
2064
+ * **Processed items**:
2065
+ * - The base path is prepended with a version: `/{version}/{base}/`
2066
+ * - Original item properties are preserved via spread operator
2067
+ * - The normalized version replaces 'root' with empty string
2068
+ *
2069
+ * The base path structure follows the pattern: `/{version}/{originalBase}/`
2070
+ * using {@link join} from path/posix for consistent URL formatting across platforms.
1812
2071
  *
1813
2072
  * @example
1814
2073
  * ```ts
1815
- * const sidebar: SidebarItemType[] = [
1816
- * { text: "Introduction", link: "/intro" },
1817
- * {
1818
- * text: "Guide",
1819
- * items: [
1820
- * { text: "Setup", link: "/setup" }
1821
- * ]
1822
- * }
2074
+ * const sidebar: Array<SidebarItemType> = [
2075
+ * { text: 'Guide', link: '/guide/', base: '/docs' },
2076
+ * { text: 'API', link: '/api/', base: '/reference' },
2077
+ * { text: 'External', link: 'https://example.com' },
2078
+ * { text: 'Skip', link: '/skip/', skipVersioning: true }
1823
2079
  * ];
1824
2080
  *
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
- * ]
2081
+ * const versioned = populateSidebar(sidebar, 'v2.0');
2082
+ * // [
2083
+ * // { text: 'Guide', link: '/guide/', base: '/v2.0/docs/' },
2084
+ * // { text: 'API', link: '/api/', base: '/v2.0/reference/' },
2085
+ * // { text: 'External', link: 'https://example.com' },
2086
+ * // { text: 'Skip', link: '/skip/', skipVersioning: true }
2087
+ * // ]
2088
+ *
2089
+ * // Root version (no prefix)
2090
+ * const rootVersioned = populateSidebar(sidebar, 'root');
2091
+ * // Base paths remain unchanged
2092
+ *
2093
+ * // Use case: Version-specific sidebar configuration
2094
+ * const versions = ['v1.0', 'v2.0', 'latest'];
2095
+ * const sidebarConfigs = versions.map(version => ({
2096
+ * version,
2097
+ * items: populateSidebar(baseSidebar, version)
2098
+ * }));
1839
2099
  * ```
1840
2100
  *
1841
2101
  * @see SidebarItemType
1842
- * @since 2.0.0
2102
+ * @since 2.0.5
1843
2103
  */
1844
2104
  declare function populateSidebar(sidebar: Array<SidebarItemType>, version: string): Array<SidebarItemType>;
1845
2105
  /**
1846
- * Normalizes a sidebar definition into a flat {@link SidebarObjectType} structure.
2106
+ * Extracts locale and version information from URL path segments.
1847
2107
  *
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 `{}`).
1852
- *
1853
- * @returns void — Mutates the `results` object directly by appending normalized sidebar items.
2108
+ * @param segments - Array of URL path segments to parse (will be modified by shifting elements).
2109
+ * @param localesList - List of valid locale identifiers for matching.
2110
+ * @param versionsList - List of valid version identifiers for matching.
2111
+ * @returns An object containing extracted language and version {@link PathSegmentsInterface}.
1854
2112
  *
1855
2113
  * @remarks
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.
2114
+ * This function parses URL path segments to identify and extract locale and version
2115
+ * information, supporting both version-first and locale-first URL structures. The
2116
+ * function operates on the segment array destructively, removing matched elements
2117
+ * via {@link Array.shift}.
2118
+ *
2119
+ * **Parsing logic**:
2120
+ * 1. If the first segment matches a version → return `{ lang: '', version }` (version-first pattern)
2121
+ * 2. If the first segment matches a locale → extract it as `lang` (locale-first pattern)
2122
+ * 3. If the second segment matches a version → extract it as `version`
2123
+ * 4. Return both extracted values (empty strings if not found)
2124
+ *
2125
+ * **URL patterns supported**:
2126
+ * - `/v2.0/guide/` → `{ lang: '', version: 'v2.0' }`
2127
+ * - `/fr/v2.0/guide/` → `{ lang: 'fr', version: 'v2.0' }`
2128
+ * - `/fr/guide/` → `{ lang: 'fr', version: '' }`
2129
+ * - `/guide/` → `{ lang: '', version: '' }`
2130
+ *
2131
+ * The segment array is mutated during extraction, with matched segments removed
2132
+ * from the beginning. This allows the following processing to work with the remaining
2133
+ * path components.
1860
2134
  *
1861
2135
  * @example
1862
2136
  * ```ts
1863
- * const results: SidebarObjectType = {};
1864
- * normalizeSidebar(results, [
1865
- * { text: "Intro", link: "/intro" }
1866
- * ]);
2137
+ * const localesList = ['en', 'fr', 'de'];
2138
+ * const versionsList = ['v1.0', 'v2.0', 'latest'];
2139
+ *
2140
+ * // Version-first pattern
2141
+ * const segments1 = ['v2.0', 'guide', 'intro'];
2142
+ * const result1 = extractLocale(segments1, localesList, versionsList);
2143
+ * console.log(result1); // { lang: '', version: 'v2.0' }
2144
+ * console.log(segments1); // ['guide', 'intro']
2145
+ *
2146
+ * // Locale-first pattern
2147
+ * const segments2 = ['fr', 'v2.0', 'api', 'reference'];
2148
+ * const result2 = extractLocale(segments2, localesList, versionsList);
2149
+ * console.log(result2); // { lang: 'fr', version: 'v2.0' }
2150
+ * console.log(segments2); // ['api', 'reference']
2151
+ *
2152
+ * // No locale or version
2153
+ * const segments3 = ['docs', 'getting-started'];
2154
+ * const result3 = extractLocale(segments3, localesList, versionsList);
2155
+ * console.log(result3); // { lang: '', version: '' }
2156
+ * console.log(segments3); // ['docs', 'getting-started']
2157
+ *
2158
+ * // Use case: URL parsing for routing
2159
+ * const url = '/de/latest/guide/installation';
2160
+ * const segments = url.split('/').filter(Boolean);
2161
+ * const { lang, version } = extractLocale(
2162
+ * segments,
2163
+ * ['en', 'de', 'fr'],
2164
+ * ['latest', 'v1', 'v2']
2165
+ * );
2166
+ * const route = segments.join('/');
2167
+ * console.log({ lang, version, route });
2168
+ * // { lang: 'de', version: 'latest', route: 'guide/installation' }
2169
+ * ```
2170
+ *
2171
+ * @see PathSegmentsInterface
2172
+ * @since 2.0.5
2173
+ */
2174
+ declare function extractLocale(segments: Array<string>, localesList: Array<string>, versionsList: Array<string>): PathSegmentsInterface;
2175
+ /**
2176
+ * Normalizes sidebar configuration into a structured format for multi-version documentation.
2177
+ *
2178
+ * @param state - The state model containing configuration data {@link StateModel}.
2179
+ * @param results - Accumulator object to store normalized sidebar entries {@link SidebarObjectType}.
2180
+ * @param sidebar - The sidebar configuration to normalize {@link SidebarType}.
2181
+ * @param prefix - Locale prefix for the sidebar (e.g., 'root', 'fr', 'de').
1867
2182
  *
1868
- * // Result:
2183
+ * @remarks
2184
+ * This function transforms sidebar configurations from various input formats into a
2185
+ * normalized structure that supports multi-version, multi-locale documentation. It
2186
+ * handles both array-based and object-based sidebar definitions.
2187
+ *
2188
+ * **Input formats supported**:
2189
+ * - **Array format**: Simple list of sidebar items for a single path
2190
+ * - **Object format**: Key-value pairs where keys are paths and values are sidebar items
2191
+ * - **Undefined**: Gracefully handles missing sidebar configuration
2192
+ *
2193
+ * **Normalization process**:
2194
+ * 1. Early return if the sidebar is undefined
2195
+ * 2. Convert the 'root' prefix to an empty string for URL normalization
2196
+ * 3. For array format: Store items under the normalized path
2197
+ * 4. For object format: Parse each key to extract locale/version using {@link extractLocale}
2198
+ * 5. Filter entries that don't match the current locale prefix
2199
+ * 6. Construct versioned paths and store items in the result accumulator
2200
+ *
2201
+ * **Results structure**:
2202
+ * ```ts
1869
2203
  * {
1870
- * root: [
1871
- * { text: "Intro", link: "/intro" }
1872
- * ]
2204
+ * 'root': { '/': [...items], '/guide/': [...items] },
2205
+ * 'fr': { '/fr/': [...items], '/fr/guide/': [...items] },
2206
+ * 'fr/v2.0': { '/fr/v2.0/': [...items] }
1873
2207
  * }
1874
2208
  * ```
1875
2209
  *
2210
+ * The function uses state data to access:
2211
+ * - {@link StateModel.localesMap} for valid locale identifiers
2212
+ * - {@link StateModel.versionsList} for valid version identifiers
2213
+ *
1876
2214
  * @example
1877
2215
  * ```ts
1878
- * const results: SidebarObjectType = {};
1879
- * normalizeSidebar(results, {
1880
- * guide: [
1881
- * { text: "Getting Started", link: "/guide/start" }
1882
- * ]
1883
- * }, "en");
2216
+ * const state = new StateModel(config).init();
2217
+ * const results: Record<string, SidebarObjectType> = {};
1884
2218
  *
1885
- * // Result:
1886
- * {
1887
- * "en/guide": [
1888
- * { text: "Getting Started", link: "/guide/start" }
1889
- * ]
2219
+ * // Array format sidebar
2220
+ * const arraySidebar = [
2221
+ * { text: 'Guide', link: '/guide/' },
2222
+ * { text: 'API', link: '/api/' }
2223
+ * ];
2224
+ * normalizeSidebar(state, results, arraySidebar, 'root');
2225
+ * // results = { 'root': { '/': [{ text: 'Guide', ... }, { text: 'API', ... }] } }
2226
+ *
2227
+ * // Object format sidebar
2228
+ * const objectSidebar = {
2229
+ * '/': [{ text: 'Home', link: '/' }],
2230
+ * '/guide/': [{ text: 'Getting Started', link: '/guide/start' }],
2231
+ * '/fr/guide/': [{ text: 'Commencer', link: '/fr/guide/start' }]
2232
+ * };
2233
+ * normalizeSidebar(state, results, objectSidebar, 'root');
2234
+ *
2235
+ * // With locale prefix
2236
+ * normalizeSidebar(state, results, objectSidebar, 'fr');
2237
+ * // Only '/fr/guide/' entries are processed
2238
+ *
2239
+ * // Use case: Multi-locale sidebar processing
2240
+ * const results = {};
2241
+ * const locales = ['root', 'fr', 'de'];
2242
+ * for (const locale of locales) {
2243
+ * const sidebar = getLocaleSidebar(locale);
2244
+ * normalizeSidebar(state, results, sidebar, locale);
1890
2245
  * }
1891
2246
  * ```
1892
2247
  *
2248
+ * @see StateModel
1893
2249
  * @see SidebarType
2250
+ * @see extractLocale
1894
2251
  * @see SidebarObjectType
1895
2252
  *
1896
- * @since 2.0.0
2253
+ * @since 2.0.5
1897
2254
  */
1898
- declare function normalizeSidebar(results: SidebarObjectType, sidebar: SidebarType, prefix?: string, root?: SidebarObjectType): void;
2255
+ declare function normalizeSidebar(state: StateModel, results: Record<string, SidebarObjectType>, sidebar?: SidebarType, prefix?: string): void;
1899
2256
  /**
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.
2257
+ * Normalizes all sidebar configurations across locales and versions.
1906
2258
  *
1907
- * @returns A flat {@link SidebarObjectType} where each key corresponds to a locale
1908
- * or `"root"` and contains an array of normalized sidebar items.
2259
+ * @param state - The state model containing configuration data {@link StateModel}.
2260
+ * @returns A normalized sidebar structure organized by locale and path {@link SidebarObjectType}.
1909
2261
  *
1910
2262
  * @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.
2263
+ * This function orchestrates the complete normalization of all sidebar configurations
2264
+ * in a multi-version, multi-locale documentation site. It processes sidebars from both
2265
+ * global theme configuration and locale-specific settings, then propagates them to all
2266
+ * versioned locale entries.
2267
+ *
2268
+ * **Processing stages**:
2269
+ * 1. **Initial Normalization**: Process sidebars from global theme config and each locale's
2270
+ * theme config using {@link normalizeSidebar}
2271
+ * 2. **Version Propagation**: For each locale entry in {@link StateModel.vitepressConfig},
2272
+ * if it lacks a normalized sidebar, inherit from its parent locale
2273
+ * 3. **Path Adjustment**: Adjust inherited paths to include the version/locale prefix
2274
+ *
2275
+ * **Data sources processed**:
2276
+ * - {@link StateModel.configuration.themeConfig.sidebar}: Global sidebar configuration
2277
+ * - Each locale's `themeConfig.sidebar`: Locale-specific sidebar configuration
2278
+ *
2279
+ * **Output structure**:
2280
+ * ```ts
2281
+ * {
2282
+ * 'root': { '/': [...], '/guide/': [...] },
2283
+ * 'v2.0': { '/v2.0/': [...], '/v2.0/guide/': [...] },
2284
+ * 'fr': { '/fr/': [...], '/fr/guide/': [...] },
2285
+ * 'fr/v2.0': { '/fr/v2.0/': [...], '/fr/v2.0/guide/': [...] }
2286
+ * }
2287
+ * ```
2288
+ *
2289
+ * The function ensures that every locale entry in the VitePress configuration has
2290
+ * appropriate sidebar items, either directly defined or inherited from parent locales.
2291
+ * This enables consistent navigation across all versions and locales.
1917
2292
  *
1918
2293
  * @example
1919
2294
  * ```ts
2295
+ * const state = new StateModel({
2296
+ * themeConfig: {
2297
+ * sidebar: {
2298
+ * '/': [{ text: 'Home', link: '/' }],
2299
+ * '/guide/': [{ text: 'Guide', link: '/guide/' }]
2300
+ * }
2301
+ * },
2302
+ * locales: {
2303
+ * root: { lang: 'en-US' },
2304
+ * '/fr/': {
2305
+ * lang: 'fr-FR',
2306
+ * themeConfig: {
2307
+ * sidebar: {
2308
+ * '/fr/guide/': [{ text: 'Guide', link: '/fr/guide/' }]
2309
+ * }
2310
+ * }
2311
+ * }
2312
+ * },
2313
+ * versionsConfig: {
2314
+ * sources: 'src',
2315
+ * archive: 'versions'
2316
+ * }
2317
+ * }).init();
2318
+ *
2319
+ * const normalized = normalizeSidebars(state);
2320
+ *
2321
+ * console.log(Object.keys(normalized));
2322
+ * // ['root', 'v1.0', 'v2.0', 'fr', 'fr/v1.0', 'fr/v2.0']
2323
+ *
2324
+ * console.log(normalized['v2.0']);
2325
+ * // { '/v2.0/': [...], '/v2.0/guide/': [...] }
2326
+ *
2327
+ * console.log(normalized['fr/v2.0']);
2328
+ * // { '/fr/v2.0/': [...], '/fr/v2.0/guide/': [...] }
2329
+ *
2330
+ * // Use case: Building a complete sidebar structure
1920
2331
  * const state = inject(StateModel);
1921
2332
  * 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
- * // }
2333
+ *
2334
+ * // Apply to VitePress config
2335
+ * for (const [locale, paths] of Object.entries(sidebars)) {
2336
+ * vitepressConfig.locales[locale].themeConfig.sidebar = paths;
2337
+ * }
1927
2338
  * ```
1928
2339
  *
1929
- * @see SidebarType
2340
+ * @see StateModel
2341
+ * @see extractLocale
1930
2342
  * @see normalizeSidebar
1931
2343
  * @see SidebarObjectType
1932
2344
  *
1933
- * @since 2.0.0
2345
+ * @since 2.0.5
1934
2346
  */
1935
- declare function normalizeSidebars(state: StateModel): SidebarObjectType;
2347
+ declare function normalizeSidebars(state: StateModel): Record<string, SidebarObjectType>;
1936
2348
  /**
1937
- * Parses and populates the sidebar structure for all locales.
2349
+ * Parses and applies sidebar configurations to all locales in the VitePress configuration.
1938
2350
  *
1939
2351
  * @remarks
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.
2352
+ * This function is the main entry point for sidebar processing in a multi-version,
2353
+ * multi-locale documentation system. It coordinates the complete sidebar normalization
2354
+ * and population workflow by:
2355
+ *
2356
+ * 1. **Injecting State**: Retrieves the {@link StateModel} singleton instance
2357
+ * 2. **Normalizing**: Calls {@link normalizeSidebars} to process all sidebar configurations
2358
+ * 3. **Applying**: Iterates through each locale in {@link StateModel.vitepressConfig.locales}
2359
+ * 4. **Populating**: Uses {@link populateSidebar} to add version-specific base paths
2360
+ * 5. **Merging**: Assigns processed sidebars to each locale's theme configuration
2361
+ *
2362
+ * **Sidebar structure handling**:
2363
+ * - Initializes `themeConfig` if it doesn't exist
2364
+ * - Converts array-based sidebars to object format for consistent processing
2365
+ * - Preserves existing sidebar structure when no normalized version exists
2366
+ * - Ensures sidebar is always in object format after processing
2367
+ *
2368
+ * The function modifies the VitePress configuration in place, updating each locale's
2369
+ * `themeConfig.sidebar` with the normalized and versioned sidebar items. This ensures
2370
+ * that all routes have appropriate navigation structures.
2371
+ *
2372
+ * **Processing flow**:
2373
+ * ```
2374
+ * User Config → normalizeSidebars() → Normalized Structure
2375
+ * ↓
2376
+ * VitePress Config ← populateSidebar() ← Per-Locale Items
2377
+ * ```
1948
2378
  *
1949
2379
  * @example
1950
2380
  * ```ts
1951
- * parseSidebar();
1952
- * // state.vitepressConfig.locales → each locale has `themeConfig.sidebar` populated
2381
+ * // Setup configuration
2382
+ * const config = {
2383
+ * themeConfig: {
2384
+ * sidebar: {
2385
+ * '/': [{ text: 'Home', link: '/' }],
2386
+ * '/guide/': [{ text: 'Getting Started', link: '/guide/start' }]
2387
+ * }
2388
+ * },
2389
+ * locales: {
2390
+ * root: { lang: 'en-US', label: 'English' },
2391
+ * '/fr/': {
2392
+ * lang: 'fr-FR',
2393
+ * label: 'Français',
2394
+ * themeConfig: {
2395
+ * sidebar: {
2396
+ * '/fr/guide/': [{ text: 'Commencer', link: '/fr/guide/start' }]
2397
+ * }
2398
+ * }
2399
+ * }
2400
+ * }
2401
+ * };
2402
+ *
2403
+ * const state = new StateModel(config).init();
2404
+ * provide(StateModel, state);
2405
+ *
2406
+ * // Parse and apply sidebars
2407
+ * parseSidebars();
2408
+ *
2409
+ * // Result: Each locale now has versioned sidebars
2410
+ * console.log(state.vitepressConfig.locales['v2.0'].themeConfig.sidebar);
2411
+ * // {
2412
+ * // '/v2.0/': [{ text: 'Home', link: '/', base: '/v2.0/' }],
2413
+ * // '/v2.0/guide/': [{ text: 'Getting Started', link: '/guide/start', base: '/v2.0/guide/' }]
2414
+ * // }
2415
+ *
2416
+ * console.log(state.vitepressConfig.locales['fr/v2.0'].themeConfig.sidebar);
2417
+ * // {
2418
+ * // '/fr/v2.0/guide/': [{ text: 'Commencer', link: '/fr/guide/start', base: '/fr/v2.0/guide/' }]
2419
+ * // }
2420
+ *
2421
+ * // Use case: Integration in VitePress config hook
2422
+ * export default defineConfig({
2423
+ * async buildStart() {
2424
+ * parseSidebars();
2425
+ * },
2426
+ * // ... rest of config
2427
+ * });
1953
2428
  * ```
1954
2429
  *
1955
- * @see SidebarType
2430
+ * @see StateModel
1956
2431
  * @see populateSidebar
1957
- * @see SidebarObjectType
1958
2432
  * @see normalizeSidebars
1959
2433
  *
1960
- * @since 2.0.0
2434
+ * @since 2.0.5
2435
+ */
2436
+ declare function parseSidebars(): void;
2437
+
2438
+ /**
2439
+ * Represents extracted locale and version information from URL path segments.
2440
+ *
2441
+ * @remarks
2442
+ * This interface defines the structure returned by {@link extractLocale} when parsing
2443
+ * URL paths in a multi-version, multi-locale documentation system. It separates the
2444
+ * locale identifier from the version identifier, enabling proper routing and content
2445
+ * resolution.
2446
+ *
2447
+ * Both properties use empty strings as sentinel values to indicate absence, rather
2448
+ * than undefined or null, simplifying string concatenation and path construction
2449
+ * operations.
2450
+ *
2451
+ * Common usage patterns:
2452
+ * - Route parsing and URL analysis
2453
+ * - Content path resolution
2454
+ * - Locale and version detection from request URLs
2455
+ * - Sidebar and navigation path construction
2456
+ * - Determining which content variant to serve
2457
+ *
2458
+ * The interface supports various URL structures:
2459
+ * - Root locale, no version: `{ lang: '', version: '' }` → `/guide/`
2460
+ * - Root locale with version: `{ lang: '', version: 'v2.0' }` → `/v2.0/guide/`
2461
+ * - Specific locale, no version: `{ lang: 'fr', version: '' }` → `/fr/guide/`
2462
+ * - Specific locale with version: `{ lang: 'fr', version: 'v2.0' }` → `/fr/v2.0/guide/`
2463
+ *
2464
+ * @example
2465
+ * ```ts
2466
+ * // Parse URL segments
2467
+ * const segments = ['fr', 'v2.0', 'guide', 'intro'];
2468
+ * const result: PathSegmentsInterface = extractLocale(
2469
+ * segments,
2470
+ * ['en', 'fr', 'de'],
2471
+ * ['v1.0', 'v2.0', 'latest']
2472
+ * );
2473
+ * console.log(result);
2474
+ * // { lang: 'fr', version: 'v2.0' }
2475
+ *
2476
+ * // Handle missing locale/version
2477
+ * const segments2 = ['docs', 'api'];
2478
+ * const result2: PathSegmentsInterface = extractLocale(segments2, locales, versions);
2479
+ * console.log(result2);
2480
+ * // { lang: '', version: '' }
2481
+ *
2482
+ * // Use in routing logic
2483
+ * function resolveContent(path: string): string {
2484
+ * const segments = path.split('/').filter(Boolean);
2485
+ * const { lang, version }: PathSegmentsInterface = extractLocale(
2486
+ * segments,
2487
+ * availableLocales,
2488
+ * availableVersions
2489
+ * );
2490
+ *
2491
+ * const contentPath = [
2492
+ * lang || 'en',
2493
+ * version || 'latest',
2494
+ * ...segments
2495
+ * ].join('/');
2496
+ *
2497
+ * return loadContent(contentPath);
2498
+ * }
2499
+ *
2500
+ * // Use in path construction
2501
+ * function buildPath(info: PathSegmentsInterface, ...segments: string[]): string {
2502
+ * const parts = [
2503
+ * info.lang,
2504
+ * info.version,
2505
+ * ...segments
2506
+ * ].filter(Boolean);
2507
+ *
2508
+ * return '/' + parts.join('/');
2509
+ * }
2510
+ *
2511
+ * const pathInfo: PathSegmentsInterface = { lang: 'de', version: 'v3.0' };
2512
+ * console.log(buildPath(pathInfo, 'guide', 'intro'));
2513
+ * // '/de/v3.0/guide/intro'
2514
+ * ```
2515
+ *
2516
+ * @see extractLocale
2517
+ * @since 2.0.5
1961
2518
  */
1962
- declare function parseSidebar(): void;
2519
+ interface PathSegmentsInterface {
2520
+ lang: string;
2521
+ version: string;
2522
+ }