Enabling Search
Docusaurus支持使用 Algolia DocSearch 来搜索你的网站。 Once you have set up your site, enter your site information to have Algolia crawl your website's documentation pages. Algolia will then send you an API key and index name for your site.
启用搜索框
Enter your search-only API key and index name into siteConfig.js
in the algolia
section to enable search for your site.
const siteConfig = {
...
algolia: {
apiKey: "my-search-only-api-key-1234",
indexName: "my-index-name"
},
...
}
Extra Search Options
You can also specify extra search options used by Algolia by using an algoliaOptions
field in algolia
. 如果您想为不同版本或语言的文档提供不同的搜索结果,这可能会很有用。 Any occurrences of "VERSION" or "LANGUAGE" will be replaced by the version or language of the current page, respectively. More details about search options can be found here.
const siteConfig = {
...
algolia: {
...
algoliaOptions: {
facetFilters: [ "tags:VERSION" ],
hitsPerPage: 5
}
},
}
Controlling the Location of the Search Bar
By default, the search bar will be the rightmost element in the top navigation bar.
If you want to change the default location, add the searchBar
flag in the headerLinks
field of siteConfig.js
in your desired location. For example, you may want the search bar in between your internal and external links.
const siteConfig = {
...
headerLinks: [
{...}
{...}
{ search: true }
{...}
{...}
],
...
}
Disabling the Search Bar
To disable the search bar, comment out (recommended) or delete the algolia
section in the siteConfig.js
file.
Also, if you have customized the location of the search bar in headerLinks
, set search: false
.