Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@easyops-cn/docusaurus-search-local

Package Overview
Dependencies
Maintainers
3
Versions
107
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@easyops-cn/docusaurus-search-local

An offline/local search plugin for Docusaurus v2.

  • 0.17.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
40K
decreased by-13.44%
Maintainers
3
Weekly downloads
 
Created
Source

@easyops-cn/docusaurus-search-local

Npm Version CI Status Coverage Status

An offline/local search plugin for Docusaurus v2, which supports multiple languages, especially optimized for language of zh.

Originally forked from cmfcmf/docusaurus-search-local.

Then later fully rewritten with TypeScript 💪, styles polished 💅, language of Chinese supported 🇨🇳, and tests covered ✅.

Live Demo

https://easyops-cn.github.io/docusaurus-search-example/

Screen Shots

Screen Shot EN

Screen Shot ZH

Installation

npm install --save @easyops-cn/docusaurus-search-local
# or
yarn add @easyops-cn/docusaurus-search-local

Usage

Add @easyops-cn/docusaurus-search-local into your docusaurus plugins.

// In your `docusaurus.config.js`:
module.exports = {
  // ... Your other configurations.
  plugins: [
    // ... Your other plugins.
    [
      require.resolve("@easyops-cn/docusaurus-search-local"),
      {
        // ... Your options.
        // `hashed` is recommended as long-term-cache of index file is possible.
        hashed: true,
        // For Docs using Chinese, The `language` is recommended to set to:
        // ```
        // language: ["en", "zh"],
        // ```
        // When applying `zh` in language, please install `nodejieba` in your project.
      },
    ],
  ],
};

Notice!

When applying "zh" in language, please also install nodejieba in your project, it became a peer dependency since v0.7.0.

npm install nodejieba
# or
yarn add nodejieba

Plugin Options

NameTypeDefaultDescription
indexDocsbooleantrueWhether to index docs.
indexBlogbooleantrueWhether to index blog.
indexPagesbooleanfalseWhether to index pages.
docsRouteBasePathstring | string[]"/docs"Base route path(s) of docs. Slash at beginning is not required.
blogRouteBasePathstring | string[]"/blog"Base route path(s) of blog. Slash at beginning is not required.
languagestring | string[]"en"All lunr-languages supported languages, + zh 🔥.
hashedbooleanfalseWhether to add a hashed query when fetching index (based on the content hash of all indexed *.md in docsDir and blogDir if applicable)
docsDirstring | string[]"docs"The dir(s) of docs to get the content hash, it's relative to the dir of your project.
blogDirstring | string[]"blog"Just like the docsDir but applied to blog.
removeDefaultStopWordFilterbooleanfalseSometimes people (E.g., us) want to keep the English stop words as indexed, since they maybe are relevant in programming docs.
highlightSearchTermsOnTargetPagebooleanfalseHighlight search terms on target page.
searchResultLimitsnumber8Limit the search results.
searchResultContextMaxLengthnumber50Set the max length of characters of each search result to show.
translationsTranslationMap-Set translations of this plugin, see docs below.
ignoreFilesstring | RegExp | (string | RegExp)[]/meta$/Set the match rules to ignore some files.

Translations

To make this plugin localized, pass a translations option which defaults to:

{
  "search_placeholder": "Search",
  "see_all_results": "See all results",
  "no_results": "No results.",
  "search_results_for": "Search results for \"{{ keyword }}\"",
  "search_the_documentation": "Search the documentation",
  "count_documents_found": "{{ count }} document found",
  "count_documents_found_plural": "{{ count }} documents found",
  "no_documents_were_found": "No documents were found"
}

Note that *_plural can be omitted if it is the same as singular.

Custom Styles

This plugin is shipped with polished styles just like the Algolia Search on the Docusaurus v2 website. Feel free to override these css custom properties (css variables) below.

VarDefault (light)Default (dark)
--search-local-modal-background#f5f6f7var(--ifm-background-color)
--search-local-modal-shadowinset 1px 1px 0 0 hsla(0, 0%, 100%, 0.5),
0 3px 8px 0 #555a64
inset 1px 1px 0 0 #2c2e40,
0 3px 8px 0 #000309
--search-local-modal-width560px-
--search-local-modal-width-sm340px-
--search-local-spacing12px-
--search-local-hit-background#fffvar(--ifm-color-emphasis-100)
--search-local-hit-shadow0 1px 3px 0 #d4d9e1none
--search-local-hit-color#444950var(--ifm-font-color-base)
--search-local-hit-height56px-
--search-local-highlight-colorvar(--ifm-color-primary)-
--search-local-muted-color#969fafvar(--ifm-color-secondary-darkest)
--search-local-icon-stroke-width1.4-
--search-local-hit-active-colorvar(--ifm-color-white)-

E.g.:

:root {
  --search-local-modal-width: 480px;
  --search-local-highlight-color: #5468ff;
}

html[data-theme="dark"] {
  --search-local-highlight-color: #d23669;
}

Trouble Shooting

When building your docs project, Set the env DEBUG=search-local:* to enable debug logs.

# In your docs project:
DEBUG=search-local:* yarn build

In case some specific errors occurred:

  • Error: Cannot mix different versions of joi schemas:
    • Try using @easyops-cn/docusaurus-search-local >= v0.16.0 with Docusaurus >= v2.0.0-alpha.73
    • Try using @easyops-cn/docusaurus-search-local between v0.14.0 and v0.15.1 with Docusaurus between v2.0.0-alpha.68 and v2.0.0-alpha.72
    • Or try using @easyops-cn/docusaurus-search-local <= v0.13.1 with Docusaurus <= v2.0.0-alpha.66
  • Error: Command failed with signal "SIGSEGV":
    • This is probably caused by a known issue introduced by nodejieba@2.5.2, if you enabled language of zh.
    • Try downgrading nodejieba to 2.4.2 and it will work again, see discussions in #47.

Further Reading

Contributing

See contributing guide.

FAQs

Package last updated on 28 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc