-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Expand file tree
/
Copy pathindex.ts
More file actions
92 lines (81 loc) · 2.5 KB
/
index.ts
File metadata and controls
92 lines (81 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import {normalizeUrl} from '@docusaurus/utils';
import {readDefaultCodeTranslationMessages} from '@docusaurus/theme-translations';
import {
createOpenSearchFile,
createOpenSearchHeadTags,
shouldCreateOpenSearchFile,
} from './opensearch';
import {docSearchV3} from './docSearchVersion';
import type {LoadContext, Plugin} from '@docusaurus/types';
import type {ThemeConfig} from '@docusaurus/theme-search-algolia';
export default function themeSearchAlgolia(context: LoadContext): Plugin<void> {
const {
baseUrl,
siteConfig: {themeConfig},
i18n: {currentLocale},
} = context;
const {
algolia: {searchPagePath},
} = themeConfig as ThemeConfig;
return {
name: 'docusaurus-theme-search-algolia',
getThemePath() {
return '../lib/theme';
},
getTypeScriptThemePath() {
return '../src/theme';
},
getDefaultCodeTranslationMessages() {
return readDefaultCodeTranslationMessages({
locale: currentLocale,
name: 'theme-search-algolia',
});
},
contentLoaded({actions: {addRoute}}) {
if (searchPagePath) {
addRoute({
path: normalizeUrl([baseUrl, searchPagePath]),
component: '@theme/SearchPage',
exact: true,
});
}
},
async postBuild() {
if (shouldCreateOpenSearchFile({context})) {
await createOpenSearchFile({context});
}
},
injectHtmlTags() {
if (shouldCreateOpenSearchFile({context})) {
return {headTags: createOpenSearchHeadTags({context})};
}
return {};
},
configureWebpack() {
// TODO Docusaurus v4: remove after dropping DocSearch v3 support
if (docSearchV3) {
// These aliases ensure DocSearch v3 imports are compatible with
// the newly added DocSearch v4 entry points
// See https://github.com/algolia/docsearch/pull/2764
const docSearchV3Entry = require.resolve('@docsearch/react');
return {
resolve: {
alias: {
'@docsearch/react/version': docSearchV3Entry,
'@docsearch/react/useDocSearchKeyboardEvents': docSearchV3Entry,
'@docsearch/react/useTheme': docSearchV3Entry,
},
},
};
}
return undefined;
},
};
}
export {validateThemeConfig} from './validateThemeConfig';