Skip to content

praveenn77/docusaurus-lunr-search

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
January 26, 2020 20:54
May 21, 2021 22:26
January 26, 2020 19:54
September 7, 2023 15:13
January 6, 2020 21:31
October 16, 2023 02:45
November 10, 2023 09:44
November 10, 2023 09:44

docusaurus-lunr-search

Offline Search for Docusaurus V2

Demo Website

MIT Licence

npm version

Sample

image

Prerequisites

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)

How to Use ?

  1. Install this package
npm i docusaurus-lunr-search  --save
  1. Then run npm install to update, build, and link the packages
npm install
  1. Add the docusaurus-lunr-search plugin to your docusaurus.config.js
module.exports = {
  // ...
    plugins: [require.resolve('docusaurus-lunr-search')],
}
  1. Then build your Docusaurus project
npm run build
  1. 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.

Using an option (eg. languages) in the plugin

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

Options available

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
highlightResult Boolean false Enable it to highlight the searched word in the result page. Used mark.js for highlighting.
You can customize the highlight color using css
mark { background-color: red !important; color: green !important }
disableVersioning Boolean false Docs versions are displayed by default. If you want to hide it, set this plugin option to true
assetUrl string \ Url from which the generated search doc files to be loaded, check issue #122

Indexing non-direct children headings of .markdown

By default, this library will only search for headings that are direct children of the .markdown element.

If you would like to render content inside the .markdown element on a swizzled DocItem component, and want this library to index the headings inside those custom elements even if they are not direct children of the .markdown element, then add the attribute data-search-children to a parent element of the headings you want to index.

The data-search-children attribute will cause this library to look for all headings inside that element, including both direct and indirect children (E.g. 'grandchildren' nodes).

Check this issue #115 for more details.

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.

Changelog

Checkout the releases page for changelog.