@docusaurus/theme-search-algolia 2.0.0-beta.15d451942 → 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.d.ts +7 -0
- package/lib/client/index.js +7 -0
- package/lib/client/useAlgoliaContextualFacetFilters.d.ts +7 -0
- package/lib/client/useAlgoliaContextualFacetFilters.js +15 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js +109 -0
- package/lib/templates/opensearch.d.ts +8 -0
- package/lib/templates/opensearch.js +23 -0
- package/lib/theme/SearchBar/index.d.ts +8 -0
- package/{src → lib}/theme/SearchBar/index.js +56 -51
- package/lib/theme/SearchBar/styles.css +21 -0
- package/lib/theme/SearchBar/styles.module.css +20 -0
- package/lib/theme/SearchPage/index.d.ts +8 -0
- package/{src → lib}/theme/SearchPage/index.js +85 -126
- package/lib/theme/SearchPage/styles.module.css +119 -0
- package/lib/validateThemeConfig.d.ts +18 -0
- package/lib/validateThemeConfig.js +50 -0
- package/package.json +33 -13
- package/src/client/index.ts +8 -0
- package/src/{theme/hooks/useAlgoliaContextualFacetFilters.js → client/useAlgoliaContextualFacetFilters.ts} +3 -3
- package/src/deps.d.ts +10 -0
- package/src/index.ts +116 -0
- package/src/templates/{opensearch.js → opensearch.ts} +7 -5
- package/src/theme/SearchBar/index.tsx +276 -0
- package/src/theme/SearchPage/index.tsx +518 -0
- package/src/theme/SearchPage/styles.module.css +15 -34
- package/src/theme-search-algolia.d.ts +35 -0
- package/src/types.d.ts +10 -0
- package/src/validateThemeConfig.ts +53 -0
- package/src/__tests__/validateThemeConfig.test.js +0 -121
- package/src/index.js +0 -92
- package/src/theme/SearchMetadatas/index.js +0 -25
- package/src/theme/hooks/useSearchQuery.js +0 -44
- package/src/validateThemeConfig.js +0 -45
|
@@ -4,26 +4,26 @@
|
|
|
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
|
-
|
|
8
7
|
/* eslint-disable jsx-a11y/no-autofocus */
|
|
9
|
-
|
|
10
8
|
import React, {useEffect, useState, useReducer, useRef} from 'react';
|
|
11
|
-
|
|
12
9
|
import algoliaSearch from 'algoliasearch/lite';
|
|
13
10
|
import algoliaSearchHelper from 'algoliasearch-helper';
|
|
14
11
|
import clsx from 'clsx';
|
|
15
|
-
|
|
16
12
|
import Head from '@docusaurus/Head';
|
|
17
13
|
import Link from '@docusaurus/Link';
|
|
18
14
|
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
|
19
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
useTitleFormatter,
|
|
17
|
+
usePluralForm,
|
|
18
|
+
isRegexpStringMatch,
|
|
19
|
+
useDynamicCallback,
|
|
20
|
+
useSearchPage,
|
|
21
|
+
} from '@docusaurus/theme-common';
|
|
20
22
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
21
|
-
import {useAllDocsData} from '@
|
|
22
|
-
import useSearchQuery from '@theme/hooks/useSearchQuery';
|
|
23
|
+
import {useAllDocsData} from '@docusaurus/plugin-content-docs/client';
|
|
23
24
|
import Layout from '@theme/Layout';
|
|
24
25
|
import Translate, {translate} from '@docusaurus/Translate';
|
|
25
26
|
import styles from './styles.module.css';
|
|
26
|
-
|
|
27
27
|
// Very simple pluralization: probably good enough for now
|
|
28
28
|
function useDocumentsFoundPlural() {
|
|
29
29
|
const {selectMessage} = usePluralForm();
|
|
@@ -41,26 +41,25 @@ function useDocumentsFoundPlural() {
|
|
|
41
41
|
),
|
|
42
42
|
);
|
|
43
43
|
}
|
|
44
|
-
|
|
45
44
|
function useDocsSearchVersionsHelpers() {
|
|
46
45
|
const allDocsData = useAllDocsData();
|
|
47
|
-
|
|
48
46
|
// State of the version select menus / algolia facet filters
|
|
49
47
|
// docsPluginId -> versionName map
|
|
50
|
-
const [searchVersions, setSearchVersions] = useState(() =>
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
const [searchVersions, setSearchVersions] = useState(() =>
|
|
49
|
+
Object.entries(allDocsData).reduce(
|
|
50
|
+
(acc, [pluginId, pluginData]) => ({
|
|
51
|
+
...acc,
|
|
52
|
+
[pluginId]: pluginData.versions[0].name,
|
|
53
|
+
}),
|
|
54
|
+
{},
|
|
55
|
+
),
|
|
56
|
+
);
|
|
56
57
|
// Set the value of a single select menu
|
|
57
58
|
const setSearchVersion = (pluginId, searchVersion) =>
|
|
58
59
|
setSearchVersions((s) => ({...s, [pluginId]: searchVersion}));
|
|
59
|
-
|
|
60
60
|
const versioningEnabled = Object.values(allDocsData).some(
|
|
61
61
|
(docsData) => docsData.versions.length > 1,
|
|
62
62
|
);
|
|
63
|
-
|
|
64
63
|
return {
|
|
65
64
|
allDocsData,
|
|
66
65
|
versioningEnabled,
|
|
@@ -68,15 +67,13 @@ function useDocsSearchVersionsHelpers() {
|
|
|
68
67
|
setSearchVersion,
|
|
69
68
|
};
|
|
70
69
|
}
|
|
71
|
-
|
|
72
70
|
// We want to display one select per versioned docs plugin instance
|
|
73
|
-
|
|
71
|
+
function SearchVersionSelectList({docsSearchVersionsHelpers}) {
|
|
74
72
|
const versionedPluginEntries = Object.entries(
|
|
75
73
|
docsSearchVersionsHelpers.allDocsData,
|
|
76
74
|
)
|
|
77
75
|
// Do not show a version select for unversioned docs plugin instances
|
|
78
76
|
.filter(([, docsData]) => docsData.versions.length > 1);
|
|
79
|
-
|
|
80
77
|
return (
|
|
81
78
|
<div
|
|
82
79
|
className={clsx(
|
|
@@ -111,22 +108,18 @@ const SearchVersionSelectList = ({docsSearchVersionsHelpers}) => {
|
|
|
111
108
|
})}
|
|
112
109
|
</div>
|
|
113
110
|
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function SearchPage() {
|
|
111
|
+
}
|
|
112
|
+
export default function SearchPage() {
|
|
117
113
|
const {
|
|
118
|
-
siteConfig: {
|
|
119
|
-
themeConfig: {
|
|
120
|
-
algolia: {appId, apiKey, indexName},
|
|
121
|
-
},
|
|
122
|
-
},
|
|
114
|
+
siteConfig: {themeConfig},
|
|
123
115
|
i18n: {currentLocale},
|
|
124
116
|
} = useDocusaurusContext();
|
|
117
|
+
const {
|
|
118
|
+
algolia: {appId, apiKey, indexName, externalUrlRegex},
|
|
119
|
+
} = themeConfig;
|
|
125
120
|
const documentsFoundPlural = useDocumentsFoundPlural();
|
|
126
|
-
|
|
127
121
|
const docsSearchVersionsHelpers = useDocsSearchVersionsHelpers();
|
|
128
|
-
const {
|
|
129
|
-
const [searchQuery, setSearchQuery] = useState(searchValue);
|
|
122
|
+
const {searchQuery, setSearchQuery} = useSearchPage();
|
|
130
123
|
const initialSearchResultState = {
|
|
131
124
|
items: [],
|
|
132
125
|
query: null,
|
|
@@ -137,8 +130,8 @@ function SearchPage() {
|
|
|
137
130
|
loading: null,
|
|
138
131
|
};
|
|
139
132
|
const [searchResultState, searchResultStateDispatcher] = useReducer(
|
|
140
|
-
(prevState,
|
|
141
|
-
switch (type) {
|
|
133
|
+
(prevState, data) => {
|
|
134
|
+
switch (data.type) {
|
|
142
135
|
case 'reset': {
|
|
143
136
|
return initialSearchResultState;
|
|
144
137
|
}
|
|
@@ -146,21 +139,19 @@ function SearchPage() {
|
|
|
146
139
|
return {...prevState, loading: true};
|
|
147
140
|
}
|
|
148
141
|
case 'update': {
|
|
149
|
-
if (searchQuery !==
|
|
142
|
+
if (searchQuery !== data.value.query) {
|
|
150
143
|
return prevState;
|
|
151
144
|
}
|
|
152
|
-
|
|
153
145
|
return {
|
|
154
|
-
...
|
|
146
|
+
...data.value,
|
|
155
147
|
items:
|
|
156
|
-
|
|
157
|
-
?
|
|
158
|
-
: prevState.items.concat(
|
|
148
|
+
data.value.lastPage === 0
|
|
149
|
+
? data.value.items
|
|
150
|
+
: prevState.items.concat(data.value.items),
|
|
159
151
|
};
|
|
160
152
|
}
|
|
161
153
|
case 'advance': {
|
|
162
154
|
const hasMore = prevState.totalPages > prevState.lastPage + 1;
|
|
163
|
-
|
|
164
155
|
return {
|
|
165
156
|
...prevState,
|
|
166
157
|
lastPage: hasMore ? prevState.lastPage + 1 : prevState.lastPage,
|
|
@@ -179,7 +170,6 @@ function SearchPage() {
|
|
|
179
170
|
advancedSyntax: true,
|
|
180
171
|
disjunctiveFacets: ['language', 'docusaurus_tag'],
|
|
181
172
|
});
|
|
182
|
-
|
|
183
173
|
algoliaHelper.on(
|
|
184
174
|
'result',
|
|
185
175
|
({results: {query, hits, page, nbHits, nbPages}}) => {
|
|
@@ -187,28 +177,26 @@ function SearchPage() {
|
|
|
187
177
|
searchResultStateDispatcher({type: 'reset'});
|
|
188
178
|
return;
|
|
189
179
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
return value.replace(
|
|
180
|
+
const sanitizeValue = (value) =>
|
|
181
|
+
value.replace(
|
|
193
182
|
/algolia-docsearch-suggestion--highlight/g,
|
|
194
183
|
'search-result-match',
|
|
195
184
|
);
|
|
196
|
-
};
|
|
197
|
-
|
|
198
185
|
const items = hits.map(
|
|
199
186
|
({
|
|
200
187
|
url,
|
|
201
188
|
_highlightResult: {hierarchy},
|
|
202
189
|
_snippetResult: snippet = {},
|
|
203
190
|
}) => {
|
|
204
|
-
const
|
|
205
|
-
const titles = Object.keys(hierarchy).map((key) =>
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
191
|
+
const parsedURL = new URL(url);
|
|
192
|
+
const titles = Object.keys(hierarchy).map((key) =>
|
|
193
|
+
sanitizeValue(hierarchy[key].value),
|
|
194
|
+
);
|
|
209
195
|
return {
|
|
210
196
|
title: titles.pop(),
|
|
211
|
-
url:
|
|
197
|
+
url: isRegexpStringMatch(externalUrlRegex, parsedURL.href)
|
|
198
|
+
? parsedURL.href
|
|
199
|
+
: parsedURL.pathname + parsedURL.hash,
|
|
212
200
|
summary: snippet.content
|
|
213
201
|
? `${sanitizeValue(snippet.content.value)}...`
|
|
214
202
|
: '',
|
|
@@ -216,7 +204,6 @@ function SearchPage() {
|
|
|
216
204
|
};
|
|
217
205
|
},
|
|
218
206
|
);
|
|
219
|
-
|
|
220
207
|
searchResultStateDispatcher({
|
|
221
208
|
type: 'update',
|
|
222
209
|
value: {
|
|
@@ -231,7 +218,6 @@ function SearchPage() {
|
|
|
231
218
|
});
|
|
232
219
|
},
|
|
233
220
|
);
|
|
234
|
-
|
|
235
221
|
const [loaderRef, setLoaderRef] = useState(null);
|
|
236
222
|
const prevY = useRef(0);
|
|
237
223
|
const observer = useRef(
|
|
@@ -242,17 +228,14 @@ function SearchPage() {
|
|
|
242
228
|
isIntersecting,
|
|
243
229
|
boundingClientRect: {y: currentY},
|
|
244
230
|
} = entries[0];
|
|
245
|
-
|
|
246
231
|
if (isIntersecting && prevY.current > currentY) {
|
|
247
232
|
searchResultStateDispatcher({type: 'advance'});
|
|
248
233
|
}
|
|
249
|
-
|
|
250
234
|
prevY.current = currentY;
|
|
251
235
|
},
|
|
252
236
|
{threshold: 1},
|
|
253
237
|
),
|
|
254
238
|
);
|
|
255
|
-
|
|
256
239
|
const getTitle = () =>
|
|
257
240
|
searchQuery
|
|
258
241
|
? translate(
|
|
@@ -270,11 +253,9 @@ function SearchPage() {
|
|
|
270
253
|
message: 'Search the documentation',
|
|
271
254
|
description: 'The search page title for empty query',
|
|
272
255
|
});
|
|
273
|
-
|
|
274
|
-
const makeSearch = (page = 0) => {
|
|
256
|
+
const makeSearch = useDynamicCallback((page = 0) => {
|
|
275
257
|
algoliaHelper.addDisjunctiveFacetRefinement('docusaurus_tag', 'default');
|
|
276
258
|
algoliaHelper.addDisjunctiveFacetRefinement('language', currentLocale);
|
|
277
|
-
|
|
278
259
|
Object.entries(docsSearchVersionsHelpers.searchVersions).forEach(
|
|
279
260
|
([pluginId, searchVersion]) => {
|
|
280
261
|
algoliaHelper.addDisjunctiveFacetRefinement(
|
|
@@ -283,50 +264,34 @@ function SearchPage() {
|
|
|
283
264
|
);
|
|
284
265
|
},
|
|
285
266
|
);
|
|
286
|
-
|
|
287
267
|
algoliaHelper.setQuery(searchQuery).setPage(page).search();
|
|
288
|
-
};
|
|
289
|
-
|
|
268
|
+
});
|
|
290
269
|
useEffect(() => {
|
|
291
270
|
if (!loaderRef) {
|
|
292
271
|
return undefined;
|
|
293
272
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
273
|
+
const currentObserver = observer.current;
|
|
274
|
+
if (currentObserver) {
|
|
275
|
+
currentObserver.observe(loaderRef);
|
|
276
|
+
return () => currentObserver.unobserve(loaderRef);
|
|
277
|
+
}
|
|
278
|
+
return () => true;
|
|
300
279
|
}, [loaderRef]);
|
|
301
|
-
|
|
302
280
|
useEffect(() => {
|
|
303
|
-
updateSearchPath(searchQuery);
|
|
304
|
-
|
|
305
281
|
searchResultStateDispatcher({type: 'reset'});
|
|
306
|
-
|
|
307
282
|
if (searchQuery) {
|
|
308
283
|
searchResultStateDispatcher({type: 'loading'});
|
|
309
|
-
|
|
310
284
|
setTimeout(() => {
|
|
311
285
|
makeSearch();
|
|
312
286
|
}, 300);
|
|
313
287
|
}
|
|
314
|
-
}, [searchQuery, docsSearchVersionsHelpers.searchVersions]);
|
|
315
|
-
|
|
288
|
+
}, [searchQuery, docsSearchVersionsHelpers.searchVersions, makeSearch]);
|
|
316
289
|
useEffect(() => {
|
|
317
290
|
if (!searchResultState.lastPage || searchResultState.lastPage === 0) {
|
|
318
291
|
return;
|
|
319
292
|
}
|
|
320
|
-
|
|
321
293
|
makeSearch(searchResultState.lastPage);
|
|
322
|
-
}, [searchResultState.lastPage]);
|
|
323
|
-
|
|
324
|
-
useEffect(() => {
|
|
325
|
-
if (searchValue && searchValue !== searchQuery) {
|
|
326
|
-
setSearchQuery(searchValue);
|
|
327
|
-
}
|
|
328
|
-
}, [searchValue]);
|
|
329
|
-
|
|
294
|
+
}, [makeSearch, searchResultState.lastPage]);
|
|
330
295
|
return (
|
|
331
296
|
<Layout wrapperClassName="search-page-wrapper">
|
|
332
297
|
<Head>
|
|
@@ -375,16 +340,19 @@ function SearchPage() {
|
|
|
375
340
|
)}
|
|
376
341
|
</form>
|
|
377
342
|
|
|
378
|
-
<div className=
|
|
343
|
+
<div className="row">
|
|
379
344
|
<div className={clsx('col', 'col--8', styles.searchResultsColumn)}>
|
|
380
|
-
{!!searchResultState.totalResults &&
|
|
381
|
-
|
|
382
|
-
{documentsFoundPlural(searchResultState.totalResults)}
|
|
383
|
-
</strong>
|
|
384
|
-
)}
|
|
345
|
+
{!!searchResultState.totalResults &&
|
|
346
|
+
documentsFoundPlural(searchResultState.totalResults)}
|
|
385
347
|
</div>
|
|
386
348
|
|
|
387
|
-
<div
|
|
349
|
+
<div
|
|
350
|
+
className={clsx(
|
|
351
|
+
'col',
|
|
352
|
+
'col--4',
|
|
353
|
+
'text--right',
|
|
354
|
+
styles.searchLogoColumn,
|
|
355
|
+
)}>
|
|
388
356
|
<a
|
|
389
357
|
target="_blank"
|
|
390
358
|
rel="noopener noreferrer"
|
|
@@ -394,10 +362,7 @@ function SearchPage() {
|
|
|
394
362
|
message: 'Search by Algolia',
|
|
395
363
|
description: 'The ARIA label for Algolia mention',
|
|
396
364
|
})}>
|
|
397
|
-
<svg
|
|
398
|
-
viewBox="0 0 168 24"
|
|
399
|
-
className={styles.algoliaLogo}
|
|
400
|
-
xmlns="http://www.w3.org/2000/svg">
|
|
365
|
+
<svg viewBox="0 0 168 24" className={styles.algoliaLogo}>
|
|
401
366
|
<g fill="none">
|
|
402
367
|
<path
|
|
403
368
|
className={styles.algoliaLogoPathFill}
|
|
@@ -418,34 +383,32 @@ function SearchPage() {
|
|
|
418
383
|
</div>
|
|
419
384
|
|
|
420
385
|
{searchResultState.items.length > 0 ? (
|
|
421
|
-
<
|
|
386
|
+
<main>
|
|
422
387
|
{searchResultState.items.map(
|
|
423
388
|
({title, url, summary, breadcrumbs}, i) => (
|
|
424
389
|
<article key={i} className={styles.searchResultItem}>
|
|
425
|
-
<
|
|
426
|
-
to={url}
|
|
427
|
-
|
|
428
|
-
dangerouslySetInnerHTML={{__html: title}}
|
|
429
|
-
/>
|
|
390
|
+
<h2 className={styles.searchResultItemHeading}>
|
|
391
|
+
<Link to={url} dangerouslySetInnerHTML={{__html: title}} />
|
|
392
|
+
</h2>
|
|
430
393
|
|
|
431
394
|
{breadcrumbs.length > 0 && (
|
|
432
|
-
<
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
395
|
+
<nav aria-label="breadcrumbs">
|
|
396
|
+
<ul
|
|
397
|
+
className={clsx(
|
|
398
|
+
'breadcrumbs',
|
|
399
|
+
styles.searchResultItemPath,
|
|
400
|
+
)}>
|
|
401
|
+
{breadcrumbs.map((html, index) => (
|
|
402
|
+
<li
|
|
403
|
+
key={index}
|
|
404
|
+
className="breadcrumbs__item"
|
|
442
405
|
// Developer provided the HTML, so assume it's safe.
|
|
443
406
|
// eslint-disable-next-line react/no-danger
|
|
444
407
|
dangerouslySetInnerHTML={{__html: html}}
|
|
445
408
|
/>
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
</
|
|
409
|
+
))}
|
|
410
|
+
</ul>
|
|
411
|
+
</nav>
|
|
449
412
|
)}
|
|
450
413
|
|
|
451
414
|
{summary && (
|
|
@@ -459,7 +422,7 @@ function SearchPage() {
|
|
|
459
422
|
</article>
|
|
460
423
|
),
|
|
461
424
|
)}
|
|
462
|
-
</
|
|
425
|
+
</main>
|
|
463
426
|
) : (
|
|
464
427
|
[
|
|
465
428
|
searchQuery && !searchResultState.loading && (
|
|
@@ -479,18 +442,14 @@ function SearchPage() {
|
|
|
479
442
|
|
|
480
443
|
{searchResultState.hasMore && (
|
|
481
444
|
<div className={styles.loader} ref={setLoaderRef}>
|
|
482
|
-
<
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
</Translate>
|
|
488
|
-
</span>
|
|
445
|
+
<Translate
|
|
446
|
+
id="theme.SearchPage.fetchingNewResults"
|
|
447
|
+
description="The paragraph for fetching new search results">
|
|
448
|
+
Fetching new results...
|
|
449
|
+
</Translate>
|
|
489
450
|
</div>
|
|
490
451
|
)}
|
|
491
452
|
</div>
|
|
492
453
|
</Layout>
|
|
493
454
|
);
|
|
494
455
|
}
|
|
495
|
-
|
|
496
|
-
export default SearchPage;
|
|
@@ -0,0 +1,119 @@
|
|
|
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
|
+
.searchQueryInput,
|
|
9
|
+
.searchVersionInput {
|
|
10
|
+
border-radius: var(--ifm-global-radius);
|
|
11
|
+
border: 2px solid var(--ifm-toc-border-color);
|
|
12
|
+
font: var(--ifm-font-size-base) var(--ifm-font-family-base);
|
|
13
|
+
padding: 0.8rem;
|
|
14
|
+
width: 100%;
|
|
15
|
+
background: var(--docsearch-searchbox-focus-background);
|
|
16
|
+
color: var(--docsearch-text-color);
|
|
17
|
+
margin-bottom: 0.5rem;
|
|
18
|
+
transition: border var(--ifm-transition-fast) ease;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.searchQueryInput:focus,
|
|
22
|
+
.searchVersionInput:focus {
|
|
23
|
+
border-color: var(--docsearch-primary-color);
|
|
24
|
+
outline: none;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.searchQueryInput::placeholder {
|
|
28
|
+
color: var(--docsearch-muted-color);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.searchResultsColumn {
|
|
32
|
+
font-size: 0.9rem;
|
|
33
|
+
font-weight: bold;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.algoliaLogo {
|
|
37
|
+
max-width: 150px;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.algoliaLogoPathFill {
|
|
41
|
+
fill: var(--ifm-font-color-base);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.searchResultItem {
|
|
45
|
+
padding: 1rem 0;
|
|
46
|
+
border-bottom: 1px solid var(--ifm-toc-border-color);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.searchResultItemHeading {
|
|
50
|
+
font-weight: 400;
|
|
51
|
+
margin-bottom: 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.searchResultItemPath {
|
|
55
|
+
font-size: 0.8rem;
|
|
56
|
+
color: var(--ifm-color-content-secondary);
|
|
57
|
+
--ifm-breadcrumb-separator-size-multiplier: 1;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.searchResultItemSummary {
|
|
61
|
+
margin: 0.5rem 0 0;
|
|
62
|
+
font-style: italic;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@media only screen and (max-width: 996px) {
|
|
66
|
+
.searchQueryColumn {
|
|
67
|
+
max-width: 60% !important;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.searchVersionColumn {
|
|
71
|
+
max-width: 40% !important;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.searchResultsColumn {
|
|
75
|
+
max-width: 60% !important;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.searchLogoColumn {
|
|
79
|
+
max-width: 40% !important;
|
|
80
|
+
padding-left: 0 !important;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@media screen and (max-width: 576px) {
|
|
85
|
+
.searchQueryColumn {
|
|
86
|
+
max-width: 100% !important;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.searchVersionColumn {
|
|
90
|
+
max-width: 100% !important;
|
|
91
|
+
padding-left: var(--ifm-spacing-horizontal) !important;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.loadingSpinner {
|
|
96
|
+
width: 3rem;
|
|
97
|
+
height: 3rem;
|
|
98
|
+
border: 0.4em solid #eee;
|
|
99
|
+
border-top-color: var(--ifm-color-primary);
|
|
100
|
+
border-radius: 50%;
|
|
101
|
+
animation: loading-spin 1s linear infinite;
|
|
102
|
+
margin: 0 auto;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@keyframes loading-spin {
|
|
106
|
+
100% {
|
|
107
|
+
transform: rotate(360deg);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.loader {
|
|
112
|
+
margin-top: 2rem;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
:global(.search-result-match) {
|
|
116
|
+
color: var(--docsearch-hit-color);
|
|
117
|
+
background: rgb(255 215 142 / 25%);
|
|
118
|
+
padding: 0.09em 0;
|
|
119
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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 { Joi } from '@docusaurus/utils-validation';
|
|
8
|
+
import type { ThemeConfig, Validate, ValidationResult } from '@docusaurus/types';
|
|
9
|
+
export declare const DEFAULT_CONFIG: {
|
|
10
|
+
contextualSearch: boolean;
|
|
11
|
+
searchParameters: {};
|
|
12
|
+
searchPagePath: string;
|
|
13
|
+
};
|
|
14
|
+
export declare const Schema: Joi.ObjectSchema<any>;
|
|
15
|
+
export declare function validateThemeConfig({ validate, themeConfig, }: {
|
|
16
|
+
validate: Validate<ThemeConfig>;
|
|
17
|
+
themeConfig: ThemeConfig;
|
|
18
|
+
}): ValidationResult<ThemeConfig>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, '__esModule', {value: true});
|
|
9
|
+
exports.validateThemeConfig = exports.Schema = exports.DEFAULT_CONFIG = void 0;
|
|
10
|
+
const utils_validation_1 = require('@docusaurus/utils-validation');
|
|
11
|
+
exports.DEFAULT_CONFIG = {
|
|
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',
|
|
17
|
+
};
|
|
18
|
+
exports.Schema = utils_validation_1.Joi.object({
|
|
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
|
|
46
|
+
});
|
|
47
|
+
function validateThemeConfig({validate, themeConfig}) {
|
|
48
|
+
return validate(exports.Schema, themeConfig);
|
|
49
|
+
}
|
|
50
|
+
exports.validateThemeConfig = validateThemeConfig;
|
package/package.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
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
|
-
"main": "
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
"./client": "./lib/client/index.js",
|
|
8
|
+
".": "./lib/index.js"
|
|
9
|
+
},
|
|
10
|
+
"types": "src/theme-search-algolia.d.ts",
|
|
6
11
|
"publishConfig": {
|
|
7
12
|
"access": "public"
|
|
8
13
|
},
|
|
@@ -12,24 +17,39 @@
|
|
|
12
17
|
"directory": "packages/docusaurus-theme-search-algolia"
|
|
13
18
|
},
|
|
14
19
|
"license": "MIT",
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "yarn build:server && yarn build:client && yarn build:copy && yarn build:format",
|
|
22
|
+
"build:server": "tsc --project tsconfig.server.json",
|
|
23
|
+
"build:client": "tsc --project tsconfig.client.json",
|
|
24
|
+
"build:copy": "node copyUntypedFiles.mjs",
|
|
25
|
+
"build:format": "prettier --config ../../.prettierrc --write \"lib/**/*.js\""
|
|
26
|
+
},
|
|
15
27
|
"dependencies": {
|
|
16
|
-
"@docsearch/react": "^3.0.0
|
|
17
|
-
"@docusaurus/core": "2.0.0-beta.
|
|
18
|
-
"@docusaurus/
|
|
19
|
-
"@docusaurus/
|
|
20
|
-
"@docusaurus/
|
|
21
|
-
"
|
|
22
|
-
"
|
|
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",
|
|
23
37
|
"clsx": "^1.1.1",
|
|
24
|
-
"eta": "^1.12.
|
|
25
|
-
"
|
|
38
|
+
"eta": "^1.12.3",
|
|
39
|
+
"fs-extra": "^10.0.1",
|
|
40
|
+
"lodash": "^4.17.21",
|
|
41
|
+
"tslib": "^2.3.1",
|
|
42
|
+
"utility-types": "^3.10.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@docusaurus/module-type-aliases": "2.0.0-beta.16"
|
|
26
46
|
},
|
|
27
47
|
"peerDependencies": {
|
|
28
48
|
"react": "^16.8.4 || ^17.0.0",
|
|
29
49
|
"react-dom": "^16.8.4 || ^17.0.0"
|
|
30
50
|
},
|
|
31
51
|
"engines": {
|
|
32
|
-
"node": ">=
|
|
52
|
+
"node": ">=14"
|
|
33
53
|
},
|
|
34
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "eb43c4d4f95a4fb97dc9bb9dc615413e0dc2e1e7"
|
|
35
55
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
export {useAlgoliaContextualFacetFilters} from './useAlgoliaContextualFacetFilters';
|