@rspress/shared 0.0.0-next-20230927072732 → 0.0.0-next-20231108104528

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
@@ -1,6 +1,6 @@
1
- import { BuilderConfig } from '@modern-js/builder-rspack-provider';
1
+ import { RsbuildPlugin } from '@rsbuild/core';
2
+ import { RsbuildConfig } from '@rsbuild/core/rspack-provider';
2
3
  import { PluggableList } from 'unified';
3
- import { BuilderPlugin } from '@modern-js/builder';
4
4
 
5
5
  interface ZoomOptions {
6
6
  /**
@@ -57,7 +57,7 @@ interface Config$1 {
57
57
  /**
58
58
  * Custom outline title in the aside component.
59
59
  *
60
- * @default 'On this page'
60
+ * @default 'ON THIS PAGE'
61
61
  */
62
62
  outlineTitle?: string;
63
63
  /**
@@ -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
  */
@@ -119,13 +121,9 @@ interface Config$1 {
119
121
  */
120
122
  search?: boolean;
121
123
  /**
122
- * Whether to use back top
123
- */
124
- backTop?: boolean;
125
- /**
126
- * Whether to hide the navbar
124
+ * The behavior of hiding navbar
127
125
  */
128
- hideNavbar?: boolean;
126
+ hideNavbar?: 'always' | 'auto' | 'never';
129
127
  /**
130
128
  * Whether to enable the animation for translation pages
131
129
  */
@@ -145,7 +143,7 @@ interface LocaleConfig {
145
143
  /**
146
144
  * Theme i18n config
147
145
  */
148
- nav?: NavItem[];
146
+ nav?: Nav;
149
147
  sidebar?: Sidebar;
150
148
  outlineTitle?: string;
151
149
  lastUpdatedText?: string;
@@ -155,6 +153,9 @@ interface LocaleConfig {
155
153
  nextPageText?: string;
156
154
  langRoutePrefix?: string;
157
155
  }
156
+ type Nav = NavItem[] | {
157
+ [key: string]: NavItem[];
158
+ };
158
159
  type NavItem = NavItemWithLink | NavItemWithChildren | NavItemWithLinkAndChildren;
159
160
  type NavItemWithLink = {
160
161
  text: string;
@@ -166,13 +167,13 @@ type NavItemWithLink = {
166
167
  interface NavItemWithChildren {
167
168
  text?: string;
168
169
  tag?: string;
169
- items: NavItem[];
170
+ items: NavItemWithLink[];
170
171
  position?: 'left' | 'right';
171
172
  }
172
173
  interface NavItemWithLinkAndChildren {
173
174
  text: string;
174
175
  link: string;
175
- items: NavItem[];
176
+ items: NavItemWithLink[];
176
177
  tag?: string;
177
178
  activeMatch?: string;
178
179
  position?: 'left' | 'right';
@@ -182,13 +183,13 @@ type Image = string | {
182
183
  alt?: string;
183
184
  };
184
185
  interface Sidebar {
185
- [path: string]: (SidebarGroup | SidebarItem)[];
186
+ [path: string]: (SidebarGroup | SidebarItem | SidebarDivider)[];
186
187
  }
187
188
  interface SidebarGroup {
188
189
  text: string;
189
190
  link?: string;
190
191
  tag?: string;
191
- items: (SidebarItem | SidebarGroup | string)[];
192
+ items: (SidebarItem | SidebarDivider | SidebarGroup | string)[];
192
193
  collapsible?: boolean;
193
194
  collapsed?: boolean;
194
195
  }
@@ -197,6 +198,9 @@ type SidebarItem = {
197
198
  link: string;
198
199
  tag?: string;
199
200
  };
201
+ type SidebarDivider = {
202
+ dividerType: 'dashed' | 'solid';
203
+ };
200
204
  interface EditLink {
201
205
  /**
202
206
  * Custom repository url for edit link.
@@ -224,7 +228,7 @@ interface SocialLink {
224
228
  mode: 'link' | 'text' | 'img';
225
229
  content: string;
226
230
  }
227
- type SocialLinkIcon = 'lark' | 'discord' | 'facebook' | 'github' | 'instagram' | 'linkedin' | 'slack' | 'twitter' | 'youtube' | 'weixin' | 'qq' | 'juejin' | 'zhihu' | 'bilibili' | 'weibo' | 'gitlab' | {
231
+ type SocialLinkIcon = 'lark' | 'discord' | 'facebook' | 'github' | 'instagram' | 'linkedin' | 'slack' | 'twitter' | 'youtube' | 'wechat' | 'qq' | 'juejin' | 'zhihu' | 'bilibili' | 'weibo' | 'gitlab' | {
228
232
  svg: string;
229
233
  };
230
234
  interface Footer {
@@ -239,12 +243,12 @@ interface LocaleLink {
239
243
  link: string;
240
244
  }
241
245
  interface NormalizedSidebarGroup extends Omit<SidebarGroup, 'items'> {
242
- items: (SidebarItem | NormalizedSidebarGroup)[];
246
+ items: (SidebarDivider | SidebarItem | NormalizedSidebarGroup)[];
243
247
  collapsible: boolean;
244
248
  collapsed: boolean;
245
249
  }
246
250
  interface NormalizedSidebar {
247
- [path: string]: (NormalizedSidebarGroup | SidebarItem)[];
251
+ [path: string]: (NormalizedSidebarGroup | SidebarItem | SidebarDivider)[];
248
252
  }
249
253
  interface NormalizedLocales extends Omit<LocaleConfig, 'sidebar'> {
250
254
  sidebar: NormalizedSidebar;
@@ -282,9 +286,9 @@ interface RspressPlugin {
282
286
  globalComponents?: string[];
283
287
  };
284
288
  /**
285
- * Builder config.
289
+ * Rsbuild config.
286
290
  */
287
- builderConfig?: BuilderConfig;
291
+ builderConfig?: RsbuildConfig;
288
292
  /**
289
293
  * Inject global components.
290
294
  */
@@ -292,29 +296,36 @@ interface RspressPlugin {
292
296
  /**
293
297
  * Modify doc config.
294
298
  */
295
- config?: (config: UserConfig) => UserConfig | Promise<UserConfig>;
299
+ config?: (config: UserConfig, utils: {
300
+ addPlugin: (plugin: RspressPlugin) => void;
301
+ removePlugin: (pluginName: string) => void;
302
+ }, isProd: boolean) => UserConfig | Promise<UserConfig>;
296
303
  /**
297
304
  * Callback before build
298
305
  */
299
- beforeBuild?: (config: UserConfig, isProd: boolean) => Promise<void>;
306
+ beforeBuild?: (config: UserConfig, isProd: boolean) => void | Promise<void>;
300
307
  /**
301
308
  * Callback after build
302
309
  */
303
- afterBuild?: (config: UserConfig, isProd: boolean) => Promise<void>;
310
+ afterBuild?: (config: UserConfig, isProd: boolean) => void | Promise<void>;
304
311
  /**
305
312
  * Extend every page's data
306
313
  */
307
314
  extendPageData?: (pageData: PageIndexInfo & {
308
315
  [key: string]: unknown;
309
- }) => void | Promise<void>;
316
+ }, isProd: boolean) => void | Promise<void>;
310
317
  /**
311
318
  * Add custom route
312
319
  */
313
320
  addPages?: (config: UserConfig, isProd: boolean) => AdditionalPage[] | Promise<AdditionalPage[]>;
321
+ /**
322
+ * Add runtime modules
323
+ */
324
+ addRuntimeModules?: (config: UserConfig, isProd: boolean) => Record<string, string> | Promise<Record<string, string>>;
314
325
  /**
315
326
  * Callback after route generated
316
327
  */
317
- routeGenerated?: (routes: RouteMeta[]) => Promise<void> | void;
328
+ routeGenerated?: (routes: RouteMeta[], isProd: boolean) => Promise<void> | void;
318
329
  /**
319
330
  * Add addition ssg routes, for dynamic routes.
320
331
  */
@@ -327,7 +338,7 @@ interface RspressPlugin {
327
338
  * @private
328
339
  * Modify search index data.
329
340
  */
330
- modifySearchIndexData?: (data: PageIndexInfo[]) => void | Promise<void>;
341
+ modifySearchIndexData?: (data: PageIndexInfo[], isProd: boolean) => void | Promise<void>;
331
342
  }
332
343
 
333
344
  interface Route {
@@ -410,9 +421,9 @@ interface UserConfig<ThemeConfig = Config$1> {
410
421
  */
411
422
  themeConfig?: ThemeConfig;
412
423
  /**
413
- * Builder Configuration
424
+ * Rsbuild Configuration
414
425
  */
415
- builderConfig?: BuilderConfig;
426
+ builderConfig?: RsbuildConfig;
416
427
  /**
417
428
  * The custom config of vite-plugin-route
418
429
  */
@@ -449,6 +460,10 @@ interface UserConfig<ThemeConfig = Config$1> {
449
460
  * Search options
450
461
  */
451
462
  search?: SearchOptions;
463
+ /**
464
+ * Whether to enable ssg, default is true
465
+ */
466
+ ssg?: boolean;
452
467
  /**
453
468
  * Whether to enable medium-zoom, default is true
454
469
  */
@@ -459,7 +474,7 @@ interface UserConfig<ThemeConfig = Config$1> {
459
474
  /**
460
475
  * Add some extra builder plugins
461
476
  */
462
- builderPlugins?: BuilderPlugin[];
477
+ builderPlugins?: RsbuildPlugin[];
463
478
  /**
464
479
  * Multi version config
465
480
  */
@@ -479,6 +494,7 @@ interface SiteData<ThemeConfig = NormalizedConfig> {
479
494
  root: string;
480
495
  base: string;
481
496
  lang: string;
497
+ route: RouteOptions;
482
498
  locales: {
483
499
  lang: string;
484
500
  label: string;
@@ -493,8 +509,10 @@ interface SiteData<ThemeConfig = NormalizedConfig> {
493
509
  };
494
510
  pages: BaseRuntimePageInfo[];
495
511
  search: SearchOptions;
512
+ ssg: boolean;
496
513
  markdown: {
497
514
  showLineNumbers: boolean;
515
+ defaultWrapCode: boolean;
498
516
  };
499
517
  multiVersion: {
500
518
  default: string;
@@ -540,6 +558,7 @@ interface Feature {
540
558
  icon: string;
541
559
  title: string;
542
560
  details: string;
561
+ span?: number;
543
562
  link?: string;
544
563
  }
545
564
  interface PageModule<T extends React.ComponentType<unknown>> {
@@ -585,6 +604,10 @@ interface RouteOptions {
585
604
  * Exclude files from being converted to routes
586
605
  */
587
606
  exclude?: string[];
607
+ /**
608
+ * use links without .html files
609
+ */
610
+ cleanUrls?: boolean;
588
611
  }
589
612
  interface SearchHooks {
590
613
  /**
@@ -610,10 +633,31 @@ type SearchOptions = LocalSearchOptions | RemoteSearchOptions | false;
610
633
  interface MarkdownOptions {
611
634
  remarkPlugins?: PluggableList;
612
635
  rehypePlugins?: PluggableList;
636
+ /**
637
+ * Whether to enable check dead links, default is false
638
+ */
613
639
  checkDeadLinks?: boolean;
614
- experimentalMdxRs?: boolean;
615
640
  showLineNumbers?: boolean;
641
+ /**
642
+ * Whether to wrap code by default, default is false
643
+ */
644
+ defaultWrapCode?: boolean;
645
+ /**
646
+ * Register global components in mdx files
647
+ */
616
648
  globalComponents?: string[];
649
+ /**
650
+ * Register prism languages
651
+ */
652
+ highlightLanguages?: (string | [string, string])[];
653
+ /**
654
+ * Whether to enable mdx-rs, default is true
655
+ */
656
+ mdxRs?: boolean;
657
+ /**
658
+ * @deprecated, use `mdxRs` instead
659
+ */
660
+ experimentalMdxRs?: boolean;
617
661
  }
618
662
  type Config = UserConfig | Promise<UserConfig> | ((env: any) => UserConfig | Promise<UserConfig>);
619
663
 
@@ -632,6 +676,7 @@ declare function normalizePosixPath(id: string): string;
632
676
  declare const inBrowser: () => boolean;
633
677
  declare function addLeadingSlash(url: string): string;
634
678
  declare function removeLeadingSlash(url: string): string;
679
+ declare function addTrailingSlash(url: string): string;
635
680
  declare function removeTrailingSlash(url: string): string;
636
681
  declare function normalizeSlash(url: string): string;
637
682
  declare function isExternalUrl(url: string): boolean;
@@ -643,6 +688,11 @@ declare function replaceLang(rawUrl: string, lang: {
643
688
  current: string;
644
689
  default: string;
645
690
  }, base?: string): string;
691
+ declare function replaceVersion(rawUrl: string, version: {
692
+ current: string;
693
+ target: string;
694
+ default: string;
695
+ }, base?: string): string;
646
696
  declare const omit: (obj: Record<string, unknown>, keys: string[]) => {
647
697
  [x: string]: unknown;
648
698
  };
@@ -650,7 +700,7 @@ declare const parseUrl: (url: string) => {
650
700
  url: string;
651
701
  hash: string;
652
702
  };
653
- declare function normalizeHref(url?: string): string;
703
+ declare function normalizeHref(url?: string, cleanUrls?: boolean): string;
654
704
  declare function withoutLang(path: string, langs: string[]): string;
655
705
  declare function withoutBase(path: string, base?: string): string;
656
706
  declare function withBase(url?: string, base?: string): string;
@@ -658,4 +708,4 @@ declare function removeBase(url: string, base: string): string;
658
708
  declare function withoutHash(url: string): string;
659
709
  declare const mergeDocConfig: (...configs: UserConfig[]) => UserConfig;
660
710
 
661
- 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, slash, withBase, withoutBase, withoutHash, withoutLang };
711
+ 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, removeLeadingSlash, removeTrailingSlash, replaceLang, replaceVersion, slash, withBase, withoutBase, withoutHash, withoutLang };
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -26,6 +27,7 @@ __export(src_exports, {
26
27
  RSPRESS_TEMP_DIR: () => RSPRESS_TEMP_DIR,
27
28
  SEARCH_INDEX_NAME: () => SEARCH_INDEX_NAME,
28
29
  addLeadingSlash: () => addLeadingSlash,
30
+ addTrailingSlash: () => addTrailingSlash,
29
31
  cleanUrl: () => cleanUrl,
30
32
  inBrowser: () => inBrowser,
31
33
  isDebugMode: () => isDebugMode,
@@ -42,6 +44,7 @@ __export(src_exports, {
42
44
  removeLeadingSlash: () => removeLeadingSlash,
43
45
  removeTrailingSlash: () => removeTrailingSlash,
44
46
  replaceLang: () => replaceLang,
47
+ replaceVersion: () => replaceVersion,
45
48
  slash: () => slash,
46
49
  withBase: () => withBase,
47
50
  withoutBase: () => withoutBase,
@@ -1150,6 +1153,9 @@ function addLeadingSlash(url) {
1150
1153
  function removeLeadingSlash(url) {
1151
1154
  return url.charAt(0) === "/" ? url.slice(1) : url;
1152
1155
  }
1156
+ function addTrailingSlash(url) {
1157
+ return url.charAt(url.length - 1) === "/" ? url : `${url}/`;
1158
+ }
1153
1159
  function removeTrailingSlash(url) {
1154
1160
  return url.charAt(url.length - 1) === "/" ? url.slice(0, -1) : url;
1155
1161
  }
@@ -1190,6 +1196,30 @@ function replaceLang(rawUrl, lang, version, base = "") {
1190
1196
  base
1191
1197
  );
1192
1198
  }
1199
+ function replaceVersion(rawUrl, version, base = "") {
1200
+ let url = removeBase(rawUrl, base);
1201
+ if (!url) {
1202
+ url = "/index.html";
1203
+ }
1204
+ let versionPart = "";
1205
+ const parts = url.split("/").filter(Boolean);
1206
+ if (version.target !== version.default) {
1207
+ versionPart = version.target;
1208
+ if (version.current !== version.default) {
1209
+ parts.shift();
1210
+ }
1211
+ } else {
1212
+ parts.shift();
1213
+ }
1214
+ let restPart = parts.join("/") || "";
1215
+ if (versionPart && !restPart) {
1216
+ restPart = "index.html";
1217
+ }
1218
+ return withBase(
1219
+ addLeadingSlash([versionPart, restPart].filter(Boolean).join("/")),
1220
+ base
1221
+ );
1222
+ }
1193
1223
  var omit = (obj, keys) => {
1194
1224
  const ret = { ...obj };
1195
1225
  for (const key of keys) {
@@ -1204,7 +1234,7 @@ var parseUrl = (url) => {
1204
1234
  hash
1205
1235
  };
1206
1236
  };
1207
- function normalizeHref(url) {
1237
+ function normalizeHref(url, cleanUrls = false) {
1208
1238
  if (!url) {
1209
1239
  return "/";
1210
1240
  }
@@ -1215,7 +1245,7 @@ function normalizeHref(url) {
1215
1245
  if (url.startsWith("mailto:") || url.startsWith("tel:")) {
1216
1246
  return url;
1217
1247
  }
1218
- if (!cleanUrl2.endsWith(".html")) {
1248
+ if (!cleanUrls && !cleanUrl2.endsWith(".html")) {
1219
1249
  if (cleanUrl2.endsWith("/")) {
1220
1250
  cleanUrl2 += "index.html";
1221
1251
  } else {
@@ -1237,7 +1267,10 @@ function withBase(url = "/", base = "") {
1237
1267
  return normalizedUrl.startsWith(normalizedBase) ? normalizedUrl : `${normalizedBase}${normalizedUrl}`;
1238
1268
  }
1239
1269
  function removeBase(url, base) {
1240
- return addLeadingSlash(url).replace(normalizeSlash(base), "");
1270
+ return addLeadingSlash(url).replace(
1271
+ new RegExp(`^${normalizeSlash(base)}`),
1272
+ ""
1273
+ );
1241
1274
  }
1242
1275
  function withoutHash(url) {
1243
1276
  return url.split("#")[0];
@@ -1261,6 +1294,7 @@ var mergeDocConfig = (...configs) => mergeWith_default({}, ...configs, (target,
1261
1294
  RSPRESS_TEMP_DIR,
1262
1295
  SEARCH_INDEX_NAME,
1263
1296
  addLeadingSlash,
1297
+ addTrailingSlash,
1264
1298
  cleanUrl,
1265
1299
  inBrowser,
1266
1300
  isDebugMode,
@@ -1277,6 +1311,7 @@ var mergeDocConfig = (...configs) => mergeWith_default({}, ...configs, (target,
1277
1311
  removeLeadingSlash,
1278
1312
  removeTrailingSlash,
1279
1313
  replaceLang,
1314
+ replaceVersion,
1280
1315
  slash,
1281
1316
  withBase,
1282
1317
  withoutBase,