refactor(theme-classic): bias again search metadata toward Algolia DocSearch (#6707)

This commit is contained in:
Sébastien Lorber 2022-02-17 14:24:31 +01:00 committed by GitHub
parent 12aae9a086
commit a6f53aa9d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 36 deletions

View File

@ -10,19 +10,25 @@ import React from 'react';
import Head from '@docusaurus/Head';
import type {Props} from '@theme/SearchMetadata';
// Note: we don't couple this to Algolia/DocSearch on purpose
// We may want to support other search engine plugins too
// Search plugins should swizzle/override this comp to add their behavior
// Note: we bias toward using Algolia metadata on purpose
// Not doing so leads to confusion in the community,
// as it requires to first crawl the site with the Algolia plugin enabled first
// - https://github.com/facebook/docusaurus/issues/6693
// - https://github.com/facebook/docusaurus/issues/4555
export default function SearchMetadata({
locale,
version,
tag,
}: Props): JSX.Element {
// Seems safe to consider here the locale is the language, as the existing
// docsearch:language filter is afaik a regular string-based filter
const language = locale;
return (
<Head>
{locale && <meta name="docusaurus_locale" content={locale} />}
{version && <meta name="docusaurus_version" content={version} />}
{tag && <meta name="docusaurus_tag" content={tag} />}
{language && <meta name="docsearch:language" content={language} />}
{version && <meta name="docsearch:version" content={version} />}
{tag && <meta name="docsearch:docusaurus_tag" content={tag} />}
</Head>
);
}

View File

@ -1,28 +0,0 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import React from 'react';
import Head from '@docusaurus/Head';
import type {Props} from '@theme/SearchMetadata';
// Override default/agnostic SearchMetadata to use Algolia-specific metadata
function SearchMetadata({locale, version, tag}: Props): JSX.Element {
// Seems safe to consider here the locale is the language, as the existing
// docsearch:language filter is afaik a regular string-based filter
const language = locale;
return (
<Head>
{language && <meta name="docsearch:language" content={language} />}
{version && <meta name="docsearch:version" content={version} />}
{tag && <meta name="docsearch:docusaurus_tag" content={tag} />}
</Head>
);
}
export default SearchMetadata;

View File

@ -127,9 +127,9 @@ Refer to its [official DocSearch documentation](https://docsearch.algolia.com/do
:::caution
The search feature will not work reliably until Algolia crawls your site with the **search plugin enabled**.
The search feature will not work reliably until Algolia crawls your site.
If you are installing the Algolia plugin for the first time and want to ensure the search feature works before deploying it to production, you can ask the DocSearch team to trigger a crawl on a staging environment url or deploy preview.
If search doesn't work after any significant change, please use the Algolia dashboard to **trigger a new crawl**.
:::