@rspress/plugin-algolia 2.0.0-alpha.1 → 2.0.0-alpha.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.
package/dist/index.d.ts CHANGED
@@ -1,751 +1,10 @@
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 DefaultThemeConfig {
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
- 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
- [key: string]: unknown;
197
- }
198
-
199
- declare interface Header {
200
- id: string;
201
- text: string;
202
- depth: number;
203
- charIndex: number;
204
- }
205
-
206
- declare interface Hero {
207
- name: string;
208
- text: string;
209
- tagline: string;
210
- image?: {
211
- src: string | {
212
- dark: string;
213
- light: string;
214
- };
215
- alt: string;
216
- /**
217
- * `srcset` and `sizes` are attributes of `<img>` tag. Please refer to https://mdn.io/srcset for the usage.
218
- * When the value is an array, rspress will join array members with commas.
219
- **/
220
- sizes?: string | string[];
221
- srcset?: string | string[];
222
- };
223
- actions: {
224
- text: string;
225
- link: string;
226
- theme: 'brand' | 'alt';
227
- }[];
228
- }
229
-
230
- declare interface Locale {
231
- lang: string;
232
- label: string;
233
- title?: string;
234
- description?: string;
235
- }
236
-
237
- /**
238
- * locale config
239
- */
240
- declare interface LocaleConfig {
241
- /**
242
- * Site i18n config, which will recover the locales config in the site level.
243
- */
244
- lang: string;
245
- title?: string;
246
- description?: string;
247
- label: string;
248
- /**
249
- * Theme i18n config
250
- */
251
- nav?: Nav;
252
- sidebar?: Sidebar;
253
- outlineTitle?: string;
254
- lastUpdatedText?: string;
255
- lastUpdated?: boolean;
256
- editLink?: EditLink;
257
- prevPageText?: string;
258
- nextPageText?: string;
259
- sourceCodeText?: string;
260
- langRoutePrefix?: string;
261
- searchPlaceholderText?: string;
262
- searchNoResultsText?: string;
263
- searchSuggestedQueryText?: string;
264
- overview?: FilterConfig;
265
- }
266
-
267
- declare type LocalSearchOptions = SearchHooks & {
268
- mode?: 'local';
269
- /**
270
- * Whether to generate separate search index for each version
271
- */
272
- versioned?: boolean;
273
- /**
274
- * If enabled, the search index will include code block content, which allows users to search code blocks.
275
- * @default false
276
- */
277
- codeBlocks?: boolean;
278
- };
279
-
280
- declare interface MarkdownOptions {
281
- remarkPlugins?: PluggableList;
282
- rehypePlugins?: PluggableList;
283
- /**
284
- * Whether to enable check dead links, default is false
285
- */
286
- checkDeadLinks?: boolean;
287
- showLineNumbers?: boolean;
288
- /**
289
- * Whether to wrap code by default, default is false
290
- */
291
- defaultWrapCode?: boolean;
292
- /**
293
- * Register global components in mdx files
294
- */
295
- globalComponents?: string[];
296
- /**
297
- * Code highlighter, default is prism for performance reason
298
- */
299
- codeHighlighter?: 'prism' | 'shiki';
300
- /**
301
- * Register prism languages
302
- */
303
- highlightLanguages?: (string | [string, string])[];
304
- /**
305
- * Whether to enable mdx-rs, default is true
306
- */
307
- mdxRs?: boolean | MdxRsOptions;
308
- /**
309
- * @deprecated, use `mdxRs` instead
310
- */
311
- experimentalMdxRs?: boolean;
312
- }
313
-
314
- declare interface MdxRsOptions {
315
- /**
316
- * Determine whether the file use mdxRs compiler
317
- */
318
- include?: (filepath: string) => boolean;
319
- }
320
-
321
- declare type Nav = NavItem[] | {
322
- [key: string]: NavItem[];
323
- };
324
-
325
- declare type NavItem = NavItemWithLink | NavItemWithChildren | NavItemWithLinkAndChildren;
326
-
327
- declare interface NavItemWithChildren {
328
- text?: string;
329
- tag?: string;
330
- items: NavItemWithLink[];
331
- position?: 'left' | 'right';
332
- }
333
-
334
- declare type NavItemWithLink = {
335
- text: string;
336
- link: string;
337
- tag?: string;
338
- activeMatch?: string;
339
- position?: 'left' | 'right';
340
- };
341
-
342
- declare interface NavItemWithLinkAndChildren {
343
- text: string;
344
- link: string;
345
- items: NavItemWithLink[];
346
- tag?: string;
347
- activeMatch?: string;
348
- position?: 'left' | 'right';
349
- }
350
-
351
- declare interface Options {
352
- selector?: string;
353
- }
354
-
355
- /**
356
- * @description search-index.json file
357
- * "_foo" is the private field that won't be written to search-index.json file
358
- * and should not be used in the runtime (usePageData).
359
- */
360
- declare interface PageIndexInfo {
361
- id: number;
362
- title: string;
363
- routePath: string;
364
- toc: Header[];
365
- content: string;
366
- _html: string;
367
- frontmatter: FrontMatterMeta;
368
- lang: string;
369
- version: string;
370
- domain: string;
371
- _filepath: string;
372
- _relativePath: string;
373
- }
374
-
375
- declare type PageType = 'home' | 'doc' | 'custom' | '404' | 'blank';
376
-
377
- export declare function pluginAlgolia(options?: Options): RspressPlugin;
378
-
379
- declare type RemoteSearchIndexInfo = string | {
380
- value: string;
381
- label: string;
382
- };
383
-
384
- declare type RemoteSearchOptions = SearchHooks & {
385
- mode: 'remote';
386
- apiUrl: string;
387
- domain?: string;
388
- indexName: string;
389
- searchIndexes?: RemoteSearchIndexInfo[];
390
- searchLoading?: boolean;
391
- };
392
-
393
- declare interface ReplaceRule {
394
- search: string | RegExp;
395
- replace: string;
396
- }
397
-
398
- declare interface RouteMeta {
399
- routePath: string;
400
- absolutePath: string;
401
- relativePath: string;
402
- pageName: string;
403
- lang: string;
404
- version: string;
405
- }
406
-
407
- declare interface RouteOptions {
408
- /**
409
- * The extension name of the filepath that will be converted to a route
410
- * @default ['js','jsx','ts','tsx','md','mdx']
411
- */
412
- extensions?: string[];
413
- /**
414
- * Include extra files from being converted to routes
415
- */
416
- include?: string[];
417
- /**
418
- * Exclude files from being converted to routes
419
- */
420
- exclude?: string[];
421
- /**
422
- * use links without .html files
423
- */
424
- cleanUrls?: boolean;
425
- }
426
-
427
- declare interface RspressPlugin {
428
- /**
429
- * Name of the plugin.
430
- */
431
- name: string;
432
- /**
433
- * Global style
434
- */
435
- globalStyles?: string;
436
- /**
437
- * Markdown options.
438
- */
439
- markdown?: {
440
- remarkPlugins?: PluggableList;
441
- rehypePlugins?: PluggableList;
442
- globalComponents?: string[];
443
- };
444
- /**
445
- * Rsbuild config.
446
- */
447
- builderConfig?: RsbuildConfig;
448
- /**
449
- * Inject global components.
450
- */
451
- globalUIComponents?: (string | [string, object])[];
452
- /**
453
- * Modify doc config.
454
- */
455
- config?: (config: UserConfig, utils: {
456
- addPlugin: (plugin: RspressPlugin) => void;
457
- removePlugin: (pluginName: string) => void;
458
- }, isProd: boolean) => UserConfig | Promise<UserConfig>;
459
- /**
460
- * Callback before build
461
- */
462
- beforeBuild?: (config: UserConfig, isProd: boolean) => void | Promise<void>;
463
- /**
464
- * Callback after build
465
- */
466
- afterBuild?: (config: UserConfig, isProd: boolean) => void | Promise<void>;
467
- /**
468
- * Extend every page's data
469
- */
470
- extendPageData?: (pageData: PageIndexInfo, isProd: boolean) => void | Promise<void>;
471
- /**
472
- * Add custom route
473
- */
474
- addPages?: (config: UserConfig, isProd: boolean) => AdditionalPage[] | Promise<AdditionalPage[]>;
475
- /**
476
- * Add runtime modules
477
- */
478
- addRuntimeModules?: (config: UserConfig, isProd: boolean) => Record<string, string> | Promise<Record<string, string>>;
479
- /**
480
- * Callback after route generated
481
- */
482
- routeGenerated?: (routes: RouteMeta[], isProd: boolean) => Promise<void> | void;
483
- /**
484
- * Add addition ssg routes, for dynamic routes.
485
- */
486
- addSSGRoutes?: (config: UserConfig, isProd: boolean) => {
487
- path: string;
488
- }[] | Promise<{
489
- path: string;
490
- }[]>;
491
- /**
492
- * @private
493
- * Modify search index data.
494
- */
495
- modifySearchIndexData?: (data: PageIndexInfo[], isProd: boolean) => void | Promise<void>;
496
- }
497
-
498
- declare interface SearchHooks {
499
- /**
500
- * The search hook function path. The corresponding file should export a function named `onSearch`.
501
- */
502
- searchHooks?: string;
503
- }
504
-
505
- declare type SearchOptions = LocalSearchOptions | RemoteSearchOptions | false;
506
-
507
- declare interface Sidebar {
508
- [path: string]: (SidebarGroup | SidebarItem | SidebarDivider | SidebarSectionHeader)[];
509
- }
510
-
511
- declare type SidebarDivider = {
512
- dividerType: 'dashed' | 'solid';
513
- };
514
-
515
- declare interface SidebarGroup {
516
- text: string;
517
- link?: string;
518
- tag?: string;
519
- items: (SidebarItem | SidebarDivider | SidebarGroup | string)[];
520
- collapsible?: boolean;
521
- collapsed?: boolean;
522
- /**
523
- * For hmr usage in development
524
- */
525
- _fileKey?: string;
526
- overviewHeaders?: number[];
527
- context?: string;
528
- }
529
-
530
- declare type SidebarItem = {
531
- text: string;
532
- link: string;
533
- tag?: string;
534
- /**
535
- * For hmr usage in development
536
- */
537
- _fileKey?: string;
538
- overviewHeaders?: number[];
539
- context?: string;
540
- };
541
-
542
- declare type SidebarSectionHeader = {
543
- sectionHeaderText: string;
544
- tag?: string;
545
- };
546
-
547
- declare interface SocialLink {
548
- icon: SocialLinkIcon;
549
- mode: 'link' | 'text' | 'img' | 'dom';
550
- content: string;
551
- }
552
-
553
- declare type SocialLinkIcon = 'lark' | 'discord' | 'facebook' | 'github' | 'instagram' | 'linkedin' | 'slack' | 'x' | 'youtube' | 'wechat' | 'qq' | 'juejin' | 'zhihu' | 'bilibili' | 'weibo' | 'gitlab' | 'X' | 'bluesky' | {
554
- svg: string;
555
- };
556
-
557
- declare type SSGConfig = boolean | {
558
- strict?: boolean;
559
- };
560
-
561
- declare interface UserConfig<ThemeConfig = DefaultThemeConfig> {
562
- /**
563
- * The root directory of the site.
564
- * @default 'docs'
565
- */
566
- root?: string;
567
- /**
568
- * Path to the logo file in nav bar.
569
- */
570
- logo?: string | {
571
- dark: string;
572
- light: string;
573
- };
574
- /**
575
- * The text of the logo in nav bar.
576
- * @default ''
577
- */
578
- logoText?: string;
579
- /**
580
- * Base path of the site.
581
- * @default '/'
582
- */
583
- base?: string;
584
- /**
585
- * Path to html icon file.
586
- */
587
- icon?: string;
588
- /**
589
- * Default language of the site.
590
- */
591
- lang?: string;
592
- /**
593
- * Title of the site.
594
- * @default 'Rspress'
595
- */
596
- title?: string;
597
- /**
598
- * Description of the site.
599
- * @default ''
600
- */
601
- description?: string;
602
- /**
603
- * Head tags.
604
- */
605
- head?: (string | [string, Record<string, string>] | ((route: RouteMeta) => string | [string, Record<string, string>] | undefined))[];
606
- /**
607
- * I18n config of the site.
608
- */
609
- locales?: Locale[];
610
- /**
611
- * The i18n text data source path. Default is `i18n.json` in cwd.
612
- */
613
- i18nSourcePath?: string;
614
- /**
615
- * Theme config.
616
- */
617
- themeConfig?: ThemeConfig;
618
- /**
619
- * Rsbuild Configuration
620
- */
621
- builderConfig?: RsbuildConfig;
622
- /**
623
- * The custom config of vite-plugin-route
624
- */
625
- route?: RouteOptions;
626
- /**
627
- * The custom config of markdown compile
628
- */
629
- markdown?: MarkdownOptions;
630
- /**
631
- * Doc plugins
632
- */
633
- plugins?: RspressPlugin[];
634
- /**
635
- * Replace rule, will replace the content of the page.
636
- */
637
- replaceRules?: ReplaceRule[];
638
- /**
639
- * Output directory
640
- */
641
- outDir?: string;
642
- /**
643
- * Custom theme directory
644
- */
645
- themeDir?: string;
646
- /**
647
- * Global components
648
- */
649
- globalUIComponents?: (string | [string, object])[];
650
- /**
651
- * Global styles, is a Absolute path
652
- */
653
- globalStyles?: string;
654
- /**
655
- * Search options
656
- */
657
- search?: SearchOptions;
658
- /**
659
- * Whether to enable ssg, default is true
660
- */
661
- ssg?: SSGConfig;
662
- /**
663
- * Whether to enable medium-zoom, default is true
664
- */
665
- mediumZoom?: boolean | {
666
- selector?: string;
667
- options?: ZoomOptions;
668
- };
669
- /**
670
- * Add some extra builder plugins
671
- */
672
- builderPlugins?: RsbuildPlugin[];
673
- /**
674
- * Multi version config
675
- */
676
- multiVersion?: {
677
- /**
678
- * The default version
679
- */
680
- default?: string;
681
- /**
682
- * The version list, such as ['v1', 'v2']
683
- */
684
- versions: string[];
685
- };
686
- /**
687
- * Language parity checking config
688
- */
689
- languageParity?: {
690
- /**
691
- * Whether to enable language parity checking
692
- */
693
- enabled?: boolean;
694
- /**
695
- * Directories to include in the parity check
696
- */
697
- include?: string[];
698
- /**
699
- * Directories to exclude from the parity check
700
- */
701
- exclude?: string[];
702
- };
703
- }
704
-
705
- declare interface ZoomContainer {
706
- width?: number
707
- height?: number
708
- top?: number
709
- bottom?: number
710
- right?: number
711
- left?: number
712
- }
713
-
714
- declare interface ZoomOptions {
715
- /**
716
- * The space outside the zoomed image.
717
- *
718
- * @default 0
719
- */
720
- margin?: number
721
-
722
- /**
723
- * The background of the overlay.
724
- *
725
- * @default '#fff'
726
- */
727
- background?: string
728
-
729
- /**
730
- * The number of pixels to scroll to close the zoom.
731
- *
732
- * @default 40
733
- */
734
- scrollOffset?: number
735
-
736
- /**
737
- * The viewport to render the zoom in.
738
- *
739
- * @default null
740
- */
741
- container?: string | HTMLElement | ZoomContainer
742
-
743
- /**
744
- * The template element to display on zoom.
745
- *
746
- * @default null
747
- */
748
- template?: string | HTMLTemplateElement
749
- }
750
-
751
- export { }
1
+ import type { RspressPlugin } from '@rspress/shared';
2
+ interface Options {
3
+ /**
4
+ * Algolia meta tag for verification
5
+ * - <meta name="algolia-site-verification" content="YOUR_VERIFICATION_CONTENT" />
6
+ */
7
+ verificationContent?: string;
8
+ }
9
+ export declare function pluginAlgolia(options?: Options): RspressPlugin;
10
+ export {};
package/dist/index.js CHANGED
@@ -1,14 +1,19 @@
1
1
  function pluginAlgolia(options = {}) {
2
+ const { verificationContent } = options;
2
3
  return {
3
4
  name: '@rspress/plugin-algolia',
5
+ config (config) {
6
+ config.search = false;
7
+ return config;
8
+ },
4
9
  builderConfig: {
5
10
  html: {
6
- meta: {
11
+ meta: verificationContent ? {
7
12
  'algolia-site-verification': {
8
13
  name: 'algolia-site-verification',
9
- content: '0F854AB11EB1D255'
14
+ content: verificationContent
10
15
  }
11
- }
16
+ } : {}
12
17
  }
13
18
  }
14
19
  };
@@ -0,0 +1,14 @@
1
+ .DocSearch {
2
+ --docsearch-searchbox-background: var(--rp-c-bg-mute);
3
+ align-self: center;
4
+ }
5
+
6
+ .DocSearch-Button-Container > .DocSearch-Button-Placeholder, span.DocSearch-Button-Keys > kbd {
7
+ font-size: .825rem;
8
+ }
9
+
10
+ .DocSearch-Screen-Icon {
11
+ justify-content: center;
12
+ display: flex;
13
+ }
14
+
@@ -0,0 +1,14 @@
1
+ import type { DocSearchProps } from '@docsearch/react';
2
+ import '@docsearch/css';
3
+ import './Search.css';
4
+ import type { Locales } from './locales';
5
+ type SearchProps = {
6
+ /**
7
+ * @link https://docsearch.algolia.com/docs/api
8
+ */
9
+ docSearchProps: DocSearchProps;
10
+ locales?: Locales;
11
+ };
12
+ declare function Search({ locales, docSearchProps }: SearchProps): import("react/jsx-runtime").JSX.Element;
13
+ export { Search };
14
+ export type { SearchProps };
@@ -0,0 +1,52 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
2
+ import * as __WEBPACK_EXTERNAL_MODULE__docsearch_react_bddc4633__ from "@docsearch/react";
3
+ import * as __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__ from "@rspress/runtime";
4
+ import * as __WEBPACK_EXTERNAL_MODULE__theme_75e53063__ from "@theme";
5
+ import "@docsearch/css";
6
+ import "./Search.css";
7
+ import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
8
+ const Hit = ({ hit, children })=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__theme_75e53063__.Link, {
9
+ href: hit.url,
10
+ children: children
11
+ });
12
+ function Search({ locales = {}, docSearchProps }) {
13
+ const navigate = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.useNavigate)();
14
+ const lang = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.useLang)();
15
+ const { translations, placeholder } = locales?.[lang] ?? {};
16
+ (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
17
+ const preconnect = document.createElement('link');
18
+ const appId = docSearchProps.appId;
19
+ preconnect.id = appId;
20
+ preconnect.rel = 'preconnect';
21
+ preconnect.href = `https://${appId}-dsn.algolia.net`;
22
+ preconnect.crossOrigin = '';
23
+ document.head.appendChild(preconnect);
24
+ return ()=>{
25
+ document.head.removeChild(preconnect);
26
+ };
27
+ }, [
28
+ docSearchProps.appId
29
+ ]);
30
+ return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.Fragment, {
31
+ children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__docsearch_react_bddc4633__.DocSearch, {
32
+ placeholder: placeholder,
33
+ translations: translations,
34
+ maxResultsPerGroup: 20,
35
+ navigator: {
36
+ navigate ({ itemUrl }) {
37
+ navigate(itemUrl);
38
+ }
39
+ },
40
+ transformItems: (items)=>items.map((item)=>{
41
+ const url = new URL(item.url);
42
+ return {
43
+ ...item,
44
+ url: item.url.replace(url.origin, '')
45
+ };
46
+ }),
47
+ hitComponent: Hit,
48
+ ...docSearchProps
49
+ })
50
+ });
51
+ }
52
+ export { Search };
@@ -0,0 +1,2 @@
1
+ export { Search, type SearchProps } from './Search';
2
+ export { type Locales, ZH_LOCALES } from './locales';
@@ -0,0 +1,5 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE__Search_js_267571c1__ from "./Search.js";
2
+ import * as __WEBPACK_EXTERNAL_MODULE__locales_js_0c471cb7__ from "./locales.js";
3
+ var __webpack_exports__Search = __WEBPACK_EXTERNAL_MODULE__Search_js_267571c1__.Search;
4
+ var __webpack_exports__ZH_LOCALES = __WEBPACK_EXTERNAL_MODULE__locales_js_0c471cb7__.ZH_LOCALES;
5
+ export { __webpack_exports__Search as Search, __webpack_exports__ZH_LOCALES as ZH_LOCALES };
@@ -0,0 +1,6 @@
1
+ import type { DocSearchProps } from '@docsearch/react';
2
+ export type Locales = Record<string, {
3
+ translations: DocSearchProps['translations'];
4
+ placeholder: string;
5
+ }>;
6
+ export declare const ZH_LOCALES: Locales;
@@ -0,0 +1,44 @@
1
+ const ZH_LOCALES = {
2
+ zh: {
3
+ placeholder: '搜索文档',
4
+ translations: {
5
+ button: {
6
+ buttonText: '搜索',
7
+ buttonAriaLabel: '搜索'
8
+ },
9
+ modal: {
10
+ searchBox: {
11
+ resetButtonTitle: '清除查询条件',
12
+ resetButtonAriaLabel: '清除查询条件',
13
+ cancelButtonText: '取消',
14
+ cancelButtonAriaLabel: '取消'
15
+ },
16
+ startScreen: {
17
+ recentSearchesTitle: '搜索历史',
18
+ noRecentSearchesText: '没有搜索历史',
19
+ saveRecentSearchButtonTitle: '保存至搜索历史',
20
+ removeRecentSearchButtonTitle: '从搜索历史中移除',
21
+ favoriteSearchesTitle: '收藏',
22
+ removeFavoriteSearchButtonTitle: '从收藏中移除'
23
+ },
24
+ errorScreen: {
25
+ titleText: '无法获取结果',
26
+ helpText: '你可能需要检查你的网络连接'
27
+ },
28
+ footer: {
29
+ selectText: '选择',
30
+ navigateText: '切换',
31
+ closeText: '关闭',
32
+ searchByText: '搜索提供者'
33
+ },
34
+ noResultsScreen: {
35
+ noResultsText: '无法找到相关结果',
36
+ suggestedQueryText: '你可以尝试查询',
37
+ reportMissingResultsText: '你认为该查询应该有结果?',
38
+ reportMissingResultsLinkText: '点击反馈'
39
+ }
40
+ }
41
+ }
42
+ }
43
+ };
44
+ export { ZH_LOCALES };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/plugin-algolia",
3
- "version": "2.0.0-alpha.1",
3
+ "version": "2.0.0-alpha.2",
4
4
  "description": "A plugin for rspress to search with algolia in docs.",
5
5
  "bugs": "https://github.com/web-infra-dev/rspress/issues",
6
6
  "repository": {
@@ -16,6 +16,16 @@
16
16
  "*.scss"
17
17
  ],
18
18
  "type": "module",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "default": "./dist/index.js"
23
+ },
24
+ "./runtime": {
25
+ "types": "./dist/runtime/index.d.ts",
26
+ "default": "./dist/runtime/index.js"
27
+ }
28
+ },
19
29
  "main": "./dist/index.js",
20
30
  "module": "./dist/index.js",
21
31
  "types": "./dist/index.d.ts",
@@ -23,19 +33,28 @@
23
33
  "dist",
24
34
  "static"
25
35
  ],
36
+ "dependencies": {
37
+ "@docsearch/css": "^3.9.0",
38
+ "@docsearch/react": "^3.9.0",
39
+ "algoliasearch": "^5.20.3",
40
+ "instantsearch.css": "^8.5.1",
41
+ "instantsearch.js": "^4.77.3",
42
+ "react-instantsearch": "^7.15.3"
43
+ },
26
44
  "devDependencies": {
27
45
  "@microsoft/api-extractor": "^7.51.1",
46
+ "@rsbuild/plugin-react": "~1.1.1",
28
47
  "@rslib/core": "0.5.3",
29
48
  "@types/node": "^18.11.17",
30
49
  "@types/react": "^18.3.18",
31
50
  "@types/react-dom": "^18.3.5",
32
51
  "react": "^18.3.1",
33
52
  "typescript": "^5.5.3",
34
- "@rspress/config": "1.0.0",
35
- "@rspress/shared": "2.0.0-alpha.1"
53
+ "@rspress/shared": "2.0.0-alpha.2",
54
+ "@rspress/config": "1.0.0"
36
55
  },
37
56
  "peerDependencies": {
38
- "@rspress/runtime": "^2.0.0-alpha.1"
57
+ "@rspress/runtime": "^2.0.0-alpha.2"
39
58
  },
40
59
  "engines": {
41
60
  "node": ">=14.17.6"