@rspress/shared 0.0.0-next-20230815050107

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Rspress
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # @rspress/shared
@@ -0,0 +1,576 @@
1
+ import { BuilderConfig } from '@modern-js/builder-rspack-provider';
2
+ import { PluggableList } from 'unified';
3
+ import { BuilderPlugin } from '@modern-js/builder';
4
+
5
+ interface Config$1 {
6
+ /**
7
+ * Whether to enable dark mode.
8
+ * @default true
9
+ */
10
+ darkMode?: boolean;
11
+ /**
12
+ * Custom outline title in the aside component.
13
+ *
14
+ * @default 'On this page'
15
+ */
16
+ outlineTitle?: string;
17
+ /**
18
+ * Whether to show the sidebar in right position.
19
+ */
20
+ outline?: boolean;
21
+ /**
22
+ * The nav items.
23
+ */
24
+ nav?: NavItem[];
25
+ /**
26
+ * The sidebar items.
27
+ */
28
+ sidebar?: Sidebar;
29
+ /**
30
+ * Info for the edit link. If it's undefined, the edit link feature will
31
+ * be disabled.
32
+ */
33
+ editLink?: EditLink;
34
+ /**
35
+ * Set custom last updated text.
36
+ *
37
+ * @default 'Last updated'
38
+ */
39
+ lastUpdatedText?: string;
40
+ /**
41
+ * Set custom last updated text.
42
+ *
43
+ * @default false
44
+ */
45
+ lastUpdated?: boolean;
46
+ /**
47
+ * Set custom prev/next labels.
48
+ */
49
+ docFooter?: DocFooter;
50
+ /**
51
+ * The social links to be displayed at the end of the nav bar. Perfect for
52
+ * placing links to social services such as GitHub, Twitter, Facebook, etc.
53
+ */
54
+ socialLinks?: SocialLink[];
55
+ /**
56
+ * The footer configuration.
57
+ */
58
+ footer?: Footer;
59
+ /**
60
+ * The prev page text.
61
+ */
62
+ prevPageText?: string;
63
+ /**
64
+ * The next page text.
65
+ */
66
+ nextPageText?: string;
67
+ /**
68
+ * Locale config
69
+ */
70
+ locales?: LocaleConfig[];
71
+ /**
72
+ * Whether to open the full text search
73
+ */
74
+ search?: boolean;
75
+ /**
76
+ * Whether to use back top
77
+ */
78
+ backTop?: boolean;
79
+ /**
80
+ * Whether to hide the navbar
81
+ */
82
+ hideNavbar?: boolean;
83
+ }
84
+ /**
85
+ * locale config
86
+ */
87
+ interface LocaleConfig {
88
+ /**
89
+ * Site i18n config, which will recover the locales config in the site level.
90
+ */
91
+ lang: string;
92
+ title?: string;
93
+ description?: string;
94
+ label: string;
95
+ /**
96
+ * Theme i18n config
97
+ */
98
+ nav?: NavItem[];
99
+ sidebar?: Sidebar;
100
+ outlineTitle?: string;
101
+ lastUpdatedText?: string;
102
+ lastUpdated?: boolean;
103
+ editLink?: EditLink;
104
+ prevPageText?: string;
105
+ nextPageText?: string;
106
+ langRoutePrefix?: string;
107
+ }
108
+ type NavItem = NavItemWithLink | NavItemWithChildren;
109
+ type NavItemWithLink = {
110
+ text: string;
111
+ link: string;
112
+ tag?: string;
113
+ activeMatch?: string;
114
+ position?: 'left' | 'right';
115
+ };
116
+ interface NavItemWithChildren {
117
+ text?: string;
118
+ tag?: string;
119
+ items: (NavItemWithChildren | NavItemWithLink)[];
120
+ position?: 'left' | 'right';
121
+ }
122
+ type Image = string | {
123
+ src: string;
124
+ alt?: string;
125
+ };
126
+ interface Sidebar {
127
+ [path: string]: (SidebarGroup | SidebarItem)[];
128
+ }
129
+ interface SidebarGroup {
130
+ text: string;
131
+ link?: string;
132
+ tag?: string;
133
+ items: (SidebarItem | SidebarGroup | string)[];
134
+ collapsible?: boolean;
135
+ collapsed?: boolean;
136
+ }
137
+ type SidebarItem = {
138
+ text: string;
139
+ link: string;
140
+ tag?: string;
141
+ };
142
+ interface EditLink {
143
+ /**
144
+ * Custom repository url for edit link.
145
+ */
146
+ docRepoBaseUrl: string;
147
+ /**
148
+ * Custom text for edit link.
149
+ *
150
+ * @default 'Edit this page'
151
+ */
152
+ text?: string;
153
+ }
154
+ interface DocFooter {
155
+ /**
156
+ * Custom label for previous page button.
157
+ */
158
+ prev?: SidebarItem;
159
+ /**
160
+ * Custom label for next page button.
161
+ */
162
+ next?: SidebarItem;
163
+ }
164
+ interface SocialLink {
165
+ icon: SocialLinkIcon;
166
+ mode: 'link' | 'text' | 'img';
167
+ content: string;
168
+ }
169
+ type SocialLinkIcon = 'lark' | 'discord' | 'facebook' | 'github' | 'instagram' | 'linkedin' | 'slack' | 'twitter' | 'youtube' | 'weixin' | 'qq' | 'juejin' | 'zhihu' | 'bilibili' | 'weibo' | 'gitlab' | {
170
+ svg: string;
171
+ };
172
+ interface Footer {
173
+ message?: string;
174
+ }
175
+ interface LocaleLinks {
176
+ text: string;
177
+ items: LocaleLink[];
178
+ }
179
+ interface LocaleLink {
180
+ text: string;
181
+ link: string;
182
+ }
183
+ interface NormalizedSidebarGroup extends Omit<SidebarGroup, 'items'> {
184
+ items: (SidebarItem | NormalizedSidebarGroup)[];
185
+ collapsible: boolean;
186
+ collapsed: boolean;
187
+ }
188
+ interface NormalizedSidebar {
189
+ [path: string]: (NormalizedSidebarGroup | SidebarItem)[];
190
+ }
191
+ interface NormalizedLocales extends Omit<LocaleConfig, 'sidebar'> {
192
+ sidebar: NormalizedSidebar;
193
+ }
194
+ interface NormalizedConfig extends Omit<Config$1, 'locales' | 'sidebar'> {
195
+ locales: NormalizedLocales[];
196
+ sidebar: NormalizedSidebar;
197
+ }
198
+
199
+ /**
200
+ * There are two ways to define what addtion routes represent.
201
+ * 1. Define filepath, then the content will be read from the file.
202
+ * 2. Define content, then then content will be written to temp file and read from it.
203
+ */
204
+ interface AdditionalPage {
205
+ routePath: string;
206
+ content?: string;
207
+ filepath?: string;
208
+ }
209
+ interface RspressPlugin {
210
+ /**
211
+ * Name of the plugin.
212
+ */
213
+ name: string;
214
+ /**
215
+ * Global style
216
+ */
217
+ globalStyles?: string;
218
+ /**
219
+ * Markdown options.
220
+ */
221
+ markdown?: {
222
+ remarkPlugins?: PluggableList;
223
+ rehypePlugins?: PluggableList;
224
+ globalComponents?: string[];
225
+ };
226
+ /**
227
+ * Builder config.
228
+ */
229
+ builderConfig?: BuilderConfig;
230
+ /**
231
+ * Inject global components.
232
+ */
233
+ globalUIComponents?: string[];
234
+ /**
235
+ * Modify doc config.
236
+ */
237
+ config?: (config: UserConfig) => UserConfig | Promise<UserConfig>;
238
+ /**
239
+ * Callback before build
240
+ */
241
+ beforeBuild?: (config: UserConfig, isProd: boolean) => Promise<void>;
242
+ /**
243
+ * Callback after build
244
+ */
245
+ afterBuild?: (config: UserConfig, isProd: boolean) => Promise<void>;
246
+ /**
247
+ * Extend every page's data
248
+ */
249
+ extendPageData?: (pageData: PageIndexInfo & {
250
+ [key: string]: unknown;
251
+ }) => void | Promise<void>;
252
+ /**
253
+ * Add custom route
254
+ */
255
+ addPages?: (config: UserConfig, isProd: boolean) => AdditionalPage[] | Promise<AdditionalPage[]>;
256
+ /**
257
+ * Callback after route generated
258
+ */
259
+ routeGenerated?: (routes: RouteMeta[]) => Promise<void> | void;
260
+ /**
261
+ * Add addition ssg routes, for dynamic routes.
262
+ */
263
+ addSSGRoutes?: (config: UserConfig, isProd: boolean) => {
264
+ path: string;
265
+ }[] | Promise<{
266
+ path: string;
267
+ }[]>;
268
+ /**
269
+ * @private
270
+ * Modify search index data.
271
+ */
272
+ modifySearchIndexData?: (data: PageIndexInfo[]) => void | Promise<void>;
273
+ }
274
+
275
+ interface Route {
276
+ path: string;
277
+ element: React.ReactElement;
278
+ filePath: string;
279
+ preload: () => Promise<PageModule<React.ComponentType<unknown>>>;
280
+ lang: string;
281
+ }
282
+ interface RouteMeta {
283
+ routePath: string;
284
+ absolutePath: string;
285
+ relativePath: string;
286
+ pageName: string;
287
+ lang: string;
288
+ }
289
+ interface ReplaceRule {
290
+ search: string | RegExp;
291
+ replace: string;
292
+ }
293
+ interface Header {
294
+ id: string;
295
+ text: string;
296
+ depth: number;
297
+ charIndex: number;
298
+ }
299
+ interface Locale {
300
+ lang: string;
301
+ label: string;
302
+ title?: string;
303
+ description?: string;
304
+ }
305
+ interface UserConfig<ThemeConfig = Config$1> {
306
+ /**
307
+ * The root directory of the site.
308
+ */
309
+ root?: string;
310
+ /**
311
+ * Path to the logo file in nav bar.
312
+ */
313
+ logo?: string | {
314
+ dark: string;
315
+ light: string;
316
+ };
317
+ /**
318
+ * Base path of the site.
319
+ */
320
+ base?: string;
321
+ /**
322
+ * Path to html icon file.
323
+ */
324
+ icon?: string;
325
+ /**
326
+ * Language of the site.
327
+ */
328
+ lang?: string;
329
+ /**
330
+ * Title of the site.
331
+ */
332
+ title?: string;
333
+ /**
334
+ * Description of the site.
335
+ */
336
+ description?: string;
337
+ /**
338
+ * Head tags.
339
+ */
340
+ head?: string[];
341
+ /**
342
+ * I18n config of the site.
343
+ */
344
+ locales?: Locale[];
345
+ /**
346
+ * The i18n text data source path. Default is `i18n.json` in cwd.
347
+ */
348
+ i18nSourcePath?: string;
349
+ /**
350
+ * Theme config.
351
+ */
352
+ themeConfig?: ThemeConfig;
353
+ /**
354
+ * Builder Configuration
355
+ */
356
+ builderConfig?: BuilderConfig;
357
+ /**
358
+ * The custom config of vite-plugin-route
359
+ */
360
+ route?: RouteOptions;
361
+ /**
362
+ * The custom config of markdown compile
363
+ */
364
+ markdown?: MarkdownOptions;
365
+ /**
366
+ * Doc plugins
367
+ */
368
+ plugins?: RspressPlugin[];
369
+ /**
370
+ * Replace rule, will replace the content of the page.
371
+ */
372
+ replaceRules?: ReplaceRule[];
373
+ /**
374
+ * Output directory
375
+ */
376
+ outDir?: string;
377
+ /**
378
+ * Custom theme directory
379
+ */
380
+ themeDir?: string;
381
+ /**
382
+ * Global components
383
+ */
384
+ globalUIComponents?: string[];
385
+ /**
386
+ * Global styles, is a Absolute path
387
+ */
388
+ globalStyles?: string;
389
+ /**
390
+ * Search options
391
+ */
392
+ search?: SearchOptions;
393
+ /**
394
+ * Whether to enable medium-zoom, default is true
395
+ */
396
+ mediumZoom?: boolean | {
397
+ selector?: string;
398
+ };
399
+ /**
400
+ * Add some extra builder plugins
401
+ */
402
+ builderPlugins?: BuilderPlugin[];
403
+ }
404
+ type BaseRuntimePageInfo = Omit<PageIndexInfo, 'id' | 'content' | 'domain'>;
405
+ interface SiteData<ThemeConfig = NormalizedConfig> {
406
+ root: string;
407
+ base: string;
408
+ lang: string;
409
+ title: string;
410
+ description: string;
411
+ icon: string;
412
+ themeConfig: ThemeConfig;
413
+ logo: string | {
414
+ dark: string;
415
+ light: string;
416
+ };
417
+ pages: BaseRuntimePageInfo[];
418
+ search: SearchOptions;
419
+ markdown: {
420
+ showLineNumbers: boolean;
421
+ };
422
+ }
423
+ type PageIndexInfo = {
424
+ id: number;
425
+ title: string;
426
+ routePath: string;
427
+ toc: Header[];
428
+ content: string;
429
+ frontmatter: Record<string, unknown>;
430
+ lang: string;
431
+ domain: string;
432
+ _filepath: string;
433
+ _relativePath: string;
434
+ };
435
+ type RemotePageInfo = PageIndexInfo & {
436
+ _matchesPosition: {
437
+ content: {
438
+ start: number;
439
+ length: number;
440
+ }[];
441
+ };
442
+ };
443
+ interface Hero {
444
+ name: string;
445
+ text: string;
446
+ tagline: string;
447
+ image?: {
448
+ src: string;
449
+ alt: string;
450
+ };
451
+ actions: {
452
+ text: string;
453
+ link: string;
454
+ theme: 'brand' | 'alt';
455
+ }[];
456
+ }
457
+ interface Feature {
458
+ icon: string;
459
+ title: string;
460
+ details: string;
461
+ link?: string;
462
+ }
463
+ interface PageModule<T extends React.ComponentType<unknown>> {
464
+ default: T;
465
+ frontmatter?: FrontMatterMeta;
466
+ content?: string;
467
+ [key: string]: unknown;
468
+ }
469
+ type PageType = 'home' | 'doc' | 'custom' | '404' | 'blank';
470
+ interface FrontMatterMeta {
471
+ title?: string;
472
+ description?: string;
473
+ overview?: boolean;
474
+ pageType?: PageType;
475
+ features?: Feature[];
476
+ hero?: Hero;
477
+ sidebar?: boolean;
478
+ outline?: boolean;
479
+ lineNumbers?: boolean;
480
+ }
481
+ interface PageData {
482
+ siteData: SiteData<Config$1>;
483
+ page: BaseRuntimePageInfo & {
484
+ pagePath: string;
485
+ lastUpdatedTime?: string;
486
+ description?: string;
487
+ pageType: PageType;
488
+ _relativePath: string;
489
+ };
490
+ }
491
+ interface RouteOptions {
492
+ /**
493
+ * The directory to search for pages
494
+ */
495
+ root?: string;
496
+ /**
497
+ * The basename of the site
498
+ */
499
+ prefix?: string;
500
+ /**
501
+ * The extension name of the filepath that will be converted to a route
502
+ * @default ['js','jsx','ts','tsx','md','mdx']
503
+ */
504
+ extensions?: string[];
505
+ /**
506
+ * Include extra files from being converted to routes
507
+ */
508
+ include?: string[];
509
+ /**
510
+ * Exclude files from being converted to routes
511
+ */
512
+ exclude?: string[];
513
+ }
514
+ interface SearchHooks {
515
+ /**
516
+ * The search hook function path. The corresponding file should export a function named `onSearch`.
517
+ */
518
+ searchHooks?: string;
519
+ }
520
+ type LocalSearchOptions = SearchHooks & {
521
+ mode: 'local';
522
+ };
523
+ type RemoteSearchIndexInfo = string | {
524
+ value: string;
525
+ label: string;
526
+ };
527
+ type RemoteSearchOptions = SearchHooks & {
528
+ mode: 'remote';
529
+ apiUrl: string;
530
+ domain?: string;
531
+ indexName: string;
532
+ searchIndexes?: RemoteSearchIndexInfo[];
533
+ };
534
+ type SearchOptions = LocalSearchOptions | RemoteSearchOptions | false;
535
+ interface MarkdownOptions {
536
+ remarkPlugins?: PluggableList;
537
+ rehypePlugins?: PluggableList;
538
+ checkDeadLinks?: boolean;
539
+ experimentalMdxRs?: boolean;
540
+ showLineNumbers?: boolean;
541
+ globalComponents?: string[];
542
+ }
543
+ type Config = UserConfig | Promise<UserConfig> | ((env: any) => UserConfig | Promise<UserConfig>);
544
+
545
+ declare const QUERY_REGEXP: RegExp;
546
+ declare const HASH_REGEXP: RegExp;
547
+ declare const MDX_REGEXP: RegExp;
548
+ declare const APPEARANCE_KEY = "modern-theme-appearance";
549
+ declare const SEARCH_INDEX_NAME = "search_index";
550
+ declare const isSCM: () => boolean;
551
+ declare const isProduction: () => boolean;
552
+ declare const isDebugMode: () => boolean;
553
+ declare const cleanUrl: (url: string) => string;
554
+ declare const inBrowser: () => boolean;
555
+ declare function addLeadingSlash(url: string): string;
556
+ declare function removeLeadingSlash(url: string): string;
557
+ declare function removeTrailingSlash(url: string): string;
558
+ declare function normalizeSlash(url: string): string;
559
+ declare function isExternalUrl(url: string): boolean;
560
+ declare function replaceLang(rawUrl: string, targetLang: string, defaultLang: string, langs: string[], base?: string): string;
561
+ declare const omit: (obj: Record<string, unknown>, keys: string[]) => {
562
+ [x: string]: unknown;
563
+ };
564
+ declare const parseUrl: (url: string) => {
565
+ url: string;
566
+ hash: string;
567
+ };
568
+ declare function normalizeHref(url?: string): string;
569
+ declare function withoutLang(path: string, langs: string[]): string;
570
+ declare function withoutBase(path: string, base?: string): string;
571
+ declare function withBase(url?: string, base?: string): string;
572
+ declare function removeBase(url: string, base: string): string;
573
+ declare function withoutHash(url: string): string;
574
+ declare const mergeDocConfig: (...configs: UserConfig[]) => UserConfig;
575
+
576
+ 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, NormalizedConfig, NormalizedConfig as NormalizedDefaultThemeConfig, NormalizedLocales, NormalizedSidebar, NormalizedSidebarGroup, PageData, PageIndexInfo, PageModule, PageType, QUERY_REGEXP, 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, normalizeSlash, omit, parseUrl, removeBase, removeLeadingSlash, removeTrailingSlash, replaceLang, withBase, withoutBase, withoutHash, withoutLang };