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:
Alexey Pyltsyn 2020-11-12 19:01:46 +03:00 committed by GitHub
parent 702fc15c8e
commit 8ef7c24583
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 3 deletions

View file

@ -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',

View file

@ -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;
}

View file

@ -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