@docusaurus/theme-search-algolia 0.0.0-4593 → 0.0.0-4597
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/index.js +32 -20
- package/lib/templates/opensearch.d.ts +1 -1
- package/lib/templates/opensearch.js +5 -5
- package/lib/theme/SearchBar/index.js +3 -1
- package/lib/validateThemeConfig.d.ts +1 -0
- package/lib/validateThemeConfig.js +8 -0
- package/package.json +9 -9
- package/src/index.ts +36 -20
- package/src/templates/opensearch.ts +5 -5
- package/src/theme/SearchBar/index.tsx +4 -1
- package/src/theme-search-algolia.d.ts +1 -0
- package/src/validateThemeConfig.ts +5 -0
package/lib/index.js
CHANGED
|
@@ -29,9 +29,12 @@ const OPEN_SEARCH_FILENAME = 'opensearch.xml';
|
|
|
29
29
|
function themeSearchAlgolia(context) {
|
|
30
30
|
const {
|
|
31
31
|
baseUrl,
|
|
32
|
-
siteConfig: {title, url, favicon},
|
|
32
|
+
siteConfig: {title, url, favicon, themeConfig},
|
|
33
33
|
i18n: {currentLocale},
|
|
34
34
|
} = context;
|
|
35
|
+
const {
|
|
36
|
+
algolia: {searchPagePath},
|
|
37
|
+
} = themeConfig;
|
|
35
38
|
return {
|
|
36
39
|
name: 'docusaurus-theme-search-algolia',
|
|
37
40
|
getThemePath() {
|
|
@@ -47,30 +50,39 @@ function themeSearchAlgolia(context) {
|
|
|
47
50
|
});
|
|
48
51
|
},
|
|
49
52
|
async contentLoaded({actions: {addRoute}}) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
if (searchPagePath) {
|
|
54
|
+
addRoute({
|
|
55
|
+
path: (0, utils_1.normalizeUrl)([baseUrl, searchPagePath]),
|
|
56
|
+
component: '@theme/SearchPage',
|
|
57
|
+
exact: true,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
55
60
|
},
|
|
56
61
|
async postBuild({outDir}) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
:
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
62
|
+
if (searchPagePath) {
|
|
63
|
+
const siteUrl = (0, utils_1.normalizeUrl)([url, baseUrl]);
|
|
64
|
+
try {
|
|
65
|
+
fs_1.default.writeFileSync(
|
|
66
|
+
path_1.default.join(outDir, OPEN_SEARCH_FILENAME),
|
|
67
|
+
renderOpenSearchTemplate({
|
|
68
|
+
title,
|
|
69
|
+
siteUrl,
|
|
70
|
+
searchUrl: (0, utils_1.normalizeUrl)([siteUrl, searchPagePath]),
|
|
71
|
+
faviconUrl: favicon
|
|
72
|
+
? (0, utils_1.normalizeUrl)([siteUrl, favicon])
|
|
73
|
+
: null,
|
|
74
|
+
}),
|
|
75
|
+
);
|
|
76
|
+
} catch (e) {
|
|
77
|
+
logger_1.default.error('Generating OpenSearch file failed.');
|
|
78
|
+
throw e;
|
|
79
|
+
}
|
|
71
80
|
}
|
|
72
81
|
},
|
|
73
82
|
injectHtmlTags() {
|
|
83
|
+
if (!searchPagePath) {
|
|
84
|
+
return {};
|
|
85
|
+
}
|
|
74
86
|
return {
|
|
75
87
|
headTags: [
|
|
76
88
|
{
|
|
@@ -4,5 +4,5 @@
|
|
|
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
|
-
declare const _default: "\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<OpenSearchDescription xmlns=\"http://a9.com/-/spec/opensearch/1.1/\"\n xmlns:moz=\"http://www.mozilla.org/2006/browser/search/\">\n <ShortName><%= it.title %></ShortName>\n <Description>Search <%= it.title %></Description>\n <InputEncoding>UTF-8</InputEncoding>\n <% if (it.
|
|
7
|
+
declare const _default: "\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<OpenSearchDescription xmlns=\"http://a9.com/-/spec/opensearch/1.1/\"\n xmlns:moz=\"http://www.mozilla.org/2006/browser/search/\">\n <ShortName><%= it.title %></ShortName>\n <Description>Search <%= it.title %></Description>\n <InputEncoding>UTF-8</InputEncoding>\n <% if (it.faviconUrl) { _%>\n <Image width=\"16\" height=\"16\" type=\"image/x-icon\"><%= it.faviconUrl %></Image>\n <% } _%>\n <Url type=\"text/html\" method=\"get\" template=\"<%= it.searchUrl %>?q={searchTerms}\"/>\n <Url type=\"application/opensearchdescription+xml\" rel=\"self\" template=\"<%= it.siteUrl %>opensearch.xml\" />\n <moz:SearchForm><%= it.siteUrl %></moz:SearchForm>\n</OpenSearchDescription>\n";
|
|
8
8
|
export default _default;
|
|
@@ -13,11 +13,11 @@ exports.default = `
|
|
|
13
13
|
<ShortName><%= it.title %></ShortName>
|
|
14
14
|
<Description>Search <%= it.title %></Description>
|
|
15
15
|
<InputEncoding>UTF-8</InputEncoding>
|
|
16
|
-
<% if (it.
|
|
17
|
-
<Image width="16" height="16" type="image/x-icon"><%= it.
|
|
16
|
+
<% if (it.faviconUrl) { _%>
|
|
17
|
+
<Image width="16" height="16" type="image/x-icon"><%= it.faviconUrl %></Image>
|
|
18
18
|
<% } _%>
|
|
19
|
-
<Url type="text/html" method="get" template="<%= it.
|
|
20
|
-
<Url type="application/opensearchdescription+xml" rel="self" template="<%= it.
|
|
21
|
-
<moz:SearchForm><%= it.
|
|
19
|
+
<Url type="text/html" method="get" template="<%= it.searchUrl %>?q={searchTerms}"/>
|
|
20
|
+
<Url type="application/opensearchdescription+xml" rel="self" template="<%= it.siteUrl %>opensearch.xml" />
|
|
21
|
+
<moz:SearchForm><%= it.siteUrl %></moz:SearchForm>
|
|
22
22
|
</OpenSearchDescription>
|
|
23
23
|
`;
|
|
@@ -194,8 +194,10 @@ function DocSearch({contextualSearch, externalUrlRegex, ...props}) {
|
|
|
194
194
|
navigator={navigator}
|
|
195
195
|
transformItems={transformItems}
|
|
196
196
|
hitComponent={Hit}
|
|
197
|
-
resultsFooterComponent={resultsFooterComponent}
|
|
198
197
|
transformSearchClient={transformSearchClient}
|
|
198
|
+
{...(props.searchPagePath && {
|
|
199
|
+
resultsFooterComponent,
|
|
200
|
+
})}
|
|
199
201
|
{...props}
|
|
200
202
|
searchParameters={searchParameters}
|
|
201
203
|
/>,
|
|
@@ -10,6 +10,7 @@ export declare const DEFAULT_CONFIG: {
|
|
|
10
10
|
contextualSearch: boolean;
|
|
11
11
|
appId: string;
|
|
12
12
|
searchParameters: {};
|
|
13
|
+
searchPagePath: string;
|
|
13
14
|
};
|
|
14
15
|
export declare const Schema: Joi.ObjectSchema<any>;
|
|
15
16
|
export declare function validateThemeConfig({ validate, themeConfig, }: {
|
|
@@ -16,6 +16,7 @@ exports.DEFAULT_CONFIG = {
|
|
|
16
16
|
// This has been designed on purpose with Algolia.
|
|
17
17
|
appId: 'BH4D9OD16A',
|
|
18
18
|
searchParameters: {},
|
|
19
|
+
searchPagePath: 'search',
|
|
19
20
|
};
|
|
20
21
|
exports.Schema = utils_validation_1.Joi.object({
|
|
21
22
|
algolia: utils_validation_1.Joi.object({
|
|
@@ -33,6 +34,13 @@ exports.Schema = utils_validation_1.Joi.object({
|
|
|
33
34
|
searchParameters: utils_validation_1.Joi.object()
|
|
34
35
|
.default(exports.DEFAULT_CONFIG.searchParameters)
|
|
35
36
|
.unknown(),
|
|
37
|
+
searchPagePath: utils_validation_1.Joi.alternatives()
|
|
38
|
+
.try(
|
|
39
|
+
utils_validation_1.Joi.boolean().invalid(true),
|
|
40
|
+
utils_validation_1.Joi.string(),
|
|
41
|
+
)
|
|
42
|
+
.allow(null)
|
|
43
|
+
.default(exports.DEFAULT_CONFIG.searchPagePath),
|
|
36
44
|
})
|
|
37
45
|
.label('themeConfig.algolia')
|
|
38
46
|
.required()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/theme-search-algolia",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4597",
|
|
4
4
|
"description": "Algolia search component for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@docsearch/react": "^3.0.0-alpha.50",
|
|
29
|
-
"@docusaurus/core": "0.0.0-
|
|
30
|
-
"@docusaurus/logger": "0.0.0-
|
|
31
|
-
"@docusaurus/theme-common": "0.0.0-
|
|
32
|
-
"@docusaurus/theme-translations": "0.0.0-
|
|
33
|
-
"@docusaurus/utils": "0.0.0-
|
|
34
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
29
|
+
"@docusaurus/core": "0.0.0-4597",
|
|
30
|
+
"@docusaurus/logger": "0.0.0-4597",
|
|
31
|
+
"@docusaurus/theme-common": "0.0.0-4597",
|
|
32
|
+
"@docusaurus/theme-translations": "0.0.0-4597",
|
|
33
|
+
"@docusaurus/utils": "0.0.0-4597",
|
|
34
|
+
"@docusaurus/utils-validation": "0.0.0-4597",
|
|
35
35
|
"algoliasearch": "^4.12.1",
|
|
36
36
|
"algoliasearch-helper": "^3.7.0",
|
|
37
37
|
"clsx": "^1.1.1",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"utility-types": "^3.10.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
44
|
+
"@docusaurus/module-type-aliases": "0.0.0-4597",
|
|
45
45
|
"fs-extra": "^10.0.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"engines": {
|
|
52
52
|
"node": ">=14"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "635ab60e7cf821111d46dee45baf932c5bf8220f"
|
|
55
55
|
}
|
package/src/index.ts
CHANGED
|
@@ -15,6 +15,7 @@ import openSearchTemplate from './templates/opensearch';
|
|
|
15
15
|
import {memoize} 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
20
|
const getCompiledOpenSearchTemplate = memoize(() =>
|
|
20
21
|
compile(openSearchTemplate.trim()),
|
|
@@ -22,8 +23,9 @@ const getCompiledOpenSearchTemplate = memoize(() =>
|
|
|
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,9 +36,12 @@ 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',
|
|
@@ -57,30 +62,41 @@ export default function themeSearchAlgolia(context: LoadContext): Plugin<void> {
|
|
|
57
62
|
},
|
|
58
63
|
|
|
59
64
|
async contentLoaded({actions: {addRoute}}) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
if (searchPagePath) {
|
|
66
|
+
addRoute({
|
|
67
|
+
path: normalizeUrl([baseUrl, searchPagePath]),
|
|
68
|
+
component: '@theme/SearchPage',
|
|
69
|
+
exact: true,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
65
72
|
},
|
|
66
73
|
|
|
67
74
|
async postBuild({outDir}) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
if (searchPagePath) {
|
|
76
|
+
const siteUrl = normalizeUrl([url, baseUrl]);
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
fs.writeFileSync(
|
|
80
|
+
path.join(outDir, OPEN_SEARCH_FILENAME),
|
|
81
|
+
renderOpenSearchTemplate({
|
|
82
|
+
title,
|
|
83
|
+
siteUrl,
|
|
84
|
+
searchUrl: normalizeUrl([siteUrl, searchPagePath]),
|
|
85
|
+
faviconUrl: favicon ? normalizeUrl([siteUrl, favicon]) : null,
|
|
86
|
+
}),
|
|
87
|
+
);
|
|
88
|
+
} catch (e) {
|
|
89
|
+
logger.error('Generating OpenSearch file failed.');
|
|
90
|
+
throw e;
|
|
91
|
+
}
|
|
80
92
|
}
|
|
81
93
|
},
|
|
82
94
|
|
|
83
95
|
injectHtmlTags() {
|
|
96
|
+
if (!searchPagePath) {
|
|
97
|
+
return {};
|
|
98
|
+
}
|
|
99
|
+
|
|
84
100
|
return {
|
|
85
101
|
headTags: [
|
|
86
102
|
{
|
|
@@ -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
|
`;
|
|
@@ -34,6 +34,7 @@ type DocSearchProps = Omit<
|
|
|
34
34
|
> & {
|
|
35
35
|
contextualSearch?: string;
|
|
36
36
|
externalUrlRegex?: string;
|
|
37
|
+
searchPagePath: boolean | string;
|
|
37
38
|
};
|
|
38
39
|
|
|
39
40
|
let DocSearchModal: typeof DocSearchModalType | null = null;
|
|
@@ -256,8 +257,10 @@ function DocSearch({
|
|
|
256
257
|
navigator={navigator}
|
|
257
258
|
transformItems={transformItems}
|
|
258
259
|
hitComponent={Hit}
|
|
259
|
-
resultsFooterComponent={resultsFooterComponent}
|
|
260
260
|
transformSearchClient={transformSearchClient}
|
|
261
|
+
{...(props.searchPagePath && {
|
|
262
|
+
resultsFooterComponent,
|
|
263
|
+
})}
|
|
261
264
|
{...props}
|
|
262
265
|
searchParameters={searchParameters}
|
|
263
266
|
/>,
|
|
@@ -18,6 +18,7 @@ export const DEFAULT_CONFIG = {
|
|
|
18
18
|
appId: 'BH4D9OD16A',
|
|
19
19
|
|
|
20
20
|
searchParameters: {},
|
|
21
|
+
searchPagePath: 'search',
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
export const Schema = Joi.object({
|
|
@@ -32,6 +33,10 @@ export const Schema = Joi.object({
|
|
|
32
33
|
searchParameters: Joi.object()
|
|
33
34
|
.default(DEFAULT_CONFIG.searchParameters)
|
|
34
35
|
.unknown(),
|
|
36
|
+
searchPagePath: Joi.alternatives()
|
|
37
|
+
.try(Joi.boolean().invalid(true), Joi.string())
|
|
38
|
+
.allow(null)
|
|
39
|
+
.default(DEFAULT_CONFIG.searchPagePath),
|
|
35
40
|
})
|
|
36
41
|
.label('themeConfig.algolia')
|
|
37
42
|
.required()
|