@rspress/shared 0.0.0-next-20230926070920 → 0.0.0-next-20231020055855

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
@@ -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
  /**
@@ -119,13 +119,13 @@ interface Config$1 {
119
119
  */
120
120
  search?: boolean;
121
121
  /**
122
- * Whether to use back top
122
+ * The behavior of hiding navbar
123
123
  */
124
- backTop?: boolean;
124
+ hideNavbar?: 'always' | 'auto' | 'never';
125
125
  /**
126
- * Whether to hide the navbar
126
+ * Whether to enable the animation for translation pages
127
127
  */
128
- hideNavbar?: boolean;
128
+ enableContentAnimation?: boolean;
129
129
  }
130
130
  /**
131
131
  * locale config
@@ -288,7 +288,10 @@ interface RspressPlugin {
288
288
  /**
289
289
  * Modify doc config.
290
290
  */
291
- config?: (config: UserConfig) => UserConfig | Promise<UserConfig>;
291
+ config?: (config: UserConfig, utils: {
292
+ addPlugin: (plugin: RspressPlugin) => void;
293
+ removePlugin: (pluginName: string) => void;
294
+ }) => UserConfig | Promise<UserConfig>;
292
295
  /**
293
296
  * Callback before build
294
297
  */
@@ -339,6 +342,7 @@ interface RouteMeta {
339
342
  relativePath: string;
340
343
  pageName: string;
341
344
  lang: string;
345
+ version: string;
342
346
  }
343
347
  interface ReplaceRule {
344
348
  search: string | RegExp;
@@ -455,12 +459,30 @@ interface UserConfig<ThemeConfig = Config$1> {
455
459
  * Add some extra builder plugins
456
460
  */
457
461
  builderPlugins?: BuilderPlugin[];
462
+ /**
463
+ * Multi version config
464
+ */
465
+ multiVersion?: {
466
+ /**
467
+ * The default version
468
+ */
469
+ default?: string;
470
+ /**
471
+ * The version list, such as ['v1', 'v2']
472
+ */
473
+ versions: string[];
474
+ };
458
475
  }
459
476
  type BaseRuntimePageInfo = Omit<PageIndexInfo, 'id' | 'content' | 'domain'>;
460
477
  interface SiteData<ThemeConfig = NormalizedConfig> {
461
478
  root: string;
462
479
  base: string;
463
480
  lang: string;
481
+ route: RouteOptions;
482
+ locales: {
483
+ lang: string;
484
+ label: string;
485
+ }[];
464
486
  title: string;
465
487
  description: string;
466
488
  icon: string;
@@ -474,6 +496,10 @@ interface SiteData<ThemeConfig = NormalizedConfig> {
474
496
  markdown: {
475
497
  showLineNumbers: boolean;
476
498
  };
499
+ multiVersion: {
500
+ default: string;
501
+ versions: string[];
502
+ };
477
503
  }
478
504
  type PageIndexInfo = {
479
505
  id: number;
@@ -483,6 +509,7 @@ type PageIndexInfo = {
483
509
  content: string;
484
510
  frontmatter: Record<string, unknown>;
485
511
  lang: string;
512
+ version: string;
486
513
  domain: string;
487
514
  _filepath: string;
488
515
  _relativePath: string;
@@ -545,14 +572,6 @@ interface PageData {
545
572
  };
546
573
  }
547
574
  interface RouteOptions {
548
- /**
549
- * The directory to search for pages
550
- */
551
- root?: string;
552
- /**
553
- * The basename of the site
554
- */
555
- prefix?: string;
556
575
  /**
557
576
  * The extension name of the filepath that will be converted to a route
558
577
  * @default ['js','jsx','ts','tsx','md','mdx']
@@ -566,6 +585,10 @@ interface RouteOptions {
566
585
  * Exclude files from being converted to routes
567
586
  */
568
587
  exclude?: string[];
588
+ /**
589
+ * use links without .html files
590
+ */
591
+ cleanUrls?: boolean;
569
592
  }
570
593
  interface SearchHooks {
571
594
  /**
@@ -591,10 +614,27 @@ type SearchOptions = LocalSearchOptions | RemoteSearchOptions | false;
591
614
  interface MarkdownOptions {
592
615
  remarkPlugins?: PluggableList;
593
616
  rehypePlugins?: PluggableList;
617
+ /**
618
+ * Whether to enable check dead links, default is false
619
+ */
594
620
  checkDeadLinks?: boolean;
595
- experimentalMdxRs?: boolean;
596
621
  showLineNumbers?: boolean;
622
+ /**
623
+ * Register global components in mdx files
624
+ */
597
625
  globalComponents?: string[];
626
+ /**
627
+ * Register prism languages
628
+ */
629
+ highlightLanguages?: (string | [string, string])[];
630
+ /**
631
+ * Whether to enable mdx-rs, default is true
632
+ */
633
+ mdxRs?: boolean;
634
+ /**
635
+ * @deprecated, use `mdxRs` instead
636
+ */
637
+ experimentalMdxRs?: boolean;
598
638
  }
599
639
  type Config = UserConfig | Promise<UserConfig> | ((env: any) => UserConfig | Promise<UserConfig>);
600
640
 
@@ -616,7 +656,19 @@ declare function removeLeadingSlash(url: string): string;
616
656
  declare function removeTrailingSlash(url: string): string;
617
657
  declare function normalizeSlash(url: string): string;
618
658
  declare function isExternalUrl(url: string): boolean;
619
- declare function replaceLang(rawUrl: string, targetLang: string, defaultLang: string, langs: string[], base?: string): string;
659
+ declare function replaceLang(rawUrl: string, lang: {
660
+ current: string;
661
+ target: string;
662
+ default: string;
663
+ }, version: {
664
+ current: string;
665
+ default: string;
666
+ }, base?: string): string;
667
+ declare function replaceVersion(rawUrl: string, version: {
668
+ current: string;
669
+ target: string;
670
+ default: string;
671
+ }, base?: string): string;
620
672
  declare const omit: (obj: Record<string, unknown>, keys: string[]) => {
621
673
  [x: string]: unknown;
622
674
  };
@@ -624,7 +676,7 @@ declare const parseUrl: (url: string) => {
624
676
  url: string;
625
677
  hash: string;
626
678
  };
627
- declare function normalizeHref(url?: string): string;
679
+ declare function normalizeHref(url?: string, cleanUrls?: boolean): string;
628
680
  declare function withoutLang(path: string, langs: string[]): string;
629
681
  declare function withoutBase(path: string, base?: string): string;
630
682
  declare function withBase(url?: string, base?: string): string;
@@ -632,4 +684,4 @@ declare function removeBase(url: string, base: string): string;
632
684
  declare function withoutHash(url: string): string;
633
685
  declare const mergeDocConfig: (...configs: UserConfig[]) => UserConfig;
634
686
 
635
- 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 };
687
+ 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 };
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;
@@ -42,6 +43,7 @@ __export(src_exports, {
42
43
  removeLeadingSlash: () => removeLeadingSlash,
43
44
  removeTrailingSlash: () => removeTrailingSlash,
44
45
  replaceLang: () => replaceLang,
46
+ replaceVersion: () => replaceVersion,
45
47
  slash: () => slash,
46
48
  withBase: () => withBase,
47
49
  withoutBase: () => withoutBase,
@@ -1159,26 +1161,60 @@ function normalizeSlash(url) {
1159
1161
  function isExternalUrl(url) {
1160
1162
  return url.startsWith("http://") || url.startsWith("https://") || url.startsWith("mailto:") || url.startsWith("tel:");
1161
1163
  }
1162
- function replaceLang(rawUrl, targetLang, defaultLang, langs, base = "") {
1164
+ function replaceLang(rawUrl, lang, version, base = "") {
1163
1165
  let url = removeBase(rawUrl, base);
1164
1166
  if (!url) {
1165
1167
  url = "/index.html";
1166
1168
  }
1167
- const originalLang = url.split("/")[1];
1168
- const inDefaultLang = !langs.includes(originalLang);
1169
- let result;
1170
- if (inDefaultLang) {
1171
- if (targetLang === defaultLang) {
1172
- result = url;
1173
- } else {
1174
- result = addLeadingSlash(`${targetLang}${url}`);
1169
+ let versionPart = "";
1170
+ let langPart = "";
1171
+ let purePathPart = "";
1172
+ const parts = url.split("/").filter(Boolean);
1173
+ if (version.current && version.current !== version.default) {
1174
+ versionPart = parts.shift() || "";
1175
+ }
1176
+ if (lang.target !== lang.default) {
1177
+ langPart = lang.target;
1178
+ if (lang.current !== lang.default) {
1179
+ parts.shift();
1175
1180
  }
1176
- } else if (targetLang === defaultLang) {
1177
- result = url.replace(`/${originalLang}`, "");
1178
1181
  } else {
1179
- result = url.replace(originalLang, targetLang);
1182
+ parts.shift();
1183
+ }
1184
+ purePathPart = parts.join("/") || "";
1185
+ if ((versionPart || langPart) && !purePathPart) {
1186
+ purePathPart = "index.html";
1187
+ }
1188
+ return withBase(
1189
+ addLeadingSlash(
1190
+ [versionPart, langPart, purePathPart].filter(Boolean).join("/")
1191
+ ),
1192
+ base
1193
+ );
1194
+ }
1195
+ function replaceVersion(rawUrl, version, base = "") {
1196
+ let url = removeBase(rawUrl, base);
1197
+ if (!url) {
1198
+ url = "/index.html";
1199
+ }
1200
+ let versionPart = "";
1201
+ const parts = url.split("/").filter(Boolean);
1202
+ if (version.target !== version.default) {
1203
+ versionPart = version.target;
1204
+ if (version.current !== version.default) {
1205
+ parts.shift();
1206
+ }
1207
+ } else {
1208
+ parts.shift();
1209
+ }
1210
+ let restPart = parts.join("/") || "";
1211
+ if (versionPart && !restPart) {
1212
+ restPart = "index.html";
1180
1213
  }
1181
- return withBase(result, base);
1214
+ return withBase(
1215
+ addLeadingSlash([versionPart, restPart].filter(Boolean).join("/")),
1216
+ base
1217
+ );
1182
1218
  }
1183
1219
  var omit = (obj, keys) => {
1184
1220
  const ret = { ...obj };
@@ -1194,7 +1230,7 @@ var parseUrl = (url) => {
1194
1230
  hash
1195
1231
  };
1196
1232
  };
1197
- function normalizeHref(url) {
1233
+ function normalizeHref(url, cleanUrls = false) {
1198
1234
  if (!url) {
1199
1235
  return "/";
1200
1236
  }
@@ -1205,7 +1241,7 @@ function normalizeHref(url) {
1205
1241
  if (url.startsWith("mailto:") || url.startsWith("tel:")) {
1206
1242
  return url;
1207
1243
  }
1208
- if (!cleanUrl2.endsWith(".html")) {
1244
+ if (!cleanUrls && !cleanUrl2.endsWith(".html")) {
1209
1245
  if (cleanUrl2.endsWith("/")) {
1210
1246
  cleanUrl2 += "index.html";
1211
1247
  } else {
@@ -1267,6 +1303,7 @@ var mergeDocConfig = (...configs) => mergeWith_default({}, ...configs, (target,
1267
1303
  removeLeadingSlash,
1268
1304
  removeTrailingSlash,
1269
1305
  replaceLang,
1306
+ replaceVersion,
1270
1307
  slash,
1271
1308
  withBase,
1272
1309
  withoutBase,