• Stars
    star
    436
  • Rank 97,769 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 4 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Local / Offline Search for docusaurus

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 [email protected])

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 run docusaurus swizzle
npm run swizzle docusaurus-lunr-search SearchBar -- --eject --danger
  1. Then build your Docusaurus project
npm run build
  1. 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('docusaurus-lunr-search'), {
      languages: ['en', 'de'] // language codes
    }]],
}

Supports all the language listed here https://github.com/MihaiValentin/lunr-languages

Other options

excludeRoutes

You can exclude certain routes from the search by using this option:

module.exports = {
  // ...
    plugins: [
    [require.resolve('docusaurus-lunr-search'), {
        excludeRoutes: [
            'docs/changelogs/**/*', // exclude changelogs from indexing
        ]
    }]
  ],
}

indexBaseUrl

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('docusaurus-lunr-search'),
            {
                indexBaseUrl: true
            }
        ]
    ],
}

disableVersioning

Docs versions are displayed by default. If you want to hide it, set this plugin option to true

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.