@cmfcmf/docusaurus-search-local

中文文档
2.0.1发布于 2025/10/26MITCommonJS构建来源已验证近 30 天下载 14万

本地 / 离线搜索 Docusaurus

中文使用文档
文档目录8 节
  1. 安装
  2. 使用量
  3. 非英语文档
  4. 文档版本
  5. 国际化
  6. 调试
  7. 捐款
  8. 许可证

下行 / 本地搜索 docusaurus v3+

Version License code style: prettier GitHub issues GitHub last commit

离线/ 本地搜索 Docusaurus 3+ 时间轴 在防火墙后面工作.

特性要领 :

  • 支持多个文档版本
  • 支持以英文以外的语文编写的文件
  • 突出显示搜索结果
  • 文件、博客和一般页面的自定义解析器
  • 懒惰地装入索引

Search in Action

注:我们使用开源 阿尔戈利亚/自动完成 用于搜索框的库. 这个图书馆只是用作前端,和, 不同于默认 Docusaurus 搜索体验(阿尔戈利亚/搜索, (中文(简体) ), 没有连接到任何 Algolia 或第三方服务器。 。 。 .

安装

npm install @cmfcmf/docusaurus-search-local

或者说

yarn add @cmfcmf/docusaurus-search-local

使用量

将此插件添加到 plugins 阵列 docusaurus.config.js。 。 。 .

const config = {
  // ...
  plugins: ["@cmfcmf/docusaurus-search-local"],

  // or, if you want to specify options:

  // ...
  plugins: [
    [
      "@cmfcmf/docusaurus-search-local",
      {
        // Options here
      },
    ],
  ],
};

export default config;

以下选项可供选择(默认情况如下):

{
  // whether to index docs pages
  indexDocs: true,

  // Whether to also index the titles of the parent categories in the sidebar of a doc page.
  // 0 disables this feature.
  // 1 indexes the direct parent category in the sidebar of a doc page
  // 2 indexes up to two nested parent categories of a doc page
  // 3...
  //
  // Do _not_ use Infinity, the value must be a JSON-serializable integer.
  indexDocSidebarParentCategories: 0,

  // Includes parent categories path in search result
  includeParentCategoriesInPageTitle: false,

  // whether to index blog pages
  indexBlog: true,

  // whether to index static pages
  // /404.html is never indexed
  indexPages: false,

  // language of your documentation, see next section
  language: "en",

  // setting this to "none" will prevent the default CSS to be included. The default CSS
  // comes from autocomplete-theme-classic, which you can read more about here:
  // https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-theme-classic/
  // When you want to overwrite CSS variables defined by the default theme, make sure to suffix your
  // overwrites with `!important`, because they might otherwise not be applied as expected. See the
  // following comment for more information: https://github.com/cmfcmf/docusaurus-search-local/issues/107#issuecomment-1119831938.
  style: undefined,

  // The maximum number of search results shown to the user. This does _not_ affect performance of
  // searches, but simply does not display additional search results that have been found.
  maxSearchResults: 8,

  // lunr.js-specific settings
  lunr: {
    // When indexing your documents, their content is split into "tokens".
    // Text entered into the search box is also tokenized.
    // This setting configures the separator used to determine where to split the text into tokens.
    // By default, it splits the text at whitespace and dashes.
    //
    // Note: Does not work for "ja" and "th" languages, since these use a different tokenizer.
    tokenizerSeparator: /[\s\-]+/,
    // https://lunrjs.com/guides/customising.html#similarity-tuning
    //
    // This parameter controls the importance given to the length of a document and its fields. This
    // value must be between 0 and 1, and by default it has a value of 0.75. Reducing this value
    // reduces the effect of different length documents on a term’s importance to that document.
    b: 0.75,
    // This controls how quickly the boost given by a common word reaches saturation. Increasing it
    // will slow down the rate of saturation and lower values result in quicker saturation. The
    // default value is 1.2. If the collection of documents being indexed have high occurrences
    // of words that are not covered by a stop word filter, these words can quickly dominate any
    // similarity calculation. In these cases, this value can be reduced to get more balanced results.
    k1: 1.2,
    // By default, we rank pages where the search term appears in the title higher than pages where
    // the search term appears in just the text. This is done by "boosting" title matches with a
    // higher value than content matches. The concrete boosting behavior can be controlled by changing
    // the following settings.
    titleBoost: 5,
    contentBoost: 1,
    tagsBoost: 3,
    parentCategoriesBoost: 2, // Only used when indexDocSidebarParentCategories > 0
  }
}

您现在可以使用搜索栏搜索您的文档 .

重要: 只搜索静态构建的文档( 即您运行后) npm run docusaurus build 文档文件夹中.

搜索确实 没有 发展工作(即运行时) npm run docusaurus start) (中文(简体) ). 如果您想要测试本地搜索, 请先使用 npm run docusaurus build,然后通过 npm run docusaurus serve。 。 。 .

非英语文档

使用 language 选项,如果文档不是用英语编写的。 您可以指定一种单一语言或多种语言的数组. 现有语言如下:

ar, da, de, en, es, fi, fr, hi, hu, it, ja, nl, no, pt, ro, ru, sv, th, tr, vi, zh

重要内容:中文支持(zh),您还必须安装 nodejieba npm 软件包在 ^2.5.0 || ^3.0.0。 。 。 .

文档版本

支持使用正式 Docusaurus Docs 插件创建的文档版本 . 搜索栏默认为最新版本( 不) next,但最新版本定义于 versions.json),当不是在文档页面上(例如,当查看博客帖或静态页面时). 如果用户访问一个文件页面,则从页面中取出该版本,只搜索该版本的文件. 搜索栏占位符文本总是反映当前检测到的文档版本.

国际化

此插件支持使用 Docusaurus i18n (英语) 从盒子里出来. 请在 代码翻译 子文件夹并提交 PR.

您也可以通过 modifiing 来调整翻译 <yourfolder>/i18n/<locale>/code.json 开始 cmfcmf/d-s-l.。 。 。 . 更多信息: https://docusaurus.io/docs/i18n/tutorial# translate-json-files (中文(简体) )

调试

如果构建文档时产生出错, 您可以以调试模式构建以解析 由哪一页引起。 要做到这一点,只需设置 DEBUG 建筑时的环境变量 文档 : DEBUG=1 npm run docusaurus build。 。 。 .

捐款

请看 捐款额 以备进一步资料.

许可证

麻省理工学院

版本与发布记录

@cmfcmf/docusaurus-search-local 共发布 36 个版本,首次发布于 2020/01/16;过去 12 个月发布了 0 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.0.1latest2025/10/261 年前
2.0.02025/10/191.1 年前
1.2.02024/06/102 年前
1.1.02023/04/113 年前
1.0.02023/02/263 年前
0.11.02022/06/124 年前

关于 @cmfcmf/docusaurus-search-local 的常见问题

@cmfcmf/docusaurus-search-local 是什么?

本地 / 离线搜索 Docusaurus

如何安装 @cmfcmf/docusaurus-search-local?

在项目目录运行 npm install @cmfcmf/docusaurus-search-local,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@docusaurus/core(^3.0.0)、react(^18 || ^19)、react-dom(^18 || ^19)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@cmfcmf/docusaurus-search-local 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/cmfcmf__docusaurus-search-local 是否存在。

@cmfcmf/docusaurus-search-local 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@cmfcmf/docusaurus-search-local 可以商用吗?

@cmfcmf/docusaurus-search-local 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cmfcmf/docusaurus-search-local 的下载量有多少?

根据 npm 官方下载统计,@cmfcmf/docusaurus-search-local 在 2026/10/10 – 2026/11/08 这 30 天内被下载 140,045 次,日均约 4,668 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cmfcmf/docusaurus-search-local 还在维护吗?

最新版本 2.0.1 发布于 2025/10/26(1 年前);至今共发布 36 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/01/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。