@rspress/shared 2.0.17 → 2.0.19

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
 
@@ -77,6 +76,7 @@ export declare interface FrontMatterMeta {
77
76
  pageType?: PageType;
78
77
  features?: Feature[];
79
78
  hero?: Hero;
79
+ icon?: string;
80
80
  tag?: string;
81
81
  navbar?: boolean;
82
82
  sidebar?: boolean | 'placeholder';
@@ -208,18 +208,103 @@ export declare type LastUpdatedAuthor = boolean | ((info: {
208
208
  filePath: string;
209
209
  }) => string);
210
210
 
211
+ export declare interface LlmsTxtContext {
212
+ /**
213
+ * The site title.
214
+ */
215
+ title: string | undefined;
216
+ /**
217
+ * The site description.
218
+ */
219
+ description: string | undefined;
220
+ /**
221
+ * The language of the generated llms.txt.
222
+ */
223
+ lang: string;
224
+ /**
225
+ * The version of the generated llms.txt.
226
+ */
227
+ version: string;
228
+ /**
229
+ * The configured base path.
230
+ */
231
+ base: string;
232
+ /**
233
+ * The configured site origin.
234
+ */
235
+ siteOrigin: string | undefined;
236
+ /**
237
+ * Page sections in navigation order.
238
+ */
239
+ sections: LlmsTxtSection[];
240
+ }
241
+
242
+ export declare interface LlmsTxtPage {
243
+ /**
244
+ * The route path of the page.
245
+ */
246
+ routePath: string;
247
+ /**
248
+ * The URL of the generated Markdown file.
249
+ */
250
+ link: string;
251
+ /**
252
+ * The title of the page.
253
+ */
254
+ title: string;
255
+ /**
256
+ * The description of the page.
257
+ */
258
+ description?: string;
259
+ /**
260
+ * The frontmatter of the page.
261
+ */
262
+ frontmatter: FrontMatterMeta;
263
+ /**
264
+ * The language of the page.
265
+ */
266
+ lang: string;
267
+ /**
268
+ * The version of the page.
269
+ */
270
+ version: string;
271
+ }
272
+
273
+ export declare type LlmsTxtRenderer = (context: LlmsTxtContext) => string | Promise<string>;
274
+
275
+ export declare interface LlmsTxtSection {
276
+ /**
277
+ * The title of the section, derived from navigation.
278
+ */
279
+ title: string;
280
+ /**
281
+ * Pages in navigation and sidebar order.
282
+ */
283
+ pages: LlmsTxtPage[];
284
+ }
285
+
211
286
  /**
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.
287
+ * Configuration for LLMS UI components displayed below H1 headers or in the
288
+ * outline sidebar. When enabled, the copy and view options UI will be added
289
+ * automatically without requiring custom getCustomMDXComponent.
215
290
  * @default false
216
291
  */
217
292
  export declare type LlmsUI = {
293
+ /**
294
+ * Whether to inject an LLM directive hint into generated pages. In SSG
295
+ * HTML output, it is rendered as a visually hidden plain-text DOM element
296
+ * with llms.txt, llms-full.txt, and the current page's Markdown version.
297
+ * In SSG-MD Markdown output, it is rendered as a leading blockquote
298
+ * string.
299
+ * @default true
300
+ */
301
+ injectLlmsHint?: boolean;
218
302
  /**
219
303
  * Options for LlmsViewOptions component dropdown menu.
304
+ * Set to `false` or an empty array to hide the view options UI.
220
305
  * @default ['markdownLink', 'chatgpt', 'claude']
221
306
  */
222
- viewOptions?: LlmsViewOption[];
307
+ viewOptions?: false | LlmsViewOption[];
223
308
  /**
224
309
  * Where to display the LLM UI components.
225
310
  * - 'title': Show as buttons below the H1 title (default)
@@ -230,17 +315,10 @@ export declare type LlmsUI = {
230
315
  } | boolean;
231
316
 
232
317
  /**
233
- * Option item for LlmsViewOptions component.
318
+ * Built-in option item for LlmsViewOptions configured through
319
+ * `rspress.config.ts`.
234
320
  */
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
- };
321
+ export declare type LlmsViewOption = 'markdownLink' | 'chatgpt' | 'claude';
244
322
 
245
323
  export declare interface Locale {
246
324
  lang: string;
@@ -372,6 +450,7 @@ export declare type NavItem = NavItemWithLink | NavItemWithChildren | NavItemWit
372
450
 
373
451
  export declare interface NavItemWithChildren {
374
452
  text?: string;
453
+ icon?: string;
375
454
  tag?: string;
376
455
  items: NavItem[];
377
456
  position?: 'left' | 'right';
@@ -381,6 +460,7 @@ export declare type NavItemWithLink = {
381
460
  text: string;
382
461
  link: string;
383
462
  download?: boolean;
463
+ icon?: string;
384
464
  tag?: string;
385
465
  activeMatch?: string;
386
466
  position?: 'left' | 'right';
@@ -392,6 +472,7 @@ export declare interface NavItemWithLinkAndChildren {
392
472
  text: string;
393
473
  link: string;
394
474
  items: NavItem[];
475
+ icon?: string;
395
476
  tag?: string;
396
477
  activeMatch?: string;
397
478
  position?: 'left' | 'right';
@@ -596,6 +677,10 @@ export declare interface Route {
596
677
 
597
678
  export declare interface RouteMeta {
598
679
  routePath: string;
680
+ /**
681
+ * Route path without language and version prefixes.
682
+ */
683
+ pureRoutePath: string;
599
684
  absolutePath: string;
600
685
  relativePath: string;
601
686
  pageName: string;
@@ -629,6 +714,12 @@ export declare interface RouteOptions {
629
714
  * @default false
630
715
  */
631
716
  cleanUrls?: boolean;
717
+ /**
718
+ * How to redirect first-time visitors to the closest configured locale
719
+ * based on their browser language.
720
+ * @default 'auto'
721
+ */
722
+ localeRedirect?: 'auto' | 'never' | 'only-default-lang';
632
723
  /**
633
724
  * Enable concurrent, optimized routing for internal links rendered by
634
725
  * Rspress' default Link component.
@@ -743,6 +834,7 @@ export declare type SidebarDivider = {
743
834
  export declare interface SidebarGroup {
744
835
  text: string;
745
836
  link?: string;
837
+ icon?: string;
746
838
  tag?: string;
747
839
  items: (SidebarGroup | SidebarItem | SidebarDivider | SidebarSectionHeader)[];
748
840
  collapsible?: boolean;
@@ -758,6 +850,7 @@ export declare interface SidebarGroup {
758
850
  export declare type SidebarItem = {
759
851
  text: string;
760
852
  link: string;
853
+ icon?: string;
761
854
  tag?: string;
762
855
  /**
763
856
  * For hmr usage in development
@@ -769,6 +862,7 @@ export declare type SidebarItem = {
769
862
 
770
863
  export declare type SidebarSectionHeader = {
771
864
  sectionHeaderText: string;
865
+ icon?: string;
772
866
  tag?: string;
773
867
  };
774
868
 
@@ -893,7 +987,8 @@ declare type ThemeConfig = {
893
987
  */
894
988
  enableScrollToTop?: boolean;
895
989
  /**
896
- * Whether to redirect to the closest locale when the user visits the site
990
+ * Whether to redirect to the closest locale when the user visits the site.
991
+ * @deprecated Use `route.localeRedirect` instead.
897
992
  * @default 'auto'
898
993
  */
899
994
  localeRedirect?: 'auto' | 'never' | 'only-default-lang';
@@ -904,8 +999,8 @@ declare type ThemeConfig = {
904
999
  fallbackHeadingTitle?: boolean;
905
1000
  /**
906
1001
  * LLMS UI components configuration.
907
- * When llmsUI.enableOnH1 is true, LlmsCopyButton and LlmsViewOptions
908
- * will be automatically added below H1 headers.
1002
+ * When enabled, LlmsCopyButton and LlmsViewOptions will be automatically
1003
+ * added below H1 headers or to the outline sidebar.
909
1004
  */
910
1005
  llmsUI?: LlmsUI;
911
1006
  };
@@ -1055,6 +1150,11 @@ export declare interface UserConfig {
1055
1150
  * @experimental
1056
1151
  */
1057
1152
  llms?: boolean | {
1153
+ /**
1154
+ * Customize the content of generated llms.txt files.
1155
+ * @experimental
1156
+ */
1157
+ llmsTxt?: LlmsTxtRenderer;
1058
1158
  /**
1059
1159
  * @experimental
1060
1160
  */
@@ -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
 
@@ -74,6 +73,7 @@ declare interface FrontMatterMeta {
74
73
  pageType?: PageType;
75
74
  features?: Feature[];
76
75
  hero?: Hero;
76
+ icon?: string;
77
77
  tag?: string;
78
78
  navbar?: boolean;
79
79
  sidebar?: boolean | 'placeholder';
@@ -195,18 +195,103 @@ declare type LastUpdatedAuthor = boolean | ((info: {
195
195
  filePath: string;
196
196
  }) => string);
197
197
 
198
+ declare interface LlmsTxtContext {
199
+ /**
200
+ * The site title.
201
+ */
202
+ title: string | undefined;
203
+ /**
204
+ * The site description.
205
+ */
206
+ description: string | undefined;
207
+ /**
208
+ * The language of the generated llms.txt.
209
+ */
210
+ lang: string;
211
+ /**
212
+ * The version of the generated llms.txt.
213
+ */
214
+ version: string;
215
+ /**
216
+ * The configured base path.
217
+ */
218
+ base: string;
219
+ /**
220
+ * The configured site origin.
221
+ */
222
+ siteOrigin: string | undefined;
223
+ /**
224
+ * Page sections in navigation order.
225
+ */
226
+ sections: LlmsTxtSection[];
227
+ }
228
+
229
+ declare interface LlmsTxtPage {
230
+ /**
231
+ * The route path of the page.
232
+ */
233
+ routePath: string;
234
+ /**
235
+ * The URL of the generated Markdown file.
236
+ */
237
+ link: string;
238
+ /**
239
+ * The title of the page.
240
+ */
241
+ title: string;
242
+ /**
243
+ * The description of the page.
244
+ */
245
+ description?: string;
246
+ /**
247
+ * The frontmatter of the page.
248
+ */
249
+ frontmatter: FrontMatterMeta;
250
+ /**
251
+ * The language of the page.
252
+ */
253
+ lang: string;
254
+ /**
255
+ * The version of the page.
256
+ */
257
+ version: string;
258
+ }
259
+
260
+ declare type LlmsTxtRenderer = (context: LlmsTxtContext) => string | Promise<string>;
261
+
262
+ declare interface LlmsTxtSection {
263
+ /**
264
+ * The title of the section, derived from navigation.
265
+ */
266
+ title: string;
267
+ /**
268
+ * Pages in navigation and sidebar order.
269
+ */
270
+ pages: LlmsTxtPage[];
271
+ }
272
+
198
273
  /**
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.
274
+ * Configuration for LLMS UI components displayed below H1 headers or in the
275
+ * outline sidebar. When enabled, the copy and view options UI will be added
276
+ * automatically without requiring custom getCustomMDXComponent.
202
277
  * @default false
203
278
  */
204
279
  declare type LlmsUI = {
280
+ /**
281
+ * Whether to inject an LLM directive hint into generated pages. In SSG
282
+ * HTML output, it is rendered as a visually hidden plain-text DOM element
283
+ * with llms.txt, llms-full.txt, and the current page's Markdown version.
284
+ * In SSG-MD Markdown output, it is rendered as a leading blockquote
285
+ * string.
286
+ * @default true
287
+ */
288
+ injectLlmsHint?: boolean;
205
289
  /**
206
290
  * Options for LlmsViewOptions component dropdown menu.
291
+ * Set to `false` or an empty array to hide the view options UI.
207
292
  * @default ['markdownLink', 'chatgpt', 'claude']
208
293
  */
209
- viewOptions?: LlmsViewOption[];
294
+ viewOptions?: false | LlmsViewOption[];
210
295
  /**
211
296
  * Where to display the LLM UI components.
212
297
  * - 'title': Show as buttons below the H1 title (default)
@@ -217,17 +302,10 @@ declare type LlmsUI = {
217
302
  } | boolean;
218
303
 
219
304
  /**
220
- * Option item for LlmsViewOptions component.
305
+ * Built-in option item for LlmsViewOptions configured through
306
+ * `rspress.config.ts`.
221
307
  */
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
- };
308
+ declare type LlmsViewOption = 'markdownLink' | 'chatgpt' | 'claude';
231
309
 
232
310
  export declare function loadFrontMatter<TFrontmatter extends Record<string, unknown> = FrontMatterMeta>(source: string, filepath: string, root: string, outputWarning?: boolean): {
233
311
  frontmatter: TFrontmatter;
@@ -356,6 +434,7 @@ declare type NavItem = NavItemWithLink | NavItemWithChildren | NavItemWithLinkAn
356
434
 
357
435
  declare interface NavItemWithChildren {
358
436
  text?: string;
437
+ icon?: string;
359
438
  tag?: string;
360
439
  items: NavItem[];
361
440
  position?: 'left' | 'right';
@@ -365,6 +444,7 @@ declare type NavItemWithLink = {
365
444
  text: string;
366
445
  link: string;
367
446
  download?: boolean;
447
+ icon?: string;
368
448
  tag?: string;
369
449
  activeMatch?: string;
370
450
  position?: 'left' | 'right';
@@ -376,6 +456,7 @@ declare interface NavItemWithLinkAndChildren {
376
456
  text: string;
377
457
  link: string;
378
458
  items: NavItem[];
459
+ icon?: string;
379
460
  tag?: string;
380
461
  activeMatch?: string;
381
462
  position?: 'left' | 'right';
@@ -470,6 +551,10 @@ declare interface ReplaceRule {
470
551
 
471
552
  declare interface RouteMeta {
472
553
  routePath: string;
554
+ /**
555
+ * Route path without language and version prefixes.
556
+ */
557
+ pureRoutePath: string;
473
558
  absolutePath: string;
474
559
  relativePath: string;
475
560
  pageName: string;
@@ -503,6 +588,12 @@ declare interface RouteOptions {
503
588
  * @default false
504
589
  */
505
590
  cleanUrls?: boolean;
591
+ /**
592
+ * How to redirect first-time visitors to the closest configured locale
593
+ * based on their browser language.
594
+ * @default 'auto'
595
+ */
596
+ localeRedirect?: 'auto' | 'never' | 'only-default-lang';
506
597
  /**
507
598
  * Enable concurrent, optimized routing for internal links rendered by
508
599
  * Rspress' default Link component.
@@ -609,6 +700,7 @@ declare type SidebarDivider = {
609
700
  declare interface SidebarGroup {
610
701
  text: string;
611
702
  link?: string;
703
+ icon?: string;
612
704
  tag?: string;
613
705
  items: (SidebarGroup | SidebarItem | SidebarDivider | SidebarSectionHeader)[];
614
706
  collapsible?: boolean;
@@ -624,6 +716,7 @@ declare interface SidebarGroup {
624
716
  declare type SidebarItem = {
625
717
  text: string;
626
718
  link: string;
719
+ icon?: string;
627
720
  tag?: string;
628
721
  /**
629
722
  * For hmr usage in development
@@ -635,6 +728,7 @@ declare type SidebarItem = {
635
728
 
636
729
  declare type SidebarSectionHeader = {
637
730
  sectionHeaderText: string;
731
+ icon?: string;
638
732
  tag?: string;
639
733
  };
640
734
 
@@ -726,7 +820,8 @@ declare type ThemeConfig = {
726
820
  */
727
821
  enableScrollToTop?: boolean;
728
822
  /**
729
- * Whether to redirect to the closest locale when the user visits the site
823
+ * Whether to redirect to the closest locale when the user visits the site.
824
+ * @deprecated Use `route.localeRedirect` instead.
730
825
  * @default 'auto'
731
826
  */
732
827
  localeRedirect?: 'auto' | 'never' | 'only-default-lang';
@@ -737,8 +832,8 @@ declare type ThemeConfig = {
737
832
  fallbackHeadingTitle?: boolean;
738
833
  /**
739
834
  * LLMS UI components configuration.
740
- * When llmsUI.enableOnH1 is true, LlmsCopyButton and LlmsViewOptions
741
- * will be automatically added below H1 headers.
835
+ * When enabled, LlmsCopyButton and LlmsViewOptions will be automatically
836
+ * added below H1 headers or to the outline sidebar.
742
837
  */
743
838
  llmsUI?: LlmsUI;
744
839
  };
@@ -884,6 +979,11 @@ declare interface UserConfig {
884
979
  * @experimental
885
980
  */
886
981
  llms?: boolean | {
982
+ /**
983
+ * Customize the content of generated llms.txt files.
984
+ * @experimental
985
+ */
986
+ llmsTxt?: LlmsTxtRenderer;
887
987
  /**
888
988
  * @experimental
889
989
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/shared",
3
- "version": "2.0.17",
3
+ "version": "2.0.19",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/web-infra-dev/rspress.git",
@@ -44,19 +44,19 @@
44
44
  "dist"
45
45
  ],
46
46
  "dependencies": {
47
- "@rsbuild/core": "^2.1.5",
47
+ "@rsbuild/core": "^2.1.8",
48
48
  "@shikijs/rehype": "^4.2.0",
49
+ "@types/react": "^19.2.17",
50
+ "mdast-util-mdx-jsx": "^3.2.0",
49
51
  "unified": "^11.0.5"
50
52
  },
51
53
  "devDependencies": {
52
- "@rslib/core": "0.23.2",
54
+ "@rslib/core": "1.0.0-beta.1",
53
55
  "@types/lodash-es": "^4.17.12",
54
56
  "@types/node": "^22.8.1",
55
- "@types/react": "^19.2.17",
56
57
  "github-slugger": "^2.0.0",
57
58
  "gray-matter": "4.0.3",
58
59
  "lodash-es": "^4.18.1",
59
- "mdast-util-mdx-jsx": "^3.2.0",
60
60
  "medium-zoom": "1.1.0",
61
61
  "rimraf": "^6.1.3",
62
62
  "rsbuild-plugin-publint": "^1.0.0",