mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-13 09:07:29 +02:00
fix(v2): use swizzled SearchPage component if any (#3721)
* fix(v2): use swizzled SearchPage component if any * Fix dependency cycles warning
This commit is contained in:
parent
702fc15c8e
commit
8ef7c24583
3 changed files with 20 additions and 3 deletions
|
@ -8,7 +8,7 @@
|
|||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const eta = require('eta');
|
||||
const {normalizeUrl} = require('@docusaurus/utils');
|
||||
const {normalizeUrl, getSwizzledComponent} = require('@docusaurus/utils');
|
||||
const openSearchTemplate = require('./templates/opensearch');
|
||||
const {validateThemeConfig} = require('./validateThemeConfig');
|
||||
const {memoize} = require('lodash');
|
||||
|
@ -29,7 +29,10 @@ function theme(context) {
|
|||
baseUrl,
|
||||
siteConfig: {title, url, favicon},
|
||||
} = context;
|
||||
const pagePath = path.resolve(__dirname, './theme/SearchPage/index.js');
|
||||
const pageComponent = './theme/SearchPage/index.js';
|
||||
const pagePath =
|
||||
getSwizzledComponent(pageComponent) ||
|
||||
path.resolve(__dirname, pageComponent);
|
||||
|
||||
return {
|
||||
name: 'docusaurus-theme-search-algolia',
|
||||
|
|
|
@ -463,3 +463,17 @@ export function reportMessage(
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function getSwizzledComponent(
|
||||
componentPath: string,
|
||||
): string | undefined {
|
||||
const swizzledComponentPath = path.resolve(
|
||||
process.cwd(),
|
||||
'src',
|
||||
componentPath,
|
||||
);
|
||||
|
||||
return fs.existsSync(swizzledComponentPath)
|
||||
? swizzledComponentPath
|
||||
: undefined;
|
||||
}
|
||||
|
|
|
@ -197,7 +197,7 @@ This theme provides a `@theme/SearchBar` component that integrates with Algolia
|
|||
npm install --save @docusaurus/theme-search-algolia
|
||||
```
|
||||
|
||||
This theme also adds search page available at `/search` path with OpenSearch support.
|
||||
This theme also adds search page available at `/search` (as swizzleable `SearchPage` component) path with OpenSearch support.
|
||||
|
||||
:::tip
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue