简体   繁体   English

Docusaurus 2 中的自定义搜索栏

[英]Custom Search Bar in Docusaurus 2

I'm just experimenting with Docusaurus V2, i want o enable offline search witth LUNR( https://lunrjs.com/ ) Search, like described, in this blog.我只是在试验 Docusaurus V2,我想使用 LUNR( https://lunrjs.com/ )搜索启用离线搜索,如本博客所述。

https://v2.docusaurus.io/feedback/p/offline-search https://v2.docusaurus.io/feedback/p/offline-search

i also searched the docs for that.我还为此搜索了文档。

https://v2.docusaurus.io/docs/search/#__docusaurus https://v2.docusaurus.io/docs/search/#__docusaurus

I installed the with the "yarn swizzle @docusaurus/theme-classic SearchBar" command, but no search bar appeared, when running with "npm start".我使用“yarn swizzle @docusaurus/theme-classic SearchBar”命令安装了,但是在使用“npm start”运行时没有出现搜索栏。

Besides, a document was created with this content in src/theme/SearchBar.js:此外,在 src/theme/SearchBar.js 中创建了一个包含此内容的文档:

/**
 * Copyright (c) 2017-present, Facebook, Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

export {default} from '@docusaurus/Noop';

The documentation is really thin, what could be wrong.文档真的很薄,可能有什么问题。 Is there a working example?有工作的例子吗?

As described in the Blog by this video, there is a possibility.正如该视频的博客中所述,有一种可能性。https://canny.io/images/873b18eabf90e91512ac4d0ceb48973b.gifhttps://canny.io/images/873b18eabf90e91512ac4d0ceb48973b.gif

You need to edit that file and implement your own searchbar component.您需要编辑该文件并实现您自己的搜索栏组件。 You can do yarn swizzle @docusaurus/theme-search-algolia SearchBar instead if you want to modify it from the algolia searchbar如果您想从 algolia 搜索栏修改它,您可以改为使用yarn swizzle @docusaurus/theme-search-algolia SearchBar

It's possible to create your own custom offline search component, so for Docusaurus didn't have any inbuilt offline search option.可以创建自己的自定义离线搜索组件,因此 Docusaurus 没有任何内置的离线搜索选项。

Running the command yarn swizzle @docusaurus/theme-classic SearchBar will create a bootstrapped search component where you have to write your own logic for search.运行命令yarn swizzle @docusaurus/theme-classic SearchBar将创建一个引导搜索组件,您必须在其中编写自己的搜索逻辑。

The offline search option is one of the most requested features in Docusaurus and the community people are working on it.离线搜索选项是 Docusaurus 中最受欢迎的功能之一,社区的人们正在致力于此。 There is a GitHub issue for it - https://github.com/facebook/docusaurus/issues/776 here you can check the progress of the feature.有一个 GitHub 问题 - https://github.com/facebook/docusaurus/issues/776在这里您可以检查该功能的进度。

There is a third-party plugin which will provide an offline search for Docusaurus - https://github.com/lelouch77/docusaurus-lunr-search有一个第三方插件可以离线搜索 Docusaurus - https://github.com/lelouch77/docusaurus-lunr-search

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM