下行 / 本地搜索 docusaurus v3+
离线/ 本地搜索 Docusaurus 3+ 时间轴 在防火墙后面工作.
特性要领 :
- 支持多个文档版本
- 支持以英文以外的语文编写的文件
- 突出显示搜索结果
- 文件、博客和一般页面的自定义解析器
- 懒惰地装入索引

注:我们使用开源 阿尔戈利亚/自动完成 用于搜索框的库. 这个图书馆只是用作前端,和, 不同于默认 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。 。 。 .
捐款
请看 捐款额 以备进一步资料.
许可证
麻省理工学院