@rspress/plugin-llms 2.0.0-alpha.8 → 2.0.0-beta.10

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,760 +1,52 @@
1
- import type { PluggableList } from 'unified';
2
- import { RsbuildConfig } from './types';
3
- import { RsbuildPlugin } from './types';
1
+ import type { PageIndexInfo } from '@rspress/shared';
2
+ import type { RspressPlugin } from '@rspress/shared';
4
3
 
5
- /**
6
- * There are two ways to define what addition routes represent.
7
- * 1. Define filepath, then the content will be read from the file.
8
- * 2. Define content, then then content will be written to temp file and read from it.
9
- */
10
- declare interface AdditionalPage {
11
- routePath: string;
12
- content?: string;
13
- filepath?: string;
4
+ export declare interface LlmsTxt {
5
+ onTitleGenerate?: (context: {
6
+ title: string | undefined;
7
+ description: string | undefined;
8
+ }) => string;
9
+ onLineGenerate?: (page: PageIndexInfo) => string;
10
+ onAfterLlmsTxtGenerate?: (llmsTxtContent: string) => string;
14
11
  }
15
12
 
16
- declare interface DefaultThemeConfig {
13
+ export declare interface Options {
17
14
  /**
18
- * Whether to enable dark mode.
15
+ * Whether to generate llms.txt.
19
16
  * @default true
20
17
  */
21
- darkMode?: boolean;
22
- /**
23
- * Custom outline title in the aside component.
24
- *
25
- * @default 'ON THIS PAGE'
26
- */
27
- outlineTitle?: string;
28
- /**
29
- * Whether to show the sidebar in right position.
30
- */
31
- outline?: boolean;
32
- /**
33
- * The nav items. When it's an object, the key is the version of current doc.
34
- */
35
- nav?: NavItem[] | {
36
- [key: string]: NavItem[];
37
- };
38
- /**
39
- * The sidebar items.
40
- */
41
- sidebar?: Sidebar;
42
- /**
43
- * Info for the edit link. If it's undefined, the edit link feature will
44
- * be disabled.
45
- */
46
- editLink?: EditLink;
47
- /**
48
- * Set custom last updated text.
49
- *
50
- * @default 'Last updated'
51
- */
52
- lastUpdatedText?: string;
53
- /**
54
- * Set custom last updated text.
55
- *
56
- * @default false
57
- */
58
- lastUpdated?: boolean;
59
- /**
60
- * Set custom prev/next labels.
61
- */
62
- docFooter?: DocFooter;
63
- /**
64
- * The social links to be displayed at the end of the nav bar. Perfect for
65
- * placing links to social services such as GitHub, X, Facebook, etc.
66
- */
67
- socialLinks?: SocialLink[];
68
- /**
69
- * The footer configuration.
70
- */
71
- footer?: Footer;
72
- /**
73
- * The prev page text.
74
- */
75
- prevPageText?: string;
76
- /**
77
- * The next page text.
78
- */
79
- nextPageText?: string;
80
- /**
81
- * The source code text.
82
- */
83
- sourceCodeText?: string;
84
- /**
85
- * Locale config
86
- */
87
- locales?: LocaleConfig[];
88
- /**
89
- * Whether to open the full text search
90
- */
91
- search?: boolean;
92
- /**
93
- * The placeholder of search input
94
- */
95
- searchPlaceholderText?: string;
96
- /**
97
- * The text of no search result
98
- */
99
- searchNoResultsText?: string;
100
- /**
101
- * The text of suggested query text when no search result
102
- */
103
- searchSuggestedQueryText?: string;
104
- /**
105
- * The text of overview filter
106
- */
107
- overview?: FilterConfig;
108
- /**
109
- * The behavior of hiding navbar
110
- */
111
- hideNavbar?: 'always' | 'auto' | 'never';
112
- /**
113
- * Whether to enable view transition animation for pages switching
114
- */
115
- enableContentAnimation?: boolean;
116
- /**
117
- * Whether to enable view transition animation for the theme
118
- */
119
- enableAppearanceAnimation?: boolean;
120
- /**
121
- * Enable scroll to top button on documentation
122
- * @default false
123
- */
124
- enableScrollToTop?: boolean;
125
- /**
126
- * Whether to redirect to the closest locale when the user visits the site
127
- * @default 'auto'
128
- */
129
- localeRedirect?: 'auto' | 'never';
18
+ llmsTxt?: boolean | LlmsTxt;
130
19
  /**
131
- * Whether to show the fallback heading title when the heading title is not presented but `frontmatter.title` exists
20
+ * Whether to generate llms.txt related md files for each route.
132
21
  * @default true
133
22
  */
134
- fallbackHeadingTitle?: boolean;
135
- }
136
-
137
- declare interface DocFooter {
138
- /**
139
- * Custom label for previous page button.
140
- */
141
- prev?: SidebarItem;
142
- /**
143
- * Custom label for next page button.
144
- */
145
- next?: SidebarItem;
146
- }
147
-
148
- declare interface EditLink {
23
+ mdFiles?: boolean;
149
24
  /**
150
- * Custom repository url for edit link.
151
- */
152
- docRepoBaseUrl: string;
153
- /**
154
- * Custom text for edit link.
155
- *
156
- * @default 'Edit this page'
157
- */
158
- text?: string;
159
- }
160
-
161
- declare interface Feature {
162
- icon: string;
163
- title: string;
164
- details: string;
165
- span?: number;
166
- link?: string;
167
- }
168
-
169
- /**
170
- * The config of filter component
171
- */
172
- declare interface FilterConfig {
173
- filterNameText?: string;
174
- filterPlaceholderText?: string;
175
- filterNoResultText?: string;
176
- }
177
-
178
- declare interface Footer {
179
- message?: string;
180
- }
181
-
182
- declare interface FrontMatterMeta {
183
- title?: string;
184
- description?: string;
185
- overview?: boolean;
186
- pageType?: PageType;
187
- features?: Feature[];
188
- hero?: Hero;
189
- sidebar?: boolean;
190
- outline?: boolean;
191
- lineNumbers?: boolean;
192
- overviewHeaders?: number[];
193
- titleSuffix?: string;
194
- head?: [string, Record<string, string>][];
195
- context?: string;
196
- footer?: boolean;
197
- [key: string]: unknown;
198
- }
199
-
200
- declare interface Header {
201
- id: string;
202
- text: string;
203
- depth: number;
204
- charIndex: number;
205
- }
206
-
207
- declare interface Hero {
208
- name: string;
209
- text: string;
210
- tagline: string;
211
- image?: {
212
- src: string | {
213
- dark: string;
214
- light: string;
215
- };
216
- alt: string;
217
- /**
218
- * `srcset` and `sizes` are attributes of `<img>` tag. Please refer to https://mdn.io/srcset for the usage.
219
- * When the value is an array, rspress will join array members with commas.
220
- **/
221
- sizes?: string | string[];
222
- srcset?: string | string[];
223
- };
224
- actions: {
225
- text: string;
226
- link: string;
227
- theme: 'brand' | 'alt';
228
- }[];
229
- }
230
-
231
- declare interface Locale {
232
- lang: string;
233
- label: string;
234
- title?: string;
235
- description?: string;
236
- }
237
-
238
- /**
239
- * locale config
240
- */
241
- declare interface LocaleConfig {
242
- /**
243
- * Site i18n config, which will recover the locales config in the site level.
244
- */
245
- lang: string;
246
- title?: string;
247
- description?: string;
248
- label: string;
249
- /**
250
- * Theme i18n config
251
- */
252
- nav?: Nav;
253
- sidebar?: Sidebar;
254
- outlineTitle?: string;
255
- lastUpdatedText?: string;
256
- lastUpdated?: boolean;
257
- editLink?: EditLink;
258
- prevPageText?: string;
259
- nextPageText?: string;
260
- sourceCodeText?: string;
261
- langRoutePrefix?: string;
262
- searchPlaceholderText?: string;
263
- searchNoResultsText?: string;
264
- searchSuggestedQueryText?: string;
265
- overview?: FilterConfig;
266
- }
267
-
268
- declare type LocalSearchOptions = SearchHooks & {
269
- mode?: 'local';
270
- /**
271
- * Whether to generate separate search index for each version
272
- */
273
- versioned?: boolean;
274
- /**
275
- * If enabled, the search index will include code block content, which allows users to search code blocks.
276
- * @default false
277
- */
278
- codeBlocks?: boolean;
279
- };
280
-
281
- declare interface MarkdownOptions {
282
- remarkPlugins?: PluggableList;
283
- rehypePlugins?: PluggableList;
284
- /**
285
- * Whether to enable check dead links, default is false
286
- */
287
- checkDeadLinks?: boolean;
288
- showLineNumbers?: boolean;
289
- /**
290
- * Whether to wrap code by default, default is false
291
- */
292
- defaultWrapCode?: boolean;
293
- /**
294
- * Register global components in mdx files
295
- */
296
- globalComponents?: string[];
297
- /**
298
- * Code highlighter, default is prism for performance reason
299
- */
300
- codeHighlighter?: 'prism' | 'shiki';
301
- /**
302
- * Register prism languages
303
- */
304
- highlightLanguages?: (string | [string, string])[];
305
- /**
306
- * Whether to enable mdx-rs, default is true
25
+ * Whether to generate llms-full.txt.
26
+ * @default true
307
27
  */
308
- mdxRs?: boolean | MdxRsOptions;
28
+ llmsFullTxt?: boolean;
309
29
  /**
310
- * @deprecated, use `mdxRs` instead
30
+ * Whether to include some routes from llms.txt.
31
+ * @param context
32
+ * @default (context) => context.page.lang === config.lang
311
33
  */
312
- experimentalMdxRs?: boolean;
313
- }
314
-
315
- declare interface MdxRsOptions {
34
+ include?: (context: {
35
+ page: PageIndexInfo;
36
+ }) => boolean;
316
37
  /**
317
- * Determine whether the file use mdxRs compiler
38
+ * Whether to exclude some routes from llms.txt.
39
+ * exclude will trigger after include
40
+ * @default undefined
318
41
  */
319
- include?: (filepath: string) => boolean;
320
- }
321
-
322
- declare type Nav = NavItem[] | {
323
- [key: string]: NavItem[];
324
- };
325
-
326
- declare type NavItem = NavItemWithLink | NavItemWithChildren | NavItemWithLinkAndChildren;
327
-
328
- declare interface NavItemWithChildren {
329
- text?: string;
330
- tag?: string;
331
- items: NavItemWithLink[];
332
- position?: 'left' | 'right';
333
- }
334
-
335
- declare type NavItemWithLink = {
336
- text: string;
337
- link: string;
338
- tag?: string;
339
- activeMatch?: string;
340
- position?: 'left' | 'right';
341
- };
342
-
343
- declare interface NavItemWithLinkAndChildren {
344
- text: string;
345
- link: string;
346
- items: NavItemWithLink[];
347
- tag?: string;
348
- activeMatch?: string;
349
- position?: 'left' | 'right';
350
- }
351
-
352
- declare interface Options {
353
- output: {
354
- llmsTxt?: boolean;
355
- mdFiles?: boolean;
356
- llmsFullTxt?: boolean;
357
- };
42
+ exclude?: (context: {
43
+ page: PageIndexInfo;
44
+ }) => boolean;
358
45
  }
359
46
 
360
- /**
361
- * @description search-index.json file
362
- * "_foo" is the private field that won't be written to search-index.json file
363
- * and should not be used in the runtime (usePageData).
364
- */
365
- declare interface PageIndexInfo {
366
- id: number;
367
- title: string;
368
- routePath: string;
369
- toc: Header[];
370
- content: string;
371
- flattenContent?: string;
372
- _html: string;
373
- frontmatter: FrontMatterMeta;
374
- lang: string;
375
- version: string;
376
- domain: string;
377
- _filepath: string;
378
- _relativePath: string;
379
- }
380
-
381
- declare type PageType = 'home' | 'doc' | 'custom' | '404' | 'blank';
382
-
383
47
  /**
384
48
  * A plugin for rspress to generate llms.txt, llms-full.txt, md files to let llm understand your website.
385
49
  */
386
50
  export declare function pluginLlms(options?: Options): RspressPlugin;
387
51
 
388
- declare type RemoteSearchIndexInfo = string | {
389
- value: string;
390
- label: string;
391
- };
392
-
393
- declare type RemoteSearchOptions = SearchHooks & {
394
- mode: 'remote';
395
- apiUrl: string;
396
- domain?: string;
397
- indexName: string;
398
- searchIndexes?: RemoteSearchIndexInfo[];
399
- searchLoading?: boolean;
400
- };
401
-
402
- declare interface ReplaceRule {
403
- search: string | RegExp;
404
- replace: string;
405
- }
406
-
407
- declare interface RouteMeta {
408
- routePath: string;
409
- absolutePath: string;
410
- relativePath: string;
411
- pageName: string;
412
- lang: string;
413
- version: string;
414
- }
415
-
416
- declare interface RouteOptions {
417
- /**
418
- * The extension name of the filepath that will be converted to a route
419
- * @default ['js','jsx','ts','tsx','md','mdx']
420
- */
421
- extensions?: string[];
422
- /**
423
- * Include extra files from being converted to routes
424
- */
425
- include?: string[];
426
- /**
427
- * Exclude files from being converted to routes
428
- */
429
- exclude?: string[];
430
- /**
431
- * use links without .html files
432
- */
433
- cleanUrls?: boolean;
434
- }
435
-
436
- declare interface RspressPlugin {
437
- /**
438
- * Name of the plugin.
439
- */
440
- name: string;
441
- /**
442
- * Global style
443
- */
444
- globalStyles?: string;
445
- /**
446
- * Markdown options.
447
- */
448
- markdown?: {
449
- remarkPlugins?: PluggableList;
450
- rehypePlugins?: PluggableList;
451
- globalComponents?: string[];
452
- };
453
- /**
454
- * Rsbuild config.
455
- */
456
- builderConfig?: RsbuildConfig;
457
- /**
458
- * Inject global components.
459
- */
460
- globalUIComponents?: (string | [string, object])[];
461
- /**
462
- * Modify doc config.
463
- */
464
- config?: (config: UserConfig, utils: {
465
- addPlugin: (plugin: RspressPlugin) => void;
466
- removePlugin: (pluginName: string) => void;
467
- }, isProd: boolean) => UserConfig | Promise<UserConfig>;
468
- /**
469
- * Callback before build
470
- */
471
- beforeBuild?: (config: UserConfig, isProd: boolean) => void | Promise<void>;
472
- /**
473
- * Callback after build
474
- */
475
- afterBuild?: (config: UserConfig, isProd: boolean) => void | Promise<void>;
476
- /**
477
- * Extend every page's data
478
- */
479
- extendPageData?: (pageData: PageIndexInfo, isProd: boolean) => void | Promise<void>;
480
- /**
481
- * Add custom route
482
- */
483
- addPages?: (config: UserConfig, isProd: boolean) => AdditionalPage[] | Promise<AdditionalPage[]>;
484
- /**
485
- * Add runtime modules
486
- */
487
- addRuntimeModules?: (config: UserConfig, isProd: boolean) => Record<string, string> | Promise<Record<string, string>>;
488
- /**
489
- * Callback after route generated
490
- */
491
- routeGenerated?: (routes: RouteMeta[], isProd: boolean) => Promise<void> | void;
492
- /**
493
- * Callback after routeService generated
494
- */
495
- routeServiceGenerated?: (routeService: any, isProd: boolean) => Promise<void> | void;
496
- /**
497
- * Add addition ssg routes, for dynamic routes.
498
- */
499
- addSSGRoutes?: (config: UserConfig, isProd: boolean) => {
500
- path: string;
501
- }[] | Promise<{
502
- path: string;
503
- }[]>;
504
- /**
505
- * @private
506
- * Modify search index data.
507
- */
508
- modifySearchIndexData?: (data: PageIndexInfo[], isProd: boolean) => void | Promise<void>;
509
- }
510
-
511
- declare interface SearchHooks {
512
- /**
513
- * The search hook function path. The corresponding file should export a function named `onSearch`.
514
- */
515
- searchHooks?: string;
516
- }
517
-
518
- declare type SearchOptions = LocalSearchOptions | RemoteSearchOptions | false;
519
-
520
- declare interface Sidebar {
521
- [path: string]: (SidebarGroup | SidebarItem | SidebarDivider | SidebarSectionHeader)[];
522
- }
523
-
524
- declare type SidebarDivider = {
525
- dividerType: 'dashed' | 'solid';
526
- };
527
-
528
- declare interface SidebarGroup {
529
- text: string;
530
- link?: string;
531
- tag?: string;
532
- items: (SidebarItem | SidebarDivider | SidebarGroup | string)[];
533
- collapsible?: boolean;
534
- collapsed?: boolean;
535
- /**
536
- * For hmr usage in development
537
- */
538
- _fileKey?: string;
539
- overviewHeaders?: number[];
540
- context?: string;
541
- }
542
-
543
- declare type SidebarItem = {
544
- text: string;
545
- link: string;
546
- tag?: string;
547
- /**
548
- * For hmr usage in development
549
- */
550
- _fileKey?: string;
551
- overviewHeaders?: number[];
552
- context?: string;
553
- };
554
-
555
- declare type SidebarSectionHeader = {
556
- sectionHeaderText: string;
557
- tag?: string;
558
- };
559
-
560
- declare interface SocialLink {
561
- icon: SocialLinkIcon;
562
- mode: 'link' | 'text' | 'img' | 'dom';
563
- content: string;
564
- }
565
-
566
- declare type SocialLinkIcon = 'lark' | 'discord' | 'facebook' | 'github' | 'instagram' | 'linkedin' | 'slack' | 'x' | 'youtube' | 'wechat' | 'qq' | 'juejin' | 'zhihu' | 'bilibili' | 'weibo' | 'gitlab' | 'X' | 'bluesky' | {
567
- svg: string;
568
- };
569
-
570
- declare interface UserConfig<ThemeConfig = DefaultThemeConfig> {
571
- /**
572
- * The root directory of the site.
573
- * @default 'docs'
574
- */
575
- root?: string;
576
- /**
577
- * Path to the logo file in nav bar.
578
- */
579
- logo?: string | {
580
- dark: string;
581
- light: string;
582
- };
583
- /**
584
- * The text of the logo in nav bar.
585
- * @default ''
586
- */
587
- logoText?: string;
588
- /**
589
- * Base path of the site.
590
- * @default '/'
591
- */
592
- base?: string;
593
- /**
594
- * Path to html icon file.
595
- */
596
- icon?: string;
597
- /**
598
- * Default language of the site.
599
- */
600
- lang?: string;
601
- /**
602
- * Title of the site.
603
- * @default 'Rspress'
604
- */
605
- title?: string;
606
- /**
607
- * Description of the site.
608
- * @default ''
609
- */
610
- description?: string;
611
- /**
612
- * Head tags.
613
- */
614
- head?: (string | [string, Record<string, string>] | ((route: RouteMeta) => string | [string, Record<string, string>] | undefined))[];
615
- /**
616
- * I18n config of the site.
617
- */
618
- locales?: Locale[];
619
- /**
620
- * The i18n text data source path. Default is `i18n.json` in cwd.
621
- */
622
- i18nSourcePath?: string;
623
- /**
624
- * Theme config.
625
- */
626
- themeConfig?: ThemeConfig;
627
- /**
628
- * Rsbuild Configuration
629
- */
630
- builderConfig?: RsbuildConfig;
631
- /**
632
- * The custom config of vite-plugin-route
633
- */
634
- route?: RouteOptions;
635
- /**
636
- * The custom config of markdown compile
637
- */
638
- markdown?: MarkdownOptions;
639
- /**
640
- * Doc plugins
641
- */
642
- plugins?: RspressPlugin[];
643
- /**
644
- * Replace rule, will replace the content of the page.
645
- */
646
- replaceRules?: ReplaceRule[];
647
- /**
648
- * Output directory
649
- */
650
- outDir?: string;
651
- /**
652
- * Custom theme directory
653
- */
654
- themeDir?: string;
655
- /**
656
- * Global components
657
- */
658
- globalUIComponents?: (string | [string, object])[];
659
- /**
660
- * Global styles, is a Absolute path
661
- */
662
- globalStyles?: string;
663
- /**
664
- * Search options
665
- */
666
- search?: SearchOptions;
667
- /**
668
- * Whether to enable ssg, default is true
669
- */
670
- ssg?: boolean;
671
- /**
672
- * Whether to enable medium-zoom, default is true
673
- */
674
- mediumZoom?: boolean | {
675
- selector?: string;
676
- options?: ZoomOptions;
677
- };
678
- /**
679
- * Add some extra builder plugins
680
- */
681
- builderPlugins?: RsbuildPlugin[];
682
- /**
683
- * Multi version config
684
- */
685
- multiVersion?: {
686
- /**
687
- * The default version
688
- */
689
- default?: string;
690
- /**
691
- * The version list, such as ['v1', 'v2']
692
- */
693
- versions: string[];
694
- };
695
- /**
696
- * Language parity checking config
697
- */
698
- languageParity?: {
699
- /**
700
- * Whether to enable language parity checking
701
- */
702
- enabled?: boolean;
703
- /**
704
- * Directories to include in the parity check
705
- */
706
- include?: string[];
707
- /**
708
- * Directories to exclude from the parity check
709
- */
710
- exclude?: string[];
711
- };
712
- }
713
-
714
- declare interface ZoomContainer {
715
- width?: number
716
- height?: number
717
- top?: number
718
- bottom?: number
719
- right?: number
720
- left?: number
721
- }
722
-
723
- declare interface ZoomOptions {
724
- /**
725
- * The space outside the zoomed image.
726
- *
727
- * @default 0
728
- */
729
- margin?: number
730
-
731
- /**
732
- * The background of the overlay.
733
- *
734
- * @default '#fff'
735
- */
736
- background?: string
737
-
738
- /**
739
- * The number of pixels to scroll to close the zoom.
740
- *
741
- * @default 40
742
- */
743
- scrollOffset?: number
744
-
745
- /**
746
- * The viewport to render the zoom in.
747
- *
748
- * @default null
749
- */
750
- container?: string | HTMLElement | ZoomContainer
751
-
752
- /**
753
- * The template element to display on zoom.
754
- *
755
- * @default null
756
- */
757
- template?: string | HTMLTemplateElement
758
- }
759
-
760
52
  export { }