Search
Sveltepress default theme supports three ways to add search to your site:
- Algolia DocSearch — via the built-in
docsearchoption - Meilisearch — via
@sveltepress/meilisearchand thesearchoption - Custom search — pass any Svelte component or a module path string to the
searchoption
Algolia DocSearch
Pass a docsearch config object to defaultTheme to enable Algolia DocSearch in the navbar.
Required fields are appId, apiKey, and indexName. Every other DocSearch option is also accepted.
import { } from '@sveltepress/theme-default'
import { } from '@sveltepress/vite'
import { } from 'vite'
export default ({
: [
({
: ({
: {
: 'YOUR_APP_ID',
: 'YOUR_SEARCH_API_KEY',
: 'YOUR_INDEX_NAME',
},
}),
}),
],
}) DocSearch is free for open-source documentation sites. Apply at docsearch.algolia.com .
Meilisearch
Meilisearch is an open-source, self-hosted search engine. Use the @sveltepress/meilisearch package together with the search option to add it to your site.
Installation
npm install --save @sveltepress/meilisearch Configuration
Pass the path to the Search.svelte component exported by @sveltepress/meilisearch to the search option:
import { } from '@sveltepress/theme-default'
import { } from '@sveltepress/vite'
import { } from 'vite'
export default ({
: [
({
: ({
: '@sveltepress/meilisearch/Search.svelte',
}),
}),
],
}) The Search.svelte component accepts the following props. You can pass them by creating a thin wrapper component around the imported Search.svelte and providing them as props.
| Prop | Type | Required | Description |
|---|---|---|---|
host | string | ✅ | URL of your Meilisearch instance |
apiKey | string | ✅ | Search-only API key |
indexName | string | ✅ | Index name to search |
placeholder | string | — | Placeholder text for the search input (default: 'Search...') |
limit | number | — | Maximum number of results to show (default: 10) |
You can host Meilisearch yourself or use Meilisearch Cloud . The host URL points to whichever deployment you choose.
Custom Search
The search option also accepts a Svelte Component directly, which lets you use any search library you like:
import { } from '@sveltepress/theme-default'
import { } from '@sveltepress/vite'
import { } from 'vite'
import from './src/components/MySearchComponent.svelte'
export default ({
: [
({
: ({
: ,
}),
}),
],
}) When both search and docsearch are provided, search takes priority and docsearch is ignored.