Skip to content

Commit

Permalink
fix(algolia): make search footer respect searchPagePath
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed Jan 10, 2023
1 parent 3526059 commit 0ee6e12
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/docusaurus-theme-common/src/hooks/useSearchPage.ts
Expand Up @@ -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';

Expand All @@ -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('');

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 0ee6e12

Please sign in to comment.