@rspress/shared 1.5.1 → 1.6.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/dist/index.d.ts CHANGED
@@ -65,9 +65,11 @@ interface Config$1 {
65
65
  */
66
66
  outline?: boolean;
67
67
  /**
68
- * The nav items.
68
+ * The nav items. When it's an object, the key is the version of current doc.
69
69
  */
70
- nav?: NavItem[];
70
+ nav?: NavItem[] | {
71
+ [key: string]: NavItem[];
72
+ };
71
73
  /**
72
74
  * The sidebar items.
73
75
  */
@@ -141,7 +143,7 @@ interface LocaleConfig {
141
143
  /**
142
144
  * Theme i18n config
143
145
  */
144
- nav?: NavItem[];
146
+ nav?: Nav;
145
147
  sidebar?: Sidebar;
146
148
  outlineTitle?: string;
147
149
  lastUpdatedText?: string;
@@ -151,6 +153,9 @@ interface LocaleConfig {
151
153
  nextPageText?: string;
152
154
  langRoutePrefix?: string;
153
155
  }
156
+ type Nav = NavItem[] | {
157
+ [key: string]: NavItem[];
158
+ };
154
159
  type NavItem = NavItemWithLink | NavItemWithChildren | NavItemWithLinkAndChildren;
155
160
  type NavItemWithLink = {
156
161
  text: string;
@@ -162,13 +167,13 @@ type NavItemWithLink = {
162
167
  interface NavItemWithChildren {
163
168
  text?: string;
164
169
  tag?: string;
165
- items: NavItem[];
170
+ items: NavItemWithLink[];
166
171
  position?: 'left' | 'right';
167
172
  }
168
173
  interface NavItemWithLinkAndChildren {
169
174
  text: string;
170
175
  link: string;
171
- items: NavItem[];
176
+ items: NavItemWithLink[];
172
177
  tag?: string;
173
178
  activeMatch?: string;
174
179
  position?: 'left' | 'right';
@@ -178,13 +183,13 @@ type Image = string | {
178
183
  alt?: string;
179
184
  };
180
185
  interface Sidebar {
181
- [path: string]: (SidebarGroup | SidebarItem)[];
186
+ [path: string]: (SidebarGroup | SidebarItem | SidebarDivider)[];
182
187
  }
183
188
  interface SidebarGroup {
184
189
  text: string;
185
190
  link?: string;
186
191
  tag?: string;
187
- items: (SidebarItem | SidebarGroup | string)[];
192
+ items: (SidebarItem | SidebarDivider | SidebarGroup | string)[];
188
193
  collapsible?: boolean;
189
194
  collapsed?: boolean;
190
195
  }
@@ -193,6 +198,9 @@ type SidebarItem = {
193
198
  link: string;
194
199
  tag?: string;
195
200
  };
201
+ type SidebarDivider = {
202
+ dividerType: 'dashed' | 'solid';
203
+ };
196
204
  interface EditLink {
197
205
  /**
198
206
  * Custom repository url for edit link.
@@ -235,12 +243,12 @@ interface LocaleLink {
235
243
  link: string;
236
244
  }
237
245
  interface NormalizedSidebarGroup extends Omit<SidebarGroup, 'items'> {
238
- items: (SidebarItem | NormalizedSidebarGroup)[];
246
+ items: (SidebarDivider | SidebarItem | NormalizedSidebarGroup)[];
239
247
  collapsible: boolean;
240
248
  collapsed: boolean;
241
249
  }
242
250
  interface NormalizedSidebar {
243
- [path: string]: (NormalizedSidebarGroup | SidebarItem)[];
251
+ [path: string]: (NormalizedSidebarGroup | SidebarItem | SidebarDivider)[];
244
252
  }
245
253
  interface NormalizedLocales extends Omit<LocaleConfig, 'sidebar'> {
246
254
  sidebar: NormalizedSidebar;
@@ -664,10 +672,12 @@ declare const isProduction: () => boolean;
664
672
  declare const isDebugMode: () => boolean;
665
673
  declare const cleanUrl: (url: string) => string;
666
674
  declare function slash(str: string): string;
675
+ declare function removeHash(str: string): string;
667
676
  declare function normalizePosixPath(id: string): string;
668
677
  declare const inBrowser: () => boolean;
669
678
  declare function addLeadingSlash(url: string): string;
670
679
  declare function removeLeadingSlash(url: string): string;
680
+ declare function addTrailingSlash(url: string): string;
671
681
  declare function removeTrailingSlash(url: string): string;
672
682
  declare function normalizeSlash(url: string): string;
673
683
  declare function isExternalUrl(url: string): boolean;
@@ -699,4 +709,4 @@ declare function removeBase(url: string, base: string): string;
699
709
  declare function withoutHash(url: string): string;
700
710
  declare const mergeDocConfig: (...configs: UserConfig[]) => UserConfig;
701
711
 
702
- export { APPEARANCE_KEY, AdditionalPage, BaseRuntimePageInfo, Config, Config$1 as DefaultThemeConfig, DocFooter, EditLink, Feature, Footer, FrontMatterMeta, HASH_REGEXP, Header, Hero, Image, LocalSearchOptions, Locale, LocaleConfig, LocaleLink, LocaleLinks, MDX_REGEXP, MarkdownOptions, NavItem, NavItemWithChildren, NavItemWithLink, NavItemWithLinkAndChildren, NormalizedConfig, NormalizedConfig as NormalizedDefaultThemeConfig, NormalizedLocales, NormalizedSidebar, NormalizedSidebarGroup, PageData, PageIndexInfo, PageModule, PageType, RspressPlugin as Plugin, QUERY_REGEXP, RSPRESS_TEMP_DIR, RemotePageInfo, RemoteSearchIndexInfo, RemoteSearchOptions, ReplaceRule, Route, RouteMeta, RouteOptions, RspressPlugin, SEARCH_INDEX_NAME, SearchHooks, SearchOptions, Sidebar, SidebarGroup, SidebarItem, SiteData, SocialLink, SocialLinkIcon, UserConfig, addLeadingSlash, cleanUrl, inBrowser, isDebugMode, isExternalUrl, isProduction, isSCM, mergeDocConfig, normalizeHref, normalizePosixPath, normalizeSlash, omit, parseUrl, removeBase, removeLeadingSlash, removeTrailingSlash, replaceLang, replaceVersion, slash, withBase, withoutBase, withoutHash, withoutLang };
712
+ export { APPEARANCE_KEY, AdditionalPage, BaseRuntimePageInfo, Config, Config$1 as DefaultThemeConfig, DocFooter, EditLink, Feature, Footer, FrontMatterMeta, HASH_REGEXP, Header, Hero, Image, LocalSearchOptions, Locale, LocaleConfig, LocaleLink, LocaleLinks, MDX_REGEXP, MarkdownOptions, Nav, NavItem, NavItemWithChildren, NavItemWithLink, NavItemWithLinkAndChildren, NormalizedConfig, NormalizedConfig as NormalizedDefaultThemeConfig, NormalizedLocales, NormalizedSidebar, NormalizedSidebarGroup, PageData, PageIndexInfo, PageModule, PageType, RspressPlugin as Plugin, QUERY_REGEXP, RSPRESS_TEMP_DIR, RemotePageInfo, RemoteSearchIndexInfo, RemoteSearchOptions, ReplaceRule, Route, RouteMeta, RouteOptions, RspressPlugin, SEARCH_INDEX_NAME, SearchHooks, SearchOptions, Sidebar, SidebarDivider, SidebarGroup, SidebarItem, SiteData, SocialLink, SocialLinkIcon, UserConfig, addLeadingSlash, addTrailingSlash, cleanUrl, inBrowser, isDebugMode, isExternalUrl, isProduction, isSCM, mergeDocConfig, normalizeHref, normalizePosixPath, normalizeSlash, omit, parseUrl, removeBase, removeHash, removeLeadingSlash, removeTrailingSlash, replaceLang, replaceVersion, slash, withBase, withoutBase, withoutHash, withoutLang };
package/dist/index.js CHANGED
@@ -27,6 +27,7 @@ __export(src_exports, {
27
27
  RSPRESS_TEMP_DIR: () => RSPRESS_TEMP_DIR,
28
28
  SEARCH_INDEX_NAME: () => SEARCH_INDEX_NAME,
29
29
  addLeadingSlash: () => addLeadingSlash,
30
+ addTrailingSlash: () => addTrailingSlash,
30
31
  cleanUrl: () => cleanUrl,
31
32
  inBrowser: () => inBrowser,
32
33
  isDebugMode: () => isDebugMode,
@@ -40,6 +41,7 @@ __export(src_exports, {
40
41
  omit: () => omit,
41
42
  parseUrl: () => parseUrl,
42
43
  removeBase: () => removeBase,
44
+ removeHash: () => removeHash,
43
45
  removeLeadingSlash: () => removeLeadingSlash,
44
46
  removeTrailingSlash: () => removeTrailingSlash,
45
47
  replaceLang: () => replaceLang,
@@ -1121,6 +1123,9 @@ var cleanUrl = (url) => url.replace(HASH_REGEXP, "").replace(QUERY_REGEXP, "");
1121
1123
  function slash(str) {
1122
1124
  return str.replace(/\\/g, "/");
1123
1125
  }
1126
+ function removeHash(str) {
1127
+ return str.replace(/#.*$/, "");
1128
+ }
1124
1129
  function normalizePosixPath(id) {
1125
1130
  const path = slash(id);
1126
1131
  const isAbsolutePath = path.startsWith("/");
@@ -1152,6 +1157,9 @@ function addLeadingSlash(url) {
1152
1157
  function removeLeadingSlash(url) {
1153
1158
  return url.charAt(0) === "/" ? url.slice(1) : url;
1154
1159
  }
1160
+ function addTrailingSlash(url) {
1161
+ return url.charAt(url.length - 1) === "/" ? url : `${url}/`;
1162
+ }
1155
1163
  function removeTrailingSlash(url) {
1156
1164
  return url.charAt(url.length - 1) === "/" ? url.slice(0, -1) : url;
1157
1165
  }
@@ -1166,6 +1174,9 @@ function replaceLang(rawUrl, lang, version, base = "") {
1166
1174
  if (!url) {
1167
1175
  url = "/index.html";
1168
1176
  }
1177
+ if (url.endsWith("/")) {
1178
+ url += "index.html";
1179
+ }
1169
1180
  let versionPart = "";
1170
1181
  let langPart = "";
1171
1182
  let purePathPart = "";
@@ -1290,6 +1301,7 @@ var mergeDocConfig = (...configs) => mergeWith_default({}, ...configs, (target,
1290
1301
  RSPRESS_TEMP_DIR,
1291
1302
  SEARCH_INDEX_NAME,
1292
1303
  addLeadingSlash,
1304
+ addTrailingSlash,
1293
1305
  cleanUrl,
1294
1306
  inBrowser,
1295
1307
  isDebugMode,
@@ -1303,6 +1315,7 @@ var mergeDocConfig = (...configs) => mergeWith_default({}, ...configs, (target,
1303
1315
  omit,
1304
1316
  parseUrl,
1305
1317
  removeBase,
1318
+ removeHash,
1306
1319
  removeLeadingSlash,
1307
1320
  removeTrailingSlash,
1308
1321
  replaceLang,
package/dist/index.mjs CHANGED
@@ -1067,6 +1067,9 @@ var cleanUrl = (url) => url.replace(HASH_REGEXP, "").replace(QUERY_REGEXP, "");
1067
1067
  function slash(str) {
1068
1068
  return str.replace(/\\/g, "/");
1069
1069
  }
1070
+ function removeHash(str) {
1071
+ return str.replace(/#.*$/, "");
1072
+ }
1070
1073
  function normalizePosixPath(id) {
1071
1074
  const path = slash(id);
1072
1075
  const isAbsolutePath = path.startsWith("/");
@@ -1098,6 +1101,9 @@ function addLeadingSlash(url) {
1098
1101
  function removeLeadingSlash(url) {
1099
1102
  return url.charAt(0) === "/" ? url.slice(1) : url;
1100
1103
  }
1104
+ function addTrailingSlash(url) {
1105
+ return url.charAt(url.length - 1) === "/" ? url : `${url}/`;
1106
+ }
1101
1107
  function removeTrailingSlash(url) {
1102
1108
  return url.charAt(url.length - 1) === "/" ? url.slice(0, -1) : url;
1103
1109
  }
@@ -1112,6 +1118,9 @@ function replaceLang(rawUrl, lang, version, base = "") {
1112
1118
  if (!url) {
1113
1119
  url = "/index.html";
1114
1120
  }
1121
+ if (url.endsWith("/")) {
1122
+ url += "index.html";
1123
+ }
1115
1124
  let versionPart = "";
1116
1125
  let langPart = "";
1117
1126
  let purePathPart = "";
@@ -1235,6 +1244,7 @@ export {
1235
1244
  RSPRESS_TEMP_DIR,
1236
1245
  SEARCH_INDEX_NAME,
1237
1246
  addLeadingSlash,
1247
+ addTrailingSlash,
1238
1248
  cleanUrl,
1239
1249
  inBrowser,
1240
1250
  isDebugMode,
@@ -1248,6 +1258,7 @@ export {
1248
1258
  omit,
1249
1259
  parseUrl,
1250
1260
  removeBase,
1261
+ removeHash,
1251
1262
  removeLeadingSlash,
1252
1263
  removeTrailingSlash,
1253
1264
  replaceLang,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/shared",
3
- "version": "1.5.1",
3
+ "version": "1.6.1",
4
4
  "types": "./dist/index.d.ts",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",