@rspress/plugin-algolia
Based on docsearch, this plugin replaces Rspress's built-in search with algolia.
Installation
Usage
First, add the following configuration to rspress.config.ts:
Then override the Search component with an algolia-supported search box via Custom Theme.
Configuration
The plugin accepts an options object with the following type:
verificationContent
- Type:
string | undefined - Default:
undefined
Used for meta tag verification when creating algolia crawler. Format: <meta name="algolia-site-verification" content="YOUR_VERIFICATION_CONTENT" />. Refer to Create a new crawler - algolia
SearchProps
The SearchProps type from @rspress/plugin-algolia/runtime is as follows:
docSearchProps
- Type:
import('@docsearch/react').DocSearchProps - Default:
undefined
docSearchProps will be directly passed to the <DocSearch /> component in @docsearch/react. For specific types, please refer to docsearch documentation.
locales
- Type:
- Default:
{}
For customizing translated text in different languages, Rspress provides the following translated text, which can be imported through import.
Rspress provides Chinese translation by default, and you can customize translated text in different languages through locales.
- Example:
Algolia crawler config
Here is an example config based on what this site uses:
Distinguish search results based on i18n
You can achieve internationalized search results by combining Runtime API with docSearchProps.
Here's an example using docSearchProps.searchParameters: