mirror of
https://github.com/facebook/docusaurus.git
synced 2025-04-28 17:57:48 +02:00
fix(algolia): make search footer respect searchPagePath (#8539)
This commit is contained in:
parent
00023c24b6
commit
19c1e27b52
1 changed files with 10 additions and 5 deletions
|
@ -8,6 +8,7 @@
|
|||
import {useCallback, useEffect, useState} from 'react';
|
||||
import {useHistory} from '@docusaurus/router';
|
||||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||
import type {ThemeConfig as AlgoliaThemeConfig} from '@docusaurus/theme-search-algolia';
|
||||
|
||||
const SEARCH_PARAM_QUERY = 'q';
|
||||
|
||||
|
@ -31,8 +32,11 @@ export function useSearchPage(): {
|
|||
} {
|
||||
const history = useHistory();
|
||||
const {
|
||||
siteConfig: {baseUrl},
|
||||
siteConfig: {baseUrl, themeConfig},
|
||||
} = useDocusaurusContext();
|
||||
const {
|
||||
algolia: {searchPagePath},
|
||||
} = themeConfig as AlgoliaThemeConfig;
|
||||
|
||||
const [searchQuery, setSearchQueryState] = useState('');
|
||||
|
||||
|
@ -65,10 +69,11 @@ export function useSearchPage(): {
|
|||
const generateSearchPageLink = useCallback(
|
||||
(targetSearchQuery: string) =>
|
||||
// Refer to https://github.com/facebook/docusaurus/pull/2838
|
||||
`${baseUrl}search?${SEARCH_PARAM_QUERY}=${encodeURIComponent(
|
||||
targetSearchQuery,
|
||||
)}`,
|
||||
[baseUrl],
|
||||
// Note: if searchPagePath is falsy, useSearchPage() will not be called
|
||||
`${baseUrl}${
|
||||
searchPagePath as string
|
||||
}?${SEARCH_PARAM_QUERY}=${encodeURIComponent(targetSearchQuery)}`,
|
||||
[baseUrl, searchPagePath],
|
||||
);
|
||||
|
||||
return {
|
||||
|
|
Loading…
Add table
Reference in a new issue