@docusaurus/theme-search-algolia 2.0.0-beta.15 → 2.0.0-beta.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client/index.js +1 -1
- package/lib/client/useAlgoliaContextualFacetFilters.js +6 -6
- package/lib/index.js +96 -67
- package/lib/templates/opensearch.d.ts +1 -1
- package/lib/templates/opensearch.js +7 -7
- package/lib/theme/SearchBar/index.d.ts +1 -2
- package/lib/theme/SearchBar/index.js +181 -125
- package/lib/theme/SearchPage/index.d.ts +1 -2
- package/lib/theme/SearchPage/index.js +381 -224
- package/lib/validateThemeConfig.d.ts +1 -1
- package/lib/validateThemeConfig.js +37 -27
- package/package.json +18 -17
- package/src/deps.d.ts +10 -0
- package/src/index.ts +41 -26
- package/src/templates/opensearch.ts +5 -5
- package/src/theme/SearchBar/index.tsx +16 -14
- package/src/theme/SearchPage/index.tsx +6 -10
- package/src/theme-search-algolia.d.ts +3 -4
- package/src/types.d.ts +0 -4
- package/src/validateThemeConfig.ts +9 -5
- package/lib/theme/SearchMetadata/index.d.ts +0 -11
- package/lib/theme/SearchMetadata/index.js +0 -20
- package/src/theme/SearchMetadata/index.tsx +0 -28
|
@@ -8,8 +8,8 @@ import { Joi } from '@docusaurus/utils-validation';
|
|
|
8
8
|
import type { ThemeConfig, Validate, ValidationResult } from '@docusaurus/types';
|
|
9
9
|
export declare const DEFAULT_CONFIG: {
|
|
10
10
|
contextualSearch: boolean;
|
|
11
|
-
appId: string;
|
|
12
11
|
searchParameters: {};
|
|
12
|
+
searchPagePath: string;
|
|
13
13
|
};
|
|
14
14
|
export declare const Schema: Joi.ObjectSchema<any>;
|
|
15
15
|
export declare function validateThemeConfig({ validate, themeConfig, }: {
|
|
@@ -1,40 +1,50 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
/**
|
|
3
3
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
-
Object.defineProperty(exports,
|
|
8
|
+
Object.defineProperty(exports, '__esModule', {value: true});
|
|
9
9
|
exports.validateThemeConfig = exports.Schema = exports.DEFAULT_CONFIG = void 0;
|
|
10
|
-
const utils_validation_1 = require(
|
|
10
|
+
const utils_validation_1 = require('@docusaurus/utils-validation');
|
|
11
11
|
exports.DEFAULT_CONFIG = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
appId: 'BH4D9OD16A',
|
|
18
|
-
searchParameters: {},
|
|
12
|
+
// enabled by default, as it makes sense in most cases
|
|
13
|
+
// see also https://github.com/facebook/docusaurus/issues/5880
|
|
14
|
+
contextualSearch: true,
|
|
15
|
+
searchParameters: {},
|
|
16
|
+
searchPagePath: 'search',
|
|
19
17
|
};
|
|
20
18
|
exports.Schema = utils_validation_1.Joi.object({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
19
|
+
algolia: utils_validation_1.Joi.object({
|
|
20
|
+
// Docusaurus attributes
|
|
21
|
+
contextualSearch: utils_validation_1.Joi.boolean().default(
|
|
22
|
+
exports.DEFAULT_CONFIG.contextualSearch,
|
|
23
|
+
),
|
|
24
|
+
externalUrlRegex: utils_validation_1.Joi.string().optional(),
|
|
25
|
+
// Algolia attributes
|
|
26
|
+
appId: utils_validation_1.Joi.string().required().messages({
|
|
27
|
+
'any.required':
|
|
28
|
+
'"algolia.appId" is required. If you haven\'t migrated to the new DocSearch infra, please refer to the blog post for instructions: https://docusaurus.io/blog/2021/11/21/algolia-docsearch-migration',
|
|
29
|
+
}),
|
|
30
|
+
apiKey: utils_validation_1.Joi.string().required(),
|
|
31
|
+
indexName: utils_validation_1.Joi.string().required(),
|
|
32
|
+
searchParameters: utils_validation_1.Joi.object()
|
|
33
|
+
.default(exports.DEFAULT_CONFIG.searchParameters)
|
|
34
|
+
.unknown(),
|
|
35
|
+
searchPagePath: utils_validation_1.Joi.alternatives()
|
|
36
|
+
.try(
|
|
37
|
+
utils_validation_1.Joi.boolean().invalid(true),
|
|
38
|
+
utils_validation_1.Joi.string(),
|
|
39
|
+
)
|
|
40
|
+
.allow(null)
|
|
41
|
+
.default(exports.DEFAULT_CONFIG.searchPagePath),
|
|
42
|
+
})
|
|
43
|
+
.label('themeConfig.algolia')
|
|
44
|
+
.required()
|
|
45
|
+
.unknown(), // DocSearch 3 is still alpha: don't validate the rest for now
|
|
36
46
|
});
|
|
37
|
-
function validateThemeConfig({
|
|
38
|
-
|
|
47
|
+
function validateThemeConfig({validate, themeConfig}) {
|
|
48
|
+
return validate(exports.Schema, themeConfig);
|
|
39
49
|
}
|
|
40
50
|
exports.validateThemeConfig = validateThemeConfig;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/theme-search-algolia",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.16",
|
|
4
4
|
"description": "Algolia search component for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -18,30 +18,31 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"scripts": {
|
|
21
|
-
"build": "yarn build:server && yarn build:
|
|
21
|
+
"build": "yarn build:server && yarn build:client && yarn build:copy && yarn build:format",
|
|
22
22
|
"build:server": "tsc --project tsconfig.server.json",
|
|
23
|
-
"build:
|
|
24
|
-
"build:copy": "node copyUntypedFiles.mjs"
|
|
23
|
+
"build:client": "tsc --project tsconfig.client.json",
|
|
24
|
+
"build:copy": "node copyUntypedFiles.mjs",
|
|
25
|
+
"build:format": "prettier --config ../../.prettierrc --write \"lib/**/*.js\""
|
|
25
26
|
},
|
|
26
27
|
"dependencies": {
|
|
27
|
-
"@docsearch/react": "^3.0.0
|
|
28
|
-
"@docusaurus/core": "2.0.0-beta.
|
|
29
|
-
"@docusaurus/logger": "2.0.0-beta.
|
|
30
|
-
"@docusaurus/theme-common": "2.0.0-beta.
|
|
31
|
-
"@docusaurus/theme-translations": "2.0.0-beta.
|
|
32
|
-
"@docusaurus/utils": "2.0.0-beta.
|
|
33
|
-
"@docusaurus/utils-validation": "2.0.0-beta.
|
|
34
|
-
"algoliasearch": "^4.
|
|
35
|
-
"algoliasearch-helper": "^3.
|
|
28
|
+
"@docsearch/react": "^3.0.0",
|
|
29
|
+
"@docusaurus/core": "2.0.0-beta.16",
|
|
30
|
+
"@docusaurus/logger": "2.0.0-beta.16",
|
|
31
|
+
"@docusaurus/theme-common": "2.0.0-beta.16",
|
|
32
|
+
"@docusaurus/theme-translations": "2.0.0-beta.16",
|
|
33
|
+
"@docusaurus/utils": "2.0.0-beta.16",
|
|
34
|
+
"@docusaurus/utils-validation": "2.0.0-beta.16",
|
|
35
|
+
"algoliasearch": "^4.12.1",
|
|
36
|
+
"algoliasearch-helper": "^3.7.0",
|
|
36
37
|
"clsx": "^1.1.1",
|
|
37
38
|
"eta": "^1.12.3",
|
|
38
|
-
"
|
|
39
|
+
"fs-extra": "^10.0.1",
|
|
40
|
+
"lodash": "^4.17.21",
|
|
39
41
|
"tslib": "^2.3.1",
|
|
40
42
|
"utility-types": "^3.10.0"
|
|
41
43
|
},
|
|
42
44
|
"devDependencies": {
|
|
43
|
-
"@docusaurus/module-type-aliases": "2.0.0-beta.
|
|
44
|
-
"fs-extra": "^10.0.0"
|
|
45
|
+
"@docusaurus/module-type-aliases": "2.0.0-beta.16"
|
|
45
46
|
},
|
|
46
47
|
"peerDependencies": {
|
|
47
48
|
"react": "^16.8.4 || ^17.0.0",
|
|
@@ -50,5 +51,5 @@
|
|
|
50
51
|
"engines": {
|
|
51
52
|
"node": ">=14"
|
|
52
53
|
},
|
|
53
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "eb43c4d4f95a4fb97dc9bb9dc615413e0dc2e1e7"
|
|
54
55
|
}
|
package/src/deps.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare module '@docsearch/react/modal';
|
|
9
|
+
|
|
10
|
+
declare module '@docsearch/react/style';
|
package/src/index.ts
CHANGED
|
@@ -6,24 +6,26 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import path from 'path';
|
|
9
|
-
import fs from 'fs';
|
|
9
|
+
import fs from 'fs-extra';
|
|
10
10
|
import {defaultConfig, compile} from 'eta';
|
|
11
11
|
import {normalizeUrl} from '@docusaurus/utils';
|
|
12
12
|
import {readDefaultCodeTranslationMessages} from '@docusaurus/theme-translations';
|
|
13
13
|
import logger from '@docusaurus/logger';
|
|
14
14
|
import openSearchTemplate from './templates/opensearch';
|
|
15
|
-
import
|
|
15
|
+
import _ from 'lodash';
|
|
16
16
|
|
|
17
17
|
import type {LoadContext, Plugin} from '@docusaurus/types';
|
|
18
|
+
import type {ThemeConfig} from '@docusaurus/theme-search-algolia';
|
|
18
19
|
|
|
19
|
-
const getCompiledOpenSearchTemplate = memoize(() =>
|
|
20
|
+
const getCompiledOpenSearchTemplate = _.memoize(() =>
|
|
20
21
|
compile(openSearchTemplate.trim()),
|
|
21
22
|
);
|
|
22
23
|
|
|
23
24
|
function renderOpenSearchTemplate(data: {
|
|
24
25
|
title: string;
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
siteUrl: string;
|
|
27
|
+
searchUrl: string;
|
|
28
|
+
faviconUrl: string | null;
|
|
27
29
|
}) {
|
|
28
30
|
const compiled = getCompiledOpenSearchTemplate();
|
|
29
31
|
return compiled(data, defaultConfig);
|
|
@@ -34,19 +36,21 @@ const OPEN_SEARCH_FILENAME = 'opensearch.xml';
|
|
|
34
36
|
export default function themeSearchAlgolia(context: LoadContext): Plugin<void> {
|
|
35
37
|
const {
|
|
36
38
|
baseUrl,
|
|
37
|
-
siteConfig: {title, url, favicon},
|
|
39
|
+
siteConfig: {title, url, favicon, themeConfig},
|
|
38
40
|
i18n: {currentLocale},
|
|
39
41
|
} = context;
|
|
42
|
+
const {
|
|
43
|
+
algolia: {searchPagePath},
|
|
44
|
+
} = themeConfig as ThemeConfig;
|
|
40
45
|
|
|
41
46
|
return {
|
|
42
47
|
name: 'docusaurus-theme-search-algolia',
|
|
43
48
|
|
|
44
49
|
getThemePath() {
|
|
45
|
-
return path.resolve(__dirname, '
|
|
50
|
+
return path.resolve(__dirname, '../lib/theme');
|
|
46
51
|
},
|
|
47
|
-
|
|
48
52
|
getTypeScriptThemePath() {
|
|
49
|
-
return path.resolve(__dirname, '
|
|
53
|
+
return path.resolve(__dirname, '../src/theme');
|
|
50
54
|
},
|
|
51
55
|
|
|
52
56
|
getDefaultCodeTranslationMessages() {
|
|
@@ -57,30 +61,41 @@ export default function themeSearchAlgolia(context: LoadContext): Plugin<void> {
|
|
|
57
61
|
},
|
|
58
62
|
|
|
59
63
|
async contentLoaded({actions: {addRoute}}) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
if (searchPagePath) {
|
|
65
|
+
addRoute({
|
|
66
|
+
path: normalizeUrl([baseUrl, searchPagePath]),
|
|
67
|
+
component: '@theme/SearchPage',
|
|
68
|
+
exact: true,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
65
71
|
},
|
|
66
72
|
|
|
67
73
|
async postBuild({outDir}) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
if (searchPagePath) {
|
|
75
|
+
const siteUrl = normalizeUrl([url, baseUrl]);
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
await fs.writeFile(
|
|
79
|
+
path.join(outDir, OPEN_SEARCH_FILENAME),
|
|
80
|
+
renderOpenSearchTemplate({
|
|
81
|
+
title,
|
|
82
|
+
siteUrl,
|
|
83
|
+
searchUrl: normalizeUrl([siteUrl, searchPagePath]),
|
|
84
|
+
faviconUrl: favicon ? normalizeUrl([siteUrl, favicon]) : null,
|
|
85
|
+
}),
|
|
86
|
+
);
|
|
87
|
+
} catch (err) {
|
|
88
|
+
logger.error('Generating OpenSearch file failed.');
|
|
89
|
+
throw err;
|
|
90
|
+
}
|
|
80
91
|
}
|
|
81
92
|
},
|
|
82
93
|
|
|
83
94
|
injectHtmlTags() {
|
|
95
|
+
if (!searchPagePath) {
|
|
96
|
+
return {};
|
|
97
|
+
}
|
|
98
|
+
|
|
84
99
|
return {
|
|
85
100
|
headTags: [
|
|
86
101
|
{
|
|
@@ -12,11 +12,11 @@ export default `
|
|
|
12
12
|
<ShortName><%= it.title %></ShortName>
|
|
13
13
|
<Description>Search <%= it.title %></Description>
|
|
14
14
|
<InputEncoding>UTF-8</InputEncoding>
|
|
15
|
-
<% if (it.
|
|
16
|
-
<Image width="16" height="16" type="image/x-icon"><%= it.
|
|
15
|
+
<% if (it.faviconUrl) { _%>
|
|
16
|
+
<Image width="16" height="16" type="image/x-icon"><%= it.faviconUrl %></Image>
|
|
17
17
|
<% } _%>
|
|
18
|
-
<Url type="text/html" method="get" template="<%= it.
|
|
19
|
-
<Url type="application/opensearchdescription+xml" rel="self" template="<%= it.
|
|
20
|
-
<moz:SearchForm><%= it.
|
|
18
|
+
<Url type="text/html" method="get" template="<%= it.searchUrl %>?q={searchTerms}"/>
|
|
19
|
+
<Url type="application/opensearchdescription+xml" rel="self" template="<%= it.siteUrl %>opensearch.xml" />
|
|
20
|
+
<moz:SearchForm><%= it.siteUrl %></moz:SearchForm>
|
|
21
21
|
</OpenSearchDescription>
|
|
22
22
|
`;
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
8
7
|
|
|
9
8
|
import React, {useState, useRef, useCallback, useMemo} from 'react';
|
|
10
9
|
import {createPortal} from 'react-dom';
|
|
@@ -16,7 +15,7 @@ import Head from '@docusaurus/Head';
|
|
|
16
15
|
import {isRegexpStringMatch, useSearchPage} from '@docusaurus/theme-common';
|
|
17
16
|
import {DocSearchButton, useDocSearchKeyboardEvents} from '@docsearch/react';
|
|
18
17
|
import {useAlgoliaContextualFacetFilters} from '@docusaurus/theme-search-algolia/client';
|
|
19
|
-
import {translate} from '@docusaurus/Translate';
|
|
18
|
+
import Translate, {translate} from '@docusaurus/Translate';
|
|
20
19
|
import styles from './styles.module.css';
|
|
21
20
|
|
|
22
21
|
import type {
|
|
@@ -35,6 +34,7 @@ type DocSearchProps = Omit<
|
|
|
35
34
|
> & {
|
|
36
35
|
contextualSearch?: string;
|
|
37
36
|
externalUrlRegex?: string;
|
|
37
|
+
searchPagePath: boolean | string;
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
let DocSearchModal: typeof DocSearchModalType | null = null;
|
|
@@ -59,7 +59,11 @@ function ResultsFooter({state, onClose}: ResultsFooterProps) {
|
|
|
59
59
|
|
|
60
60
|
return (
|
|
61
61
|
<Link to={generateSearchPageLink(state.query)} onClick={onClose}>
|
|
62
|
-
|
|
62
|
+
<Translate
|
|
63
|
+
id="theme.SearchBar.seeAll"
|
|
64
|
+
values={{count: state.context.nbHits}}>
|
|
65
|
+
{'See all {count} results'}
|
|
66
|
+
</Translate>
|
|
63
67
|
</Link>
|
|
64
68
|
);
|
|
65
69
|
}
|
|
@@ -71,8 +75,8 @@ type FacetFilters = Required<
|
|
|
71
75
|
function mergeFacetFilters(f1: FacetFilters, f2: FacetFilters): FacetFilters {
|
|
72
76
|
const normalize = (
|
|
73
77
|
f: FacetFilters,
|
|
74
|
-
): readonly string[] | ReadonlyArray<readonly string[]> =>
|
|
75
|
-
f
|
|
78
|
+
): readonly string[] | ReadonlyArray<string | readonly string[]> =>
|
|
79
|
+
typeof f === 'string' ? [f] : f;
|
|
76
80
|
return [...normalize(f1), ...normalize(f2)] as FacetFilters;
|
|
77
81
|
}
|
|
78
82
|
|
|
@@ -116,9 +120,7 @@ function DocSearch({
|
|
|
116
120
|
}
|
|
117
121
|
|
|
118
122
|
return Promise.all([
|
|
119
|
-
// @ts-ignore
|
|
120
123
|
import('@docsearch/react/modal'),
|
|
121
|
-
// @ts-ignore
|
|
122
124
|
import('@docsearch/react/style'),
|
|
123
125
|
import('./styles.css'),
|
|
124
126
|
]).then(([{DocSearchModal: Modal}]) => {
|
|
@@ -167,7 +169,8 @@ function DocSearch({
|
|
|
167
169
|
const transformItems = useRef<DocSearchModalProps['transformItems']>(
|
|
168
170
|
(items) =>
|
|
169
171
|
items.map((item) => {
|
|
170
|
-
// If Algolia contains a external domain, we should navigate without
|
|
172
|
+
// If Algolia contains a external domain, we should navigate without
|
|
173
|
+
// relative URL
|
|
171
174
|
if (isRegexpStringMatch(externalUrlRegex, item.url)) {
|
|
172
175
|
return item;
|
|
173
176
|
}
|
|
@@ -254,8 +257,10 @@ function DocSearch({
|
|
|
254
257
|
navigator={navigator}
|
|
255
258
|
transformItems={transformItems}
|
|
256
259
|
hitComponent={Hit}
|
|
257
|
-
resultsFooterComponent={resultsFooterComponent}
|
|
258
260
|
transformSearchClient={transformSearchClient}
|
|
261
|
+
{...(props.searchPagePath && {
|
|
262
|
+
resultsFooterComponent,
|
|
263
|
+
})}
|
|
259
264
|
{...props}
|
|
260
265
|
searchParameters={searchParameters}
|
|
261
266
|
/>,
|
|
@@ -265,10 +270,7 @@ function DocSearch({
|
|
|
265
270
|
);
|
|
266
271
|
}
|
|
267
272
|
|
|
268
|
-
function SearchBar(): JSX.Element {
|
|
273
|
+
export default function SearchBar(): JSX.Element {
|
|
269
274
|
const {siteConfig} = useDocusaurusContext();
|
|
270
|
-
|
|
271
|
-
return <DocSearch {...siteConfig.themeConfig.algolia} />;
|
|
275
|
+
return <DocSearch {...(siteConfig.themeConfig.algolia as DocSearchProps)} />;
|
|
272
276
|
}
|
|
273
|
-
|
|
274
|
-
export default SearchBar;
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
/* eslint-disable jsx-a11y/no-autofocus */
|
|
9
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
10
9
|
|
|
11
10
|
import React, {useEffect, useState, useReducer, useRef} from 'react';
|
|
12
11
|
|
|
@@ -29,6 +28,7 @@ import {useAllDocsData} from '@docusaurus/plugin-content-docs/client';
|
|
|
29
28
|
import Layout from '@theme/Layout';
|
|
30
29
|
import Translate, {translate} from '@docusaurus/Translate';
|
|
31
30
|
import styles from './styles.module.css';
|
|
31
|
+
import type {ThemeConfig} from '@docusaurus/theme-search-algolia';
|
|
32
32
|
|
|
33
33
|
// Very simple pluralization: probably good enough for now
|
|
34
34
|
function useDocumentsFoundPlural() {
|
|
@@ -149,16 +149,14 @@ type ResultDispatcher =
|
|
|
149
149
|
| {type: 'update'; value: ResultDispatcherState}
|
|
150
150
|
| {type: 'advance'; value?: undefined};
|
|
151
151
|
|
|
152
|
-
function SearchPage(): JSX.Element {
|
|
152
|
+
export default function SearchPage(): JSX.Element {
|
|
153
153
|
const {
|
|
154
|
-
siteConfig: {
|
|
155
|
-
themeConfig: {
|
|
156
|
-
// @ts-ignore
|
|
157
|
-
algolia: {appId, apiKey, indexName, externalUrlRegex},
|
|
158
|
-
},
|
|
159
|
-
},
|
|
154
|
+
siteConfig: {themeConfig},
|
|
160
155
|
i18n: {currentLocale},
|
|
161
156
|
} = useDocusaurusContext();
|
|
157
|
+
const {
|
|
158
|
+
algolia: {appId, apiKey, indexName, externalUrlRegex},
|
|
159
|
+
} = themeConfig as ThemeConfig;
|
|
162
160
|
const documentsFoundPlural = useDocumentsFoundPlural();
|
|
163
161
|
|
|
164
162
|
const docsSearchVersionsHelpers = useDocsSearchVersionsHelpers();
|
|
@@ -518,5 +516,3 @@ function SearchPage(): JSX.Element {
|
|
|
518
516
|
</Layout>
|
|
519
517
|
);
|
|
520
518
|
}
|
|
521
|
-
|
|
522
|
-
export default SearchPage;
|
|
@@ -16,6 +16,7 @@ declare module '@docusaurus/theme-search-algolia' {
|
|
|
16
16
|
apiKey: string;
|
|
17
17
|
indexName: string;
|
|
18
18
|
searchParameters: Record<string, unknown>;
|
|
19
|
+
searchPagePath: string | false | null;
|
|
19
20
|
};
|
|
20
21
|
};
|
|
21
22
|
export type UserThemeConfig = DeepPartial<ThemeConfig>;
|
|
@@ -26,11 +27,9 @@ declare module '@docusaurus/theme-search-algolia/client' {
|
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
declare module '@theme/SearchPage' {
|
|
29
|
-
|
|
30
|
-
export default SearchPage;
|
|
30
|
+
export default function SearchPage(): JSX.Element;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
declare module '@theme/SearchBar' {
|
|
34
|
-
|
|
35
|
-
export default SearchBar;
|
|
34
|
+
export default function SearchBar(): JSX.Element;
|
|
36
35
|
}
|
package/src/types.d.ts
CHANGED
|
@@ -8,7 +8,3 @@
|
|
|
8
8
|
/// <reference types="@docusaurus/module-type-aliases" />
|
|
9
9
|
/// <reference types="@docusaurus/theme-common" />
|
|
10
10
|
/// <reference types="@docusaurus/theme-classic" />
|
|
11
|
-
|
|
12
|
-
export type FacetFilters = Required<
|
|
13
|
-
Required<DocSearchProps>['searchParameters']
|
|
14
|
-
>['facetFilters'];
|
|
@@ -13,11 +13,8 @@ export const DEFAULT_CONFIG = {
|
|
|
13
13
|
// see also https://github.com/facebook/docusaurus/issues/5880
|
|
14
14
|
contextualSearch: true,
|
|
15
15
|
|
|
16
|
-
// By default, all Docusaurus sites are using the same AppId
|
|
17
|
-
// This has been designed on purpose with Algolia.
|
|
18
|
-
appId: 'BH4D9OD16A',
|
|
19
|
-
|
|
20
16
|
searchParameters: {},
|
|
17
|
+
searchPagePath: 'search',
|
|
21
18
|
};
|
|
22
19
|
|
|
23
20
|
export const Schema = Joi.object({
|
|
@@ -26,12 +23,19 @@ export const Schema = Joi.object({
|
|
|
26
23
|
contextualSearch: Joi.boolean().default(DEFAULT_CONFIG.contextualSearch),
|
|
27
24
|
externalUrlRegex: Joi.string().optional(),
|
|
28
25
|
// Algolia attributes
|
|
29
|
-
appId: Joi.string().
|
|
26
|
+
appId: Joi.string().required().messages({
|
|
27
|
+
'any.required':
|
|
28
|
+
'"algolia.appId" is required. If you haven\'t migrated to the new DocSearch infra, please refer to the blog post for instructions: https://docusaurus.io/blog/2021/11/21/algolia-docsearch-migration',
|
|
29
|
+
}),
|
|
30
30
|
apiKey: Joi.string().required(),
|
|
31
31
|
indexName: Joi.string().required(),
|
|
32
32
|
searchParameters: Joi.object()
|
|
33
33
|
.default(DEFAULT_CONFIG.searchParameters)
|
|
34
34
|
.unknown(),
|
|
35
|
+
searchPagePath: Joi.alternatives()
|
|
36
|
+
.try(Joi.boolean().invalid(true), Joi.string())
|
|
37
|
+
.allow(null)
|
|
38
|
+
.default(DEFAULT_CONFIG.searchPagePath),
|
|
35
39
|
})
|
|
36
40
|
.label('themeConfig.algolia')
|
|
37
41
|
.required()
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
/// <reference types="@docusaurus/theme-classic" />
|
|
8
|
-
/// <reference types="react" />
|
|
9
|
-
import type { Props } from '@theme/SearchMetadata';
|
|
10
|
-
declare function SearchMetadata({ locale, version, tag }: Props): JSX.Element;
|
|
11
|
-
export default SearchMetadata;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
import React from 'react';
|
|
8
|
-
import Head from '@docusaurus/Head';
|
|
9
|
-
// Override default/agnostic SearchMetadata to use Algolia-specific metadata
|
|
10
|
-
function SearchMetadata({ locale, version, tag }) {
|
|
11
|
-
// Seems safe to consider here the locale is the language,
|
|
12
|
-
// as the existing docsearch:language filter is afaik a regular string-based filter
|
|
13
|
-
const language = locale;
|
|
14
|
-
return (<Head>
|
|
15
|
-
{language && <meta name="docsearch:language" content={language}/>}
|
|
16
|
-
{version && <meta name="docsearch:version" content={version}/>}
|
|
17
|
-
{tag && <meta name="docsearch:docusaurus_tag" content={tag}/>}
|
|
18
|
-
</Head>);
|
|
19
|
-
}
|
|
20
|
-
export default SearchMetadata;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import React from 'react';
|
|
9
|
-
|
|
10
|
-
import Head from '@docusaurus/Head';
|
|
11
|
-
import type {Props} from '@theme/SearchMetadata';
|
|
12
|
-
|
|
13
|
-
// Override default/agnostic SearchMetadata to use Algolia-specific metadata
|
|
14
|
-
function SearchMetadata({locale, version, tag}: Props): JSX.Element {
|
|
15
|
-
// Seems safe to consider here the locale is the language,
|
|
16
|
-
// as the existing docsearch:language filter is afaik a regular string-based filter
|
|
17
|
-
const language = locale;
|
|
18
|
-
|
|
19
|
-
return (
|
|
20
|
-
<Head>
|
|
21
|
-
{language && <meta name="docsearch:language" content={language} />}
|
|
22
|
-
{version && <meta name="docsearch:version" content={version} />}
|
|
23
|
-
{tag && <meta name="docsearch:docusaurus_tag" content={tag} />}
|
|
24
|
-
</Head>
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export default SearchMetadata;
|