Offline Search for Docusaurus V2
worker_thread
is needed, suggested node version > 12.X
For older version of node use docusaurus-lunr-search
version 2.1.0
(npm i docusaurus-lunr-search@2.1.0
)
- Install this package
npm i docusaurus-lunr-search --save
- Then run
npm install
to update, build, and link the packages
npm install
- Add the docusaurus-lunr-search plugin to your
docusaurus.config.js
module.exports = {
// ...
plugins: [require.resolve('docusaurus-lunr-search')],
}
- Then build your Docusaurus project
npm run build
- Serve your application
npm run serve
or
npx http-server ./build
Note: Docusaurus search information can only be generated from a production build. Local development is currently not supported.
module.exports = {
// ...
plugins: [[ require.resolve('docusaurus-lunr-search'), {
languages: ['en', 'de'] // language codes
}]],
}
Supports all the language listed here https://github.com/MihaiValentin/lunr-languages
Option | Type | Default | Description |
---|---|---|---|
languages |
Array |
['en'] |
Language codes to use for stemming, Supports all the language listed here https://github.com/MihaiValentin/lunr-languages |
indexBaseUrl |
Boolean |
false |
Base url will not indexed by default, if you want to index the base url set this option to true |
excludeRoutes |
Array |
[] |
Exclude certain routes from the search |
includeRoutes |
Array |
[] |
Include only specific routes for search |
stopWords |
Array |
[] |
Add stop words(words that are exclude from search result) to the search index |
excludeTags |
Array |
[] |
Exclude certain tags from the search |
disableVersioning |
Boolean |
false |
Docs versions are displayed by default. If you want to hide it, set this plugin option to true |
By default the library will search for heading only in the children of .markdown
element.
If you are using a FrontMatter and you have headings that are encapsulated by other elements, such as divs, then add the attribute data-search-children
to the elements having headings.
This also applies for all descendants of the wrapper with data-search-children.
Check this issue #115 for more detail
Thanks to algolia/docsearch.js
, I modified it to create this search component
And thanks cmfcmf, I used the code from his library docusaurus-search-local for multi-language support.
Checkout the releases page for changelog.