@rspress/shared 2.0.16 → 2.0.18

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
@@ -2,7 +2,6 @@ import type { ComponentType } from 'react';
2
2
  import type { loadConfig } from '@rsbuild/core';
3
3
  import type { PluggableList } from 'unified';
4
4
  import type { ReactElement } from 'react';
5
- import type { ReactNode } from 'react';
6
5
  import type { RehypeShikiOptions } from '@shikijs/rehype';
7
6
  import type { RsbuildConfig } from '@rsbuild/core';
8
7
 
@@ -208,18 +207,100 @@ export declare type LastUpdatedAuthor = boolean | ((info: {
208
207
  filePath: string;
209
208
  }) => string);
210
209
 
210
+ export declare interface LlmsTxtContext {
211
+ /**
212
+ * The site title.
213
+ */
214
+ title: string | undefined;
215
+ /**
216
+ * The site description.
217
+ */
218
+ description: string | undefined;
219
+ /**
220
+ * The language of the generated llms.txt.
221
+ */
222
+ lang: string;
223
+ /**
224
+ * The version of the generated llms.txt.
225
+ */
226
+ version: string;
227
+ /**
228
+ * The configured base path.
229
+ */
230
+ base: string;
231
+ /**
232
+ * The configured site origin.
233
+ */
234
+ siteOrigin: string | undefined;
235
+ /**
236
+ * Page sections in navigation order.
237
+ */
238
+ sections: LlmsTxtSection[];
239
+ }
240
+
241
+ export declare interface LlmsTxtPage {
242
+ /**
243
+ * The route path of the page.
244
+ */
245
+ routePath: string;
246
+ /**
247
+ * The URL of the generated Markdown file.
248
+ */
249
+ link: string;
250
+ /**
251
+ * The title of the page.
252
+ */
253
+ title: string;
254
+ /**
255
+ * The description of the page.
256
+ */
257
+ description?: string;
258
+ /**
259
+ * The frontmatter of the page.
260
+ */
261
+ frontmatter: FrontMatterMeta;
262
+ /**
263
+ * The language of the page.
264
+ */
265
+ lang: string;
266
+ /**
267
+ * The version of the page.
268
+ */
269
+ version: string;
270
+ }
271
+
272
+ export declare type LlmsTxtRenderer = (context: LlmsTxtContext) => string | Promise<string>;
273
+
274
+ export declare interface LlmsTxtSection {
275
+ /**
276
+ * The title of the section, derived from navigation.
277
+ */
278
+ title: string;
279
+ /**
280
+ * Pages in navigation and sidebar order.
281
+ */
282
+ pages: LlmsTxtPage[];
283
+ }
284
+
211
285
  /**
212
- * Configuration for LLMS UI components displayed on H1 headers.
213
- * When enabled, LlmsCopyButton and LlmsViewOptions will be automatically
214
- * added below H1 headers without requiring custom getCustomMDXComponent.
286
+ * Configuration for LLMS UI components displayed below H1 headers or in the
287
+ * outline sidebar. When enabled, the copy and view options UI will be added
288
+ * automatically without requiring custom getCustomMDXComponent.
215
289
  * @default false
216
290
  */
217
291
  export declare type LlmsUI = {
292
+ /**
293
+ * Whether to inject a hidden hint into SSG HTML pages that points LLMs
294
+ * to llms.txt and llms-full.txt.
295
+ * @default true
296
+ */
297
+ injectLlmsHint?: boolean;
218
298
  /**
219
299
  * Options for LlmsViewOptions component dropdown menu.
300
+ * Set to `false` or an empty array to hide the view options UI.
220
301
  * @default ['markdownLink', 'chatgpt', 'claude']
221
302
  */
222
- viewOptions?: LlmsViewOption[];
303
+ viewOptions?: false | LlmsViewOption[];
223
304
  /**
224
305
  * Where to display the LLM UI components.
225
306
  * - 'title': Show as buttons below the H1 title (default)
@@ -230,17 +311,10 @@ export declare type LlmsUI = {
230
311
  } | boolean;
231
312
 
232
313
  /**
233
- * Option item for LlmsViewOptions component.
314
+ * Built-in option item for LlmsViewOptions configured through
315
+ * `rspress.config.ts`.
234
316
  */
235
- export declare type LlmsViewOption = 'markdownLink' | 'chatgpt' | 'claude' | {
236
- title: string;
237
- icon?: ReactNode;
238
- onClick?: () => void;
239
- } | {
240
- title: string;
241
- href: string;
242
- icon?: ReactNode;
243
- };
317
+ export declare type LlmsViewOption = 'markdownLink' | 'chatgpt' | 'claude';
244
318
 
245
319
  export declare interface Locale {
246
320
  lang: string;
@@ -596,6 +670,10 @@ export declare interface Route {
596
670
 
597
671
  export declare interface RouteMeta {
598
672
  routePath: string;
673
+ /**
674
+ * Route path without language and version prefixes.
675
+ */
676
+ pureRoutePath: string;
599
677
  absolutePath: string;
600
678
  relativePath: string;
601
679
  pageName: string;
@@ -629,6 +707,18 @@ export declare interface RouteOptions {
629
707
  * @default false
630
708
  */
631
709
  cleanUrls?: boolean;
710
+ /**
711
+ * Enable concurrent, optimized routing for internal links rendered by
712
+ * Rspress' default Link component.
713
+ * @default true
714
+ */
715
+ useTransitions?: boolean;
716
+ /**
717
+ * Whether to enable prefetching for matching internal routes from Rspress'
718
+ * default Link component.
719
+ * @default true
720
+ */
721
+ prefetchLink?: boolean;
632
722
  }
633
723
 
634
724
  export declare const RSPRESS_TEMP_DIR = ".rspress";
@@ -762,6 +852,7 @@ export declare type SidebarSectionHeader = {
762
852
 
763
853
  export declare interface SiteData {
764
854
  base: string;
855
+ siteOrigin: string;
765
856
  lang: string;
766
857
  route: RouteOptions;
767
858
  locales: {
@@ -891,8 +982,8 @@ declare type ThemeConfig = {
891
982
  fallbackHeadingTitle?: boolean;
892
983
  /**
893
984
  * LLMS UI components configuration.
894
- * When llmsUI.enableOnH1 is true, LlmsCopyButton and LlmsViewOptions
895
- * will be automatically added below H1 headers.
985
+ * When enabled, LlmsCopyButton and LlmsViewOptions will be automatically
986
+ * added below H1 headers or to the outline sidebar.
896
987
  */
897
988
  llmsUI?: LlmsUI;
898
989
  };
@@ -930,6 +1021,10 @@ export declare interface UserConfig {
930
1021
  * @default '/'
931
1022
  */
932
1023
  base?: string;
1024
+ /**
1025
+ * Origin of the site, such as `https://example.com`.
1026
+ */
1027
+ siteOrigin?: string;
933
1028
  /**
934
1029
  * Path to html icon file.
935
1030
  * @default ''
@@ -1038,6 +1133,11 @@ export declare interface UserConfig {
1038
1133
  * @experimental
1039
1134
  */
1040
1135
  llms?: boolean | {
1136
+ /**
1137
+ * Customize the content of generated llms.txt files.
1138
+ * @experimental
1139
+ */
1140
+ llmsTxt?: LlmsTxtRenderer;
1041
1141
  /**
1042
1142
  * @experimental
1043
1143
  */
@@ -1090,6 +1190,8 @@ export declare function withBase(url: string, base: string): string;
1090
1190
 
1091
1191
  export declare function withoutLang(path: string, langs: string[]): string;
1092
1192
 
1193
+ export declare function withSiteOrigin(url: string, siteOrigin?: string): string;
1194
+
1093
1195
  declare interface ZoomContainer {
1094
1196
  width?: number
1095
1197
  height?: number
package/dist/index.js CHANGED
@@ -140,6 +140,10 @@ function withBase(url, base) {
140
140
  }
141
141
  return `${normalizedBase}${normalizedUrl}`;
142
142
  }
143
+ function withSiteOrigin(url, siteOrigin) {
144
+ if (!siteOrigin || isExternalUrl(url)) return url;
145
+ return new URL(addLeadingSlash(url), addTrailingSlash(siteOrigin)).href;
146
+ }
143
147
  function removeBase(url, base) {
144
148
  const normalizedUrl = addLeadingSlash(url);
145
149
  const normalizedBase = normalizeSlash(base);
@@ -173,4 +177,4 @@ const getDefaultDarkModeValue = (darkMode)=>{
173
177
  return normalizedDarkMode;
174
178
  };
175
179
  const isDarkModeSwitchEnabled = (darkMode)=>!normalizeDarkMode(darkMode).startsWith('force-');
176
- export { HASH_REGEXP, MDX_OR_MD_REGEXP, QUERY_REGEXP, RSPRESS_TEMP_DIR, SEARCH_INDEX_NAME, addLeadingSlash, addTrailingSlash, getDefaultDarkModeValue, getSidebarDataGroup, inBrowser, isDarkModeSwitchEnabled, isDataUrl, isDebugMode, isDevDebugMode, isExternalUrl, isProduction, matchNavbar, matchSidebar, normalizeDarkMode, normalizeHref, normalizePosixPath, parseUrl, removeBase, removeHash, removeLeadingSlash, removeTrailingSlash, replaceLang, replaceVersion, slash, utils_cleanUrl as cleanUrl, withBase, withoutLang };
180
+ export { HASH_REGEXP, MDX_OR_MD_REGEXP, QUERY_REGEXP, RSPRESS_TEMP_DIR, SEARCH_INDEX_NAME, addLeadingSlash, addTrailingSlash, getDefaultDarkModeValue, getSidebarDataGroup, inBrowser, isDarkModeSwitchEnabled, isDataUrl, isDebugMode, isDevDebugMode, isExternalUrl, isProduction, matchNavbar, matchSidebar, normalizeDarkMode, normalizeHref, normalizePosixPath, parseUrl, removeBase, removeHash, removeLeadingSlash, removeTrailingSlash, replaceLang, replaceVersion, slash, utils_cleanUrl as cleanUrl, withBase, withSiteOrigin, withoutLang };
@@ -4,7 +4,6 @@ import type { MdxJsxExpressionAttribute } from 'mdast-util-mdx-jsx';
4
4
  import type { MdxJsxFlowElement } from 'mdast-util-mdx-jsx';
5
5
  import type { MdxJsxTextElement } from 'mdast-util-mdx-jsx';
6
6
  import type { PluggableList } from 'unified';
7
- import type { ReactNode } from 'react';
8
7
  import type { RehypeShikiOptions } from '@shikijs/rehype';
9
8
  import type { RsbuildConfig } from '@rsbuild/core';
10
9
 
@@ -195,18 +194,100 @@ declare type LastUpdatedAuthor = boolean | ((info: {
195
194
  filePath: string;
196
195
  }) => string);
197
196
 
197
+ declare interface LlmsTxtContext {
198
+ /**
199
+ * The site title.
200
+ */
201
+ title: string | undefined;
202
+ /**
203
+ * The site description.
204
+ */
205
+ description: string | undefined;
206
+ /**
207
+ * The language of the generated llms.txt.
208
+ */
209
+ lang: string;
210
+ /**
211
+ * The version of the generated llms.txt.
212
+ */
213
+ version: string;
214
+ /**
215
+ * The configured base path.
216
+ */
217
+ base: string;
218
+ /**
219
+ * The configured site origin.
220
+ */
221
+ siteOrigin: string | undefined;
222
+ /**
223
+ * Page sections in navigation order.
224
+ */
225
+ sections: LlmsTxtSection[];
226
+ }
227
+
228
+ declare interface LlmsTxtPage {
229
+ /**
230
+ * The route path of the page.
231
+ */
232
+ routePath: string;
233
+ /**
234
+ * The URL of the generated Markdown file.
235
+ */
236
+ link: string;
237
+ /**
238
+ * The title of the page.
239
+ */
240
+ title: string;
241
+ /**
242
+ * The description of the page.
243
+ */
244
+ description?: string;
245
+ /**
246
+ * The frontmatter of the page.
247
+ */
248
+ frontmatter: FrontMatterMeta;
249
+ /**
250
+ * The language of the page.
251
+ */
252
+ lang: string;
253
+ /**
254
+ * The version of the page.
255
+ */
256
+ version: string;
257
+ }
258
+
259
+ declare type LlmsTxtRenderer = (context: LlmsTxtContext) => string | Promise<string>;
260
+
261
+ declare interface LlmsTxtSection {
262
+ /**
263
+ * The title of the section, derived from navigation.
264
+ */
265
+ title: string;
266
+ /**
267
+ * Pages in navigation and sidebar order.
268
+ */
269
+ pages: LlmsTxtPage[];
270
+ }
271
+
198
272
  /**
199
- * Configuration for LLMS UI components displayed on H1 headers.
200
- * When enabled, LlmsCopyButton and LlmsViewOptions will be automatically
201
- * added below H1 headers without requiring custom getCustomMDXComponent.
273
+ * Configuration for LLMS UI components displayed below H1 headers or in the
274
+ * outline sidebar. When enabled, the copy and view options UI will be added
275
+ * automatically without requiring custom getCustomMDXComponent.
202
276
  * @default false
203
277
  */
204
278
  declare type LlmsUI = {
279
+ /**
280
+ * Whether to inject a hidden hint into SSG HTML pages that points LLMs
281
+ * to llms.txt and llms-full.txt.
282
+ * @default true
283
+ */
284
+ injectLlmsHint?: boolean;
205
285
  /**
206
286
  * Options for LlmsViewOptions component dropdown menu.
287
+ * Set to `false` or an empty array to hide the view options UI.
207
288
  * @default ['markdownLink', 'chatgpt', 'claude']
208
289
  */
209
- viewOptions?: LlmsViewOption[];
290
+ viewOptions?: false | LlmsViewOption[];
210
291
  /**
211
292
  * Where to display the LLM UI components.
212
293
  * - 'title': Show as buttons below the H1 title (default)
@@ -217,17 +298,10 @@ declare type LlmsUI = {
217
298
  } | boolean;
218
299
 
219
300
  /**
220
- * Option item for LlmsViewOptions component.
301
+ * Built-in option item for LlmsViewOptions configured through
302
+ * `rspress.config.ts`.
221
303
  */
222
- declare type LlmsViewOption = 'markdownLink' | 'chatgpt' | 'claude' | {
223
- title: string;
224
- icon?: ReactNode;
225
- onClick?: () => void;
226
- } | {
227
- title: string;
228
- href: string;
229
- icon?: ReactNode;
230
- };
304
+ declare type LlmsViewOption = 'markdownLink' | 'chatgpt' | 'claude';
231
305
 
232
306
  export declare function loadFrontMatter<TFrontmatter extends Record<string, unknown> = FrontMatterMeta>(source: string, filepath: string, root: string, outputWarning?: boolean): {
233
307
  frontmatter: TFrontmatter;
@@ -470,6 +544,10 @@ declare interface ReplaceRule {
470
544
 
471
545
  declare interface RouteMeta {
472
546
  routePath: string;
547
+ /**
548
+ * Route path without language and version prefixes.
549
+ */
550
+ pureRoutePath: string;
473
551
  absolutePath: string;
474
552
  relativePath: string;
475
553
  pageName: string;
@@ -503,6 +581,18 @@ declare interface RouteOptions {
503
581
  * @default false
504
582
  */
505
583
  cleanUrls?: boolean;
584
+ /**
585
+ * Enable concurrent, optimized routing for internal links rendered by
586
+ * Rspress' default Link component.
587
+ * @default true
588
+ */
589
+ useTransitions?: boolean;
590
+ /**
591
+ * Whether to enable prefetching for matching internal routes from Rspress'
592
+ * default Link component.
593
+ * @default true
594
+ */
595
+ prefetchLink?: boolean;
506
596
  }
507
597
 
508
598
  declare interface RspressPlugin {
@@ -725,8 +815,8 @@ declare type ThemeConfig = {
725
815
  fallbackHeadingTitle?: boolean;
726
816
  /**
727
817
  * LLMS UI components configuration.
728
- * When llmsUI.enableOnH1 is true, LlmsCopyButton and LlmsViewOptions
729
- * will be automatically added below H1 headers.
818
+ * When enabled, LlmsCopyButton and LlmsViewOptions will be automatically
819
+ * added below H1 headers or to the outline sidebar.
730
820
  */
731
821
  llmsUI?: LlmsUI;
732
822
  };
@@ -760,6 +850,10 @@ declare interface UserConfig {
760
850
  * @default '/'
761
851
  */
762
852
  base?: string;
853
+ /**
854
+ * Origin of the site, such as `https://example.com`.
855
+ */
856
+ siteOrigin?: string;
763
857
  /**
764
858
  * Path to html icon file.
765
859
  * @default ''
@@ -868,6 +962,11 @@ declare interface UserConfig {
868
962
  * @experimental
869
963
  */
870
964
  llms?: boolean | {
965
+ /**
966
+ * Customize the content of generated llms.txt files.
967
+ * @experimental
968
+ */
969
+ llmsTxt?: LlmsTxtRenderer;
871
970
  /**
872
971
  * @experimental
873
972
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/shared",
3
- "version": "2.0.16",
3
+ "version": "2.0.18",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/web-infra-dev/rspress.git",
@@ -44,12 +44,12 @@
44
44
  "dist"
45
45
  ],
46
46
  "dependencies": {
47
- "@rsbuild/core": "^2.0.15",
47
+ "@rsbuild/core": "^2.1.5",
48
48
  "@shikijs/rehype": "^4.2.0",
49
49
  "unified": "^11.0.5"
50
50
  },
51
51
  "devDependencies": {
52
- "@rslib/core": "0.23.0",
52
+ "@rslib/core": "0.23.2",
53
53
  "@types/lodash-es": "^4.17.12",
54
54
  "@types/node": "^22.8.1",
55
55
  "@types/react": "^19.2.17",