@rspress/shared 1.41.0 → 1.41.2

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.
@@ -1,12 +1,703 @@
1
- import { U as UserConfig } from './index-ba0faa42.js';
2
- import '@rsbuild/core';
3
- import 'unified';
4
-
5
- declare function loadFrontMatter<TFrontmatter extends Record<string, unknown> = Record<string, string>>(source: string, filepath: string, root: string, outputWarning?: boolean): {
6
- frontmatter: TFrontmatter;
7
- content: string;
8
- };
9
-
10
- declare const mergeDocConfig: (...configs: UserConfig[]) => Promise<UserConfig>;
11
-
12
- export { loadFrontMatter, mergeDocConfig };
1
+ import type { PluggableList } from 'unified';
2
+ import type { RsbuildConfig } from '@rsbuild/core';
3
+ import type { RsbuildPlugin } from '@rsbuild/core';
4
+
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;
14
+ }
15
+
16
+ declare interface Config {
17
+ /**
18
+ * Whether to enable dark mode.
19
+ * @default true
20
+ */
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';
130
+ /**
131
+ * Whether to show the fallback heading title when the heading title is not presented but `frontmatter.title` exists
132
+ * @default true
133
+ */
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 {
149
+ /**
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
+ /**
162
+ * The config of filter component
163
+ */
164
+ declare interface FilterConfig {
165
+ filterNameText?: string;
166
+ filterPlaceholderText?: string;
167
+ filterNoResultText?: string;
168
+ }
169
+
170
+ declare interface Footer {
171
+ message?: string;
172
+ }
173
+
174
+ declare interface Header {
175
+ id: string;
176
+ text: string;
177
+ depth: number;
178
+ charIndex: number;
179
+ }
180
+
181
+ export declare function loadFrontMatter<TFrontmatter extends Record<string, unknown> = Record<string, string>>(source: string, filepath: string, root: string, outputWarning?: boolean): {
182
+ frontmatter: TFrontmatter;
183
+ content: string;
184
+ };
185
+
186
+ declare interface Locale {
187
+ lang: string;
188
+ label: string;
189
+ title?: string;
190
+ description?: string;
191
+ }
192
+
193
+ /**
194
+ * locale config
195
+ */
196
+ declare interface LocaleConfig {
197
+ /**
198
+ * Site i18n config, which will recover the locales config in the site level.
199
+ */
200
+ lang: string;
201
+ title?: string;
202
+ description?: string;
203
+ label: string;
204
+ /**
205
+ * Theme i18n config
206
+ */
207
+ nav?: Nav;
208
+ sidebar?: Sidebar;
209
+ outlineTitle?: string;
210
+ lastUpdatedText?: string;
211
+ lastUpdated?: boolean;
212
+ editLink?: EditLink;
213
+ prevPageText?: string;
214
+ nextPageText?: string;
215
+ sourceCodeText?: string;
216
+ langRoutePrefix?: string;
217
+ searchPlaceholderText?: string;
218
+ searchNoResultsText?: string;
219
+ searchSuggestedQueryText?: string;
220
+ overview?: FilterConfig;
221
+ }
222
+
223
+ declare type LocalSearchOptions = SearchHooks & {
224
+ mode?: 'local';
225
+ /**
226
+ * Whether to generate separate search index for each version
227
+ */
228
+ versioned?: boolean;
229
+ /**
230
+ * If enabled, the search index will include code block content, which allows users to search code blocks.
231
+ * @default false
232
+ */
233
+ codeBlocks?: boolean;
234
+ };
235
+
236
+ declare interface MarkdownOptions {
237
+ remarkPlugins?: PluggableList;
238
+ rehypePlugins?: PluggableList;
239
+ /**
240
+ * Whether to enable check dead links, default is false
241
+ */
242
+ checkDeadLinks?: boolean;
243
+ showLineNumbers?: boolean;
244
+ /**
245
+ * Whether to wrap code by default, default is false
246
+ */
247
+ defaultWrapCode?: boolean;
248
+ /**
249
+ * Register global components in mdx files
250
+ */
251
+ globalComponents?: string[];
252
+ /**
253
+ * Code highlighter, default is prism for performance reason
254
+ */
255
+ codeHighlighter?: 'prism' | 'shiki';
256
+ /**
257
+ * Register prism languages
258
+ */
259
+ highlightLanguages?: (string | [string, string])[];
260
+ /**
261
+ * Whether to enable mdx-rs, default is true
262
+ */
263
+ mdxRs?: boolean | MdxRsOptions;
264
+ /**
265
+ * @deprecated, use `mdxRs` instead
266
+ */
267
+ experimentalMdxRs?: boolean;
268
+ }
269
+
270
+ declare interface MdxRsOptions {
271
+ /**
272
+ * Determine whether the file use mdxRs compiler
273
+ */
274
+ include?: (filepath: string) => boolean;
275
+ }
276
+
277
+ export declare const mergeDocConfig: (...configs: UserConfig[]) => Promise<UserConfig>;
278
+
279
+ declare type Nav = NavItem[] | {
280
+ [key: string]: NavItem[];
281
+ };
282
+
283
+ declare type NavItem = NavItemWithLink | NavItemWithChildren | NavItemWithLinkAndChildren;
284
+
285
+ declare interface NavItemWithChildren {
286
+ text?: string;
287
+ tag?: string;
288
+ items: NavItemWithLink[];
289
+ position?: 'left' | 'right';
290
+ }
291
+
292
+ declare type NavItemWithLink = {
293
+ text: string;
294
+ link: string;
295
+ tag?: string;
296
+ activeMatch?: string;
297
+ position?: 'left' | 'right';
298
+ };
299
+
300
+ declare interface NavItemWithLinkAndChildren {
301
+ text: string;
302
+ link: string;
303
+ items: NavItemWithLink[];
304
+ tag?: string;
305
+ activeMatch?: string;
306
+ position?: 'left' | 'right';
307
+ }
308
+
309
+ /**
310
+ * @description search-index.json file
311
+ * "_foo" is the private field that won't be written to search-index.json file
312
+ * and should not be used in the runtime (usePageData).
313
+ */
314
+ declare type PageIndexInfo = {
315
+ id: number;
316
+ title: string;
317
+ routePath: string;
318
+ toc: Header[];
319
+ content: string;
320
+ _html: string;
321
+ frontmatter: Record<string, unknown>;
322
+ lang: string;
323
+ version: string;
324
+ domain: string;
325
+ _filepath: string;
326
+ _relativePath: string;
327
+ };
328
+
329
+ declare type RemoteSearchIndexInfo = string | {
330
+ value: string;
331
+ label: string;
332
+ };
333
+
334
+ declare type RemoteSearchOptions = SearchHooks & {
335
+ mode: 'remote';
336
+ apiUrl: string;
337
+ domain?: string;
338
+ indexName: string;
339
+ searchIndexes?: RemoteSearchIndexInfo[];
340
+ searchLoading?: boolean;
341
+ };
342
+
343
+ declare interface ReplaceRule {
344
+ search: string | RegExp;
345
+ replace: string;
346
+ }
347
+
348
+ declare interface RouteMeta {
349
+ routePath: string;
350
+ absolutePath: string;
351
+ relativePath: string;
352
+ pageName: string;
353
+ lang: string;
354
+ version: string;
355
+ }
356
+
357
+ declare interface RouteOptions {
358
+ /**
359
+ * The extension name of the filepath that will be converted to a route
360
+ * @default ['js','jsx','ts','tsx','md','mdx']
361
+ */
362
+ extensions?: string[];
363
+ /**
364
+ * Include extra files from being converted to routes
365
+ */
366
+ include?: string[];
367
+ /**
368
+ * Exclude files from being converted to routes
369
+ */
370
+ exclude?: string[];
371
+ /**
372
+ * use links without .html files
373
+ */
374
+ cleanUrls?: boolean;
375
+ }
376
+
377
+ declare interface RspressPlugin {
378
+ /**
379
+ * Name of the plugin.
380
+ */
381
+ name: string;
382
+ /**
383
+ * Global style
384
+ */
385
+ globalStyles?: string;
386
+ /**
387
+ * Markdown options.
388
+ */
389
+ markdown?: {
390
+ remarkPlugins?: PluggableList;
391
+ rehypePlugins?: PluggableList;
392
+ globalComponents?: string[];
393
+ };
394
+ /**
395
+ * Rsbuild config.
396
+ */
397
+ builderConfig?: RsbuildConfig;
398
+ /**
399
+ * Inject global components.
400
+ */
401
+ globalUIComponents?: (string | [string, object])[];
402
+ /**
403
+ * Modify doc config.
404
+ */
405
+ config?: (config: UserConfig, utils: {
406
+ addPlugin: (plugin: RspressPlugin) => void;
407
+ removePlugin: (pluginName: string) => void;
408
+ }, isProd: boolean) => UserConfig | Promise<UserConfig>;
409
+ /**
410
+ * Callback before build
411
+ */
412
+ beforeBuild?: (config: UserConfig, isProd: boolean) => void | Promise<void>;
413
+ /**
414
+ * Callback after build
415
+ */
416
+ afterBuild?: (config: UserConfig, isProd: boolean) => void | Promise<void>;
417
+ /**
418
+ * Extend every page's data
419
+ */
420
+ extendPageData?: (pageData: PageIndexInfo & {
421
+ [key: string]: unknown;
422
+ }, isProd: boolean) => void | Promise<void>;
423
+ /**
424
+ * Add custom route
425
+ */
426
+ addPages?: (config: UserConfig, isProd: boolean) => AdditionalPage[] | Promise<AdditionalPage[]>;
427
+ /**
428
+ * Add runtime modules
429
+ */
430
+ addRuntimeModules?: (config: UserConfig, isProd: boolean) => Record<string, string> | Promise<Record<string, string>>;
431
+ /**
432
+ * Callback after route generated
433
+ */
434
+ routeGenerated?: (routes: RouteMeta[], isProd: boolean) => Promise<void> | void;
435
+ /**
436
+ * Add addition ssg routes, for dynamic routes.
437
+ */
438
+ addSSGRoutes?: (config: UserConfig, isProd: boolean) => {
439
+ path: string;
440
+ }[] | Promise<{
441
+ path: string;
442
+ }[]>;
443
+ /**
444
+ * @private
445
+ * Modify search index data.
446
+ */
447
+ modifySearchIndexData?: (data: PageIndexInfo[], isProd: boolean) => void | Promise<void>;
448
+ }
449
+
450
+ declare interface SearchHooks {
451
+ /**
452
+ * The search hook function path. The corresponding file should export a function named `onSearch`.
453
+ */
454
+ searchHooks?: string;
455
+ }
456
+
457
+ declare type SearchOptions = LocalSearchOptions | RemoteSearchOptions | false;
458
+
459
+ declare interface Sidebar {
460
+ [path: string]: (SidebarGroup | SidebarItem | SidebarDivider | SidebarSectionHeader)[];
461
+ }
462
+
463
+ declare type SidebarDivider = {
464
+ dividerType: 'dashed' | 'solid';
465
+ };
466
+
467
+ declare interface SidebarGroup {
468
+ text: string;
469
+ link?: string;
470
+ tag?: string;
471
+ items: (SidebarItem | SidebarDivider | SidebarGroup | string)[];
472
+ collapsible?: boolean;
473
+ collapsed?: boolean;
474
+ /**
475
+ * For hmr usage in development
476
+ */
477
+ _fileKey?: string;
478
+ overviewHeaders?: number[];
479
+ context?: string;
480
+ }
481
+
482
+ declare type SidebarItem = {
483
+ text: string;
484
+ link: string;
485
+ tag?: string;
486
+ /**
487
+ * For hmr usage in development
488
+ */
489
+ _fileKey?: string;
490
+ overviewHeaders?: number[];
491
+ context?: string;
492
+ };
493
+
494
+ declare type SidebarSectionHeader = {
495
+ sectionHeaderText: string;
496
+ tag?: string;
497
+ };
498
+
499
+ declare interface SocialLink {
500
+ icon: SocialLinkIcon;
501
+ mode: 'link' | 'text' | 'img' | 'dom';
502
+ content: string;
503
+ }
504
+
505
+ declare type SocialLinkIcon = 'lark' | 'discord' | 'facebook' | 'github' | 'instagram' | 'linkedin' | 'slack' | 'x' | 'youtube' | 'wechat' | 'qq' | 'juejin' | 'zhihu' | 'bilibili' | 'weibo' | 'gitlab' | 'X' | 'bluesky' | {
506
+ svg: string;
507
+ };
508
+
509
+ declare type SSGConfig = boolean | {
510
+ strict?: boolean;
511
+ };
512
+
513
+ declare interface UserConfig<ThemeConfig = Config> {
514
+ /**
515
+ * The root directory of the site.
516
+ * @default 'docs'
517
+ */
518
+ root?: string;
519
+ /**
520
+ * Path to the logo file in nav bar.
521
+ */
522
+ logo?: string | {
523
+ dark: string;
524
+ light: string;
525
+ };
526
+ /**
527
+ * The text of the logo in nav bar.
528
+ * @default ''
529
+ */
530
+ logoText?: string;
531
+ /**
532
+ * Base path of the site.
533
+ * @default '/'
534
+ */
535
+ base?: string;
536
+ /**
537
+ * Path to html icon file.
538
+ */
539
+ icon?: string;
540
+ /**
541
+ * Default language of the site.
542
+ */
543
+ lang?: string;
544
+ /**
545
+ * Title of the site.
546
+ * @default 'Rspress'
547
+ */
548
+ title?: string;
549
+ /**
550
+ * Description of the site.
551
+ * @default ''
552
+ */
553
+ description?: string;
554
+ /**
555
+ * Head tags.
556
+ */
557
+ head?: (string | [string, Record<string, string>] | ((route: RouteMeta) => string | [string, Record<string, string>] | undefined))[];
558
+ /**
559
+ * I18n config of the site.
560
+ */
561
+ locales?: Locale[];
562
+ /**
563
+ * The i18n text data source path. Default is `i18n.json` in cwd.
564
+ */
565
+ i18nSourcePath?: string;
566
+ /**
567
+ * Theme config.
568
+ */
569
+ themeConfig?: ThemeConfig;
570
+ /**
571
+ * Rsbuild Configuration
572
+ */
573
+ builderConfig?: RsbuildConfig;
574
+ /**
575
+ * The custom config of vite-plugin-route
576
+ */
577
+ route?: RouteOptions;
578
+ /**
579
+ * The custom config of markdown compile
580
+ */
581
+ markdown?: MarkdownOptions;
582
+ /**
583
+ * Doc plugins
584
+ */
585
+ plugins?: RspressPlugin[];
586
+ /**
587
+ * Replace rule, will replace the content of the page.
588
+ */
589
+ replaceRules?: ReplaceRule[];
590
+ /**
591
+ * Output directory
592
+ */
593
+ outDir?: string;
594
+ /**
595
+ * Custom theme directory
596
+ */
597
+ themeDir?: string;
598
+ /**
599
+ * Global components
600
+ */
601
+ globalUIComponents?: (string | [string, object])[];
602
+ /**
603
+ * Global styles, is a Absolute path
604
+ */
605
+ globalStyles?: string;
606
+ /**
607
+ * Search options
608
+ */
609
+ search?: SearchOptions;
610
+ /**
611
+ * Whether to enable ssg, default is true
612
+ */
613
+ ssg?: SSGConfig;
614
+ /**
615
+ * Whether to enable medium-zoom, default is true
616
+ */
617
+ mediumZoom?: boolean | {
618
+ selector?: string;
619
+ options?: ZoomOptions;
620
+ };
621
+ /**
622
+ * Add some extra builder plugins
623
+ */
624
+ builderPlugins?: RsbuildPlugin[];
625
+ /**
626
+ * Multi version config
627
+ */
628
+ multiVersion?: {
629
+ /**
630
+ * The default version
631
+ */
632
+ default?: string;
633
+ /**
634
+ * The version list, such as ['v1', 'v2']
635
+ */
636
+ versions: string[];
637
+ };
638
+ /**
639
+ * Language parity checking config
640
+ */
641
+ languageParity?: {
642
+ /**
643
+ * Whether to enable language parity checking
644
+ */
645
+ enabled: boolean;
646
+ /**
647
+ * Directories to include in the parity check
648
+ */
649
+ include: string[];
650
+ /**
651
+ * Directories to exclude from the parity check
652
+ */
653
+ exclude: string[];
654
+ };
655
+ }
656
+
657
+ declare interface ZoomContainer {
658
+ width?: number
659
+ height?: number
660
+ top?: number
661
+ bottom?: number
662
+ right?: number
663
+ left?: number
664
+ }
665
+
666
+ declare interface ZoomOptions {
667
+ /**
668
+ * The space outside the zoomed image.
669
+ *
670
+ * @default 0
671
+ */
672
+ margin?: number
673
+
674
+ /**
675
+ * The background of the overlay.
676
+ *
677
+ * @default '#fff'
678
+ */
679
+ background?: string
680
+
681
+ /**
682
+ * The number of pixels to scroll to close the zoom.
683
+ *
684
+ * @default 40
685
+ */
686
+ scrollOffset?: number
687
+
688
+ /**
689
+ * The viewport to render the zoom in.
690
+ *
691
+ * @default null
692
+ */
693
+ container?: string | HTMLElement | ZoomContainer
694
+
695
+ /**
696
+ * The template element to display on zoom.
697
+ *
698
+ * @default null
699
+ */
700
+ template?: string | HTMLTemplateElement
701
+ }
702
+
703
+ export { }