@docusaurus/theme-search-algolia 0.0.0-4594 → 0.0.0-4602

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 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
- addRoute({
51
- path: (0, utils_1.normalizeUrl)([baseUrl, 'search']),
52
- component: '@theme/SearchPage',
53
- exact: true,
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
- try {
58
- fs_1.default.writeFileSync(
59
- path_1.default.join(outDir, OPEN_SEARCH_FILENAME),
60
- renderOpenSearchTemplate({
61
- title,
62
- url: url + baseUrl,
63
- favicon: favicon
64
- ? (0, utils_1.normalizeUrl)([url, baseUrl, favicon])
65
- : null,
66
- }),
67
- );
68
- } catch (e) {
69
- logger_1.default.error('Generating OpenSearch file failed.');
70
- throw e;
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.favicon) { _%>\n <Image width=\"16\" height=\"16\" type=\"image/x-icon\"><%= it.favicon %></Image>\n <% } _%>\n <Url type=\"text/html\" method=\"get\" template=\"<%= it.url %>search?q={searchTerms}\"/>\n <Url type=\"application/opensearchdescription+xml\" rel=\"self\" template=\"<%= it.url %>opensearch.xml\" />\n <moz:SearchForm><%= it.url %></moz:SearchForm>\n</OpenSearchDescription>\n";
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.favicon) { _%>
17
- <Image width="16" height="16" type="image/x-icon"><%= it.favicon %></Image>
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.url %>search?q={searchTerms}"/>
20
- <Url type="application/opensearchdescription+xml" rel="self" template="<%= it.url %>opensearch.xml" />
21
- <moz:SearchForm><%= it.url %></moz:SearchForm>
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-4594",
3
+ "version": "0.0.0-4602",
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-4594",
30
- "@docusaurus/logger": "0.0.0-4594",
31
- "@docusaurus/theme-common": "0.0.0-4594",
32
- "@docusaurus/theme-translations": "0.0.0-4594",
33
- "@docusaurus/utils": "0.0.0-4594",
34
- "@docusaurus/utils-validation": "0.0.0-4594",
29
+ "@docusaurus/core": "0.0.0-4602",
30
+ "@docusaurus/logger": "0.0.0-4602",
31
+ "@docusaurus/theme-common": "0.0.0-4602",
32
+ "@docusaurus/theme-translations": "0.0.0-4602",
33
+ "@docusaurus/utils": "0.0.0-4602",
34
+ "@docusaurus/utils-validation": "0.0.0-4602",
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-4594",
44
+ "@docusaurus/module-type-aliases": "0.0.0-4602",
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": "877ac1ede73b4b1da7e536afb8fc3718f50f7c5a"
54
+ "gitHead": "5f89abf1d9b54116c27d696334ceb3e898531268"
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
- url: string;
26
- favicon: string | null;
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
- addRoute({
61
- path: normalizeUrl([baseUrl, 'search']),
62
- component: '@theme/SearchPage',
63
- exact: true,
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
- try {
69
- fs.writeFileSync(
70
- path.join(outDir, OPEN_SEARCH_FILENAME),
71
- renderOpenSearchTemplate({
72
- title,
73
- url: url + baseUrl,
74
- favicon: favicon ? normalizeUrl([url, baseUrl, favicon]) : null,
75
- }),
76
- );
77
- } catch (e) {
78
- logger.error('Generating OpenSearch file failed.');
79
- throw e;
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.favicon) { _%>
16
- <Image width="16" height="16" type="image/x-icon"><%= it.favicon %></Image>
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.url %>search?q={searchTerms}"/>
19
- <Url type="application/opensearchdescription+xml" rel="self" template="<%= it.url %>opensearch.xml" />
20
- <moz:SearchForm><%= it.url %></moz:SearchForm>
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
  />,
@@ -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>;
@@ -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()
@@ -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,22 +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, as the existing
12
- // docsearch:language filter is afaik a regular string-based filter
13
- const language = locale;
14
- return (
15
- <Head>
16
- {language && <meta name="docsearch:language" content={language} />}
17
- {version && <meta name="docsearch:version" content={version} />}
18
- {tag && <meta name="docsearch:docusaurus_tag" content={tag} />}
19
- </Head>
20
- );
21
- }
22
- 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, as the existing
16
- // 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;