Offline search component by lunr for Docusaurus V2
npm install docs-searchworker_thread is needed, suggested node version > 12.X
npm i docs-search --save
`
2. Then run npm install to update, build, and link the packages
`
npm install
`
3. Then run docusaurus swizzle
`
npm run swizzle docs-search SearchBar -- --danger
`
4. Add the docs-search plugin to your docusaurus.config.js
`
module.exports = {
// ...
plugins: [require.resolve('docs-search')],
}
`
5. Then build your Docusaurus project
`
npm run build
`
6. Serve your application
`
npx http-server ./build
`Note: Docusaurus search information can only be generated from a production build. Local development is currently not supported.
Language options
`
module.exports = {
// ...
plugins: [[ require.resolve('docs-search'), {
languages: ['en', 'de'] // language codes
}]],
}
`Other options
$3
You can exclude certain routes from the search by using this option:
`
module.exports = {
// ...
plugins: [
[require.resolve('docs-search'), {
excludeRoutes: [
'docs/changelogs/*/', // exclude changelogs from indexing
]
}]
],
}
`
$3
Base url will not indexed by default, if you want to index the base url set this option to true
`
module.exports = {
// ...
plugins: [
[require.resolve('docs-search'),
{
indexBaseUrl: true
}
]
],
}
`
Thanks to algolia/docsearch.js`, I modified it to create this search component