@azerion/bunosaurus-theme-search-algolia 0.0.0-stage → 4.0.0
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/README.md +6 -2
- package/lib/client/index.d.ts +12 -0
- package/lib/client/index.js +12 -0
- package/lib/client/searchPage.d.ts +14 -0
- package/lib/client/searchPage.js +29 -0
- package/lib/client/useAlgoliaAskAi.d.ts +32 -0
- package/lib/client/useAlgoliaAskAi.js +59 -0
- package/lib/client/useAlgoliaContextualFacetFilters.d.ts +9 -0
- package/lib/client/useAlgoliaContextualFacetFilters.js +34 -0
- package/lib/client/useAlgoliaThemeConfig.d.ts +2 -0
- package/lib/client/useAlgoliaThemeConfig.js +11 -0
- package/lib/client/useSearchResultUrlProcessor.d.ts +11 -0
- package/lib/client/useSearchResultUrlProcessor.js +33 -0
- package/lib/client/utils.d.ts +9 -0
- package/lib/client/utils.js +21 -0
- package/lib/docSearchVersion.d.ts +7 -0
- package/lib/docSearchVersion.js +13 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js +74 -0
- package/lib/opensearch.d.ts +16 -0
- package/lib/opensearch.js +66 -0
- package/lib/templates/opensearch.d.ts +8 -0
- package/lib/templates/opensearch.js +23 -0
- package/lib/theme/SearchBar/index.d.ts +24 -0
- package/lib/theme/SearchBar/index.js +231 -0
- package/lib/theme/SearchBar/styles.css +25 -0
- package/lib/theme/SearchPage/index.d.ts +8 -0
- package/lib/theme/SearchPage/index.js +518 -0
- package/lib/theme/SearchPage/styles.module.css +127 -0
- package/lib/theme/SearchTranslations/index.d.ts +58 -0
- package/lib/theme/SearchTranslations/index.js +322 -0
- package/lib/validateThemeConfig.d.ts +14 -0
- package/lib/validateThemeConfig.js +124 -0
- package/package.json +64 -4
- package/src/client/index.ts +16 -0
- package/src/client/searchPage.ts +43 -0
- package/src/client/useAlgoliaAskAi.ts +108 -0
- package/src/client/useAlgoliaContextualFacetFilters.ts +45 -0
- package/src/client/useAlgoliaThemeConfig.ts +15 -0
- package/src/client/useSearchResultUrlProcessor.ts +54 -0
- package/src/client/utils.ts +40 -0
- package/src/deps.d.ts +10 -0
- package/src/docSearchVersion.ts +12 -0
- package/src/index.ts +92 -0
- package/src/opensearch.ts +117 -0
- package/src/templates/opensearch.ts +22 -0
- package/src/theme/SearchBar/index.tsx +323 -0
- package/src/theme/SearchBar/styles.css +25 -0
- package/src/theme/SearchPage/index.tsx +588 -0
- package/src/theme/SearchPage/styles.module.css +127 -0
- package/src/theme/SearchTranslations/index.ts +377 -0
- package/src/theme-search-algolia.d.ts +109 -0
- package/src/types.d.ts +10 -0
- package/src/validateThemeConfig.ts +151 -0
package/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@docusaurus/theme-search-algolia`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Algolia search component for Docusaurus.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
See [`@docusaurus/theme-search-algolia` documentation](https://docusaurus.io/docs/api/themes/@docusaurus/theme-search-algolia).
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
export { useAlgoliaThemeConfig } from './useAlgoliaThemeConfig';
|
|
8
|
+
export { useAlgoliaContextualFacetFilters, useAlgoliaContextualFacetFiltersIfEnabled, } from './useAlgoliaContextualFacetFilters';
|
|
9
|
+
export { useSearchResultUrlProcessor } from './useSearchResultUrlProcessor';
|
|
10
|
+
export { useAlgoliaAskAi } from './useAlgoliaAskAi';
|
|
11
|
+
export { useSearchQueryString, useSearchLinkCreator } from './searchPage';
|
|
12
|
+
export { mergeFacetFilters } from './utils';
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
export { useAlgoliaThemeConfig } from './useAlgoliaThemeConfig';
|
|
8
|
+
export { useAlgoliaContextualFacetFilters, useAlgoliaContextualFacetFiltersIfEnabled, } from './useAlgoliaContextualFacetFilters';
|
|
9
|
+
export { useSearchResultUrlProcessor } from './useSearchResultUrlProcessor';
|
|
10
|
+
export { useAlgoliaAskAi } from './useAlgoliaAskAi';
|
|
11
|
+
export { useSearchQueryString, useSearchLinkCreator } from './searchPage';
|
|
12
|
+
export { mergeFacetFilters } from './utils';
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
* Permits to read/write the current search query string
|
|
9
|
+
*/
|
|
10
|
+
export declare function useSearchQueryString(): [string, (newValue: string) => void];
|
|
11
|
+
/**
|
|
12
|
+
* Permits to create links to the search page with the appropriate query string
|
|
13
|
+
*/
|
|
14
|
+
export declare function useSearchLinkCreator(): (searchValue: string) => string;
|
|
@@ -0,0 +1,29 @@
|
|
|
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 { useCallback } from 'react';
|
|
8
|
+
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
9
|
+
import { useQueryString } from '@docusaurus/theme-common';
|
|
10
|
+
import { useAlgoliaThemeConfig } from './useAlgoliaThemeConfig';
|
|
11
|
+
const SEARCH_PARAM_QUERY = 'q';
|
|
12
|
+
/**
|
|
13
|
+
* Permits to read/write the current search query string
|
|
14
|
+
*/
|
|
15
|
+
export function useSearchQueryString() {
|
|
16
|
+
return useQueryString(SEARCH_PARAM_QUERY);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Permits to create links to the search page with the appropriate query string
|
|
20
|
+
*/
|
|
21
|
+
export function useSearchLinkCreator() {
|
|
22
|
+
const { siteConfig: { baseUrl }, } = useDocusaurusContext();
|
|
23
|
+
const { algolia: { searchPagePath }, } = useAlgoliaThemeConfig();
|
|
24
|
+
return useCallback(function createSearchLink(searchValue) {
|
|
25
|
+
// Refer to https://github.com/facebook/docusaurus/pull/2838
|
|
26
|
+
// Note: if searchPagePath is falsy, useSearchPage() will not be called
|
|
27
|
+
return `${baseUrl}${searchPagePath}?${SEARCH_PARAM_QUERY}=${encodeURIComponent(searchValue)}`;
|
|
28
|
+
}, [baseUrl, searchPagePath]);
|
|
29
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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 type { AskAiConfig } from '@docusaurus/theme-search-algolia';
|
|
8
|
+
import type { DocSearchModalProps, DocSearchTranslations } from '@docsearch/react';
|
|
9
|
+
interface DocSearchV4PropsLite {
|
|
10
|
+
indexName: string;
|
|
11
|
+
apiKey: string;
|
|
12
|
+
appId: string;
|
|
13
|
+
placeholder?: string;
|
|
14
|
+
translations?: DocSearchTranslations;
|
|
15
|
+
searchParameters?: DocSearchModalProps['searchParameters'];
|
|
16
|
+
askAi?: AskAiConfig;
|
|
17
|
+
}
|
|
18
|
+
type UseAskAiResult = {
|
|
19
|
+
canHandleAskAi: boolean;
|
|
20
|
+
isAskAiActive: boolean;
|
|
21
|
+
currentPlaceholder: string | undefined;
|
|
22
|
+
onAskAiToggle: (active: boolean) => void;
|
|
23
|
+
askAi?: AskAiConfig;
|
|
24
|
+
extraAskAiProps: Partial<DocSearchModalProps> & {
|
|
25
|
+
askAi?: AskAiConfig;
|
|
26
|
+
canHandleAskAi?: boolean;
|
|
27
|
+
isAskAiActive?: boolean;
|
|
28
|
+
onAskAiToggle?: (active: boolean) => void;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export declare function useAlgoliaAskAi(props: DocSearchV4PropsLite): UseAskAiResult;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
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 { useCallback, useMemo, useState } from 'react';
|
|
8
|
+
import { version as docsearchVersion } from '@docsearch/react/version';
|
|
9
|
+
import translations from '@theme/SearchTranslations';
|
|
10
|
+
import { useAlgoliaContextualFacetFiltersIfEnabled } from './useAlgoliaContextualFacetFilters';
|
|
11
|
+
import { mergeFacetFilters } from './utils';
|
|
12
|
+
const isV4 = docsearchVersion.startsWith('4.');
|
|
13
|
+
// We need to apply contextualSearch facetFilters to AskAI filters
|
|
14
|
+
// This can't be done at config normalization time because contextual filters
|
|
15
|
+
// can only be determined at runtime
|
|
16
|
+
function applyAskAiContextualSearch(askAi, contextualSearchFilters) {
|
|
17
|
+
if (!askAi) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
if (!contextualSearchFilters) {
|
|
21
|
+
return askAi;
|
|
22
|
+
}
|
|
23
|
+
const askAiFacetFilters = askAi.searchParameters?.facetFilters;
|
|
24
|
+
return {
|
|
25
|
+
...askAi,
|
|
26
|
+
searchParameters: {
|
|
27
|
+
...askAi.searchParameters,
|
|
28
|
+
facetFilters: mergeFacetFilters(askAiFacetFilters, contextualSearchFilters),
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export function useAlgoliaAskAi(props) {
|
|
33
|
+
const [isAskAiActive, setIsAskAiActive] = useState(false);
|
|
34
|
+
const contextualSearchFilters = useAlgoliaContextualFacetFiltersIfEnabled();
|
|
35
|
+
const askAi = useMemo(() => {
|
|
36
|
+
return applyAskAiContextualSearch(props.askAi, contextualSearchFilters);
|
|
37
|
+
}, [props.askAi, contextualSearchFilters]);
|
|
38
|
+
const canHandleAskAi = Boolean(askAi);
|
|
39
|
+
const currentPlaceholder = isAskAiActive && isV4
|
|
40
|
+
? translations.modal?.searchBox?.placeholderTextAskAi
|
|
41
|
+
: translations.modal?.searchBox?.placeholderText || props?.placeholder;
|
|
42
|
+
const onAskAiToggle = useCallback((askAiToggle) => {
|
|
43
|
+
setIsAskAiActive(askAiToggle);
|
|
44
|
+
}, []);
|
|
45
|
+
const extraAskAiProps = {
|
|
46
|
+
askAi: askAi,
|
|
47
|
+
canHandleAskAi,
|
|
48
|
+
isAskAiActive,
|
|
49
|
+
onAskAiToggle,
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
canHandleAskAi,
|
|
53
|
+
isAskAiActive,
|
|
54
|
+
currentPlaceholder,
|
|
55
|
+
onAskAiToggle,
|
|
56
|
+
askAi,
|
|
57
|
+
extraAskAiProps,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
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 type { FacetFilters } from 'algoliasearch/lite';
|
|
8
|
+
export declare function useAlgoliaContextualFacetFilters(): FacetFilters;
|
|
9
|
+
export declare function useAlgoliaContextualFacetFiltersIfEnabled(): FacetFilters | undefined;
|
|
@@ -0,0 +1,34 @@
|
|
|
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 { DEFAULT_SEARCH_TAG } from '@docusaurus/theme-common/internal';
|
|
8
|
+
import { useDocsContextualSearchTags } from '@docusaurus/plugin-content-docs/client';
|
|
9
|
+
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
10
|
+
import { useAlgoliaThemeConfig } from './useAlgoliaThemeConfig';
|
|
11
|
+
function useSearchTags() {
|
|
12
|
+
// only docs have custom search tags per version
|
|
13
|
+
const docsTags = useDocsContextualSearchTags();
|
|
14
|
+
return [DEFAULT_SEARCH_TAG, ...docsTags];
|
|
15
|
+
}
|
|
16
|
+
// Translate search-engine agnostic search tags to Algolia search filters
|
|
17
|
+
export function useAlgoliaContextualFacetFilters() {
|
|
18
|
+
const locale = useDocusaurusContext().i18n.currentLocale;
|
|
19
|
+
const tags = useSearchTags();
|
|
20
|
+
// Seems safe to convert locale->language, see AlgoliaSearchMetadata comment
|
|
21
|
+
const languageFilter = `language:${locale}`;
|
|
22
|
+
const tagsFilter = tags.map((tag) => `docusaurus_tag:${tag}`);
|
|
23
|
+
return [languageFilter, tagsFilter];
|
|
24
|
+
}
|
|
25
|
+
export function useAlgoliaContextualFacetFiltersIfEnabled() {
|
|
26
|
+
const { algolia: { contextualSearch }, } = useAlgoliaThemeConfig();
|
|
27
|
+
const facetFilters = useAlgoliaContextualFacetFilters();
|
|
28
|
+
if (contextualSearch) {
|
|
29
|
+
return facetFilters;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
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 useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
8
|
+
export function useAlgoliaThemeConfig() {
|
|
9
|
+
const { siteConfig: { themeConfig }, } = useDocusaurusContext();
|
|
10
|
+
return themeConfig;
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
* Process the search result url from Algolia to its final form, ready to be
|
|
9
|
+
* navigated to or used as a link
|
|
10
|
+
*/
|
|
11
|
+
export declare function useSearchResultUrlProcessor(): (url: string) => string;
|
|
@@ -0,0 +1,33 @@
|
|
|
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 { useCallback } from 'react';
|
|
8
|
+
import { isRegexpStringMatch } from '@docusaurus/theme-common';
|
|
9
|
+
import { useBaseUrlUtils } from '@docusaurus/useBaseUrl';
|
|
10
|
+
import { useAlgoliaThemeConfig } from './useAlgoliaThemeConfig';
|
|
11
|
+
function replacePathname(pathname, replaceSearchResultPathname) {
|
|
12
|
+
return replaceSearchResultPathname
|
|
13
|
+
? pathname.replaceAll(new RegExp(replaceSearchResultPathname.from, 'g'), replaceSearchResultPathname.to)
|
|
14
|
+
: pathname;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Process the search result url from Algolia to its final form, ready to be
|
|
18
|
+
* navigated to or used as a link
|
|
19
|
+
*/
|
|
20
|
+
export function useSearchResultUrlProcessor() {
|
|
21
|
+
const { withBaseUrl } = useBaseUrlUtils();
|
|
22
|
+
const { algolia: { externalUrlRegex, replaceSearchResultPathname }, } = useAlgoliaThemeConfig();
|
|
23
|
+
return useCallback((url) => {
|
|
24
|
+
const parsedURL = new URL(url);
|
|
25
|
+
// Algolia contains an external domain => navigate to URL
|
|
26
|
+
if (isRegexpStringMatch(externalUrlRegex, parsedURL.href)) {
|
|
27
|
+
return url;
|
|
28
|
+
}
|
|
29
|
+
// Otherwise => transform to relative URL for SPA navigation
|
|
30
|
+
const relativeUrl = `${parsedURL.pathname}${parsedURL.search}${parsedURL.hash}`;
|
|
31
|
+
return withBaseUrl(replacePathname(relativeUrl, replaceSearchResultPathname));
|
|
32
|
+
}, [withBaseUrl, externalUrlRegex, replaceSearchResultPathname]);
|
|
33
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
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 type { FacetFilters } from 'algoliasearch/lite';
|
|
8
|
+
export declare function mergeFacetFilters(f1: FacetFilters, f2: FacetFilters): FacetFilters;
|
|
9
|
+
export declare function mergeFacetFilters(f1: FacetFilters | undefined, f2: FacetFilters | undefined): FacetFilters | undefined;
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
export function mergeFacetFilters(f1, f2) {
|
|
8
|
+
if (f1 === undefined) {
|
|
9
|
+
return f2;
|
|
10
|
+
}
|
|
11
|
+
if (f2 === undefined) {
|
|
12
|
+
return f1;
|
|
13
|
+
}
|
|
14
|
+
const normalize = (f) => typeof f === 'string' ? [f] : f;
|
|
15
|
+
// Historical behavior: we flatten everything
|
|
16
|
+
// TODO I'm pretty sure this is incorrect
|
|
17
|
+
// see https://www.algolia.com/doc/api-reference/api-parameters/facetFilters/?client=javascript
|
|
18
|
+
// Note: Algolia is working to provide a reliable facet merging strategy
|
|
19
|
+
// see https://github.com/facebook/docusaurus/pull/11327#issuecomment-3284742923
|
|
20
|
+
return [...normalize(f1), ...normalize(f2)];
|
|
21
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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.docSearchV3 = void 0;
|
|
10
|
+
const react_1 = require("@docsearch/react");
|
|
11
|
+
// TODO Docusaurus v4: upgrade to DocSearch v4
|
|
12
|
+
// drop v3 compat, remove this file?
|
|
13
|
+
exports.docSearchV3 = react_1.version.startsWith('3.');
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
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 type { LoadContext, Plugin } from '@docusaurus/types';
|
|
8
|
+
export default function themeSearchAlgolia(context: LoadContext): Plugin<void>;
|
|
9
|
+
export { validateThemeConfig } from './validateThemeConfig';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
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 = void 0;
|
|
10
|
+
exports.default = themeSearchAlgolia;
|
|
11
|
+
const utils_1 = require("@docusaurus/utils");
|
|
12
|
+
const theme_translations_1 = require("@docusaurus/theme-translations");
|
|
13
|
+
const opensearch_1 = require("./opensearch");
|
|
14
|
+
const docSearchVersion_1 = require("./docSearchVersion");
|
|
15
|
+
function themeSearchAlgolia(context) {
|
|
16
|
+
const { baseUrl, siteConfig: { themeConfig }, i18n: { currentLocale }, } = context;
|
|
17
|
+
const { algolia: { searchPagePath }, } = themeConfig;
|
|
18
|
+
return {
|
|
19
|
+
name: 'docusaurus-theme-search-algolia',
|
|
20
|
+
getThemePath() {
|
|
21
|
+
return '../lib/theme';
|
|
22
|
+
},
|
|
23
|
+
getTypeScriptThemePath() {
|
|
24
|
+
return '../src/theme';
|
|
25
|
+
},
|
|
26
|
+
getDefaultCodeTranslationMessages() {
|
|
27
|
+
return (0, theme_translations_1.readDefaultCodeTranslationMessages)({
|
|
28
|
+
locale: currentLocale,
|
|
29
|
+
name: 'theme-search-algolia',
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
contentLoaded({ actions: { addRoute } }) {
|
|
33
|
+
if (searchPagePath) {
|
|
34
|
+
addRoute({
|
|
35
|
+
path: (0, utils_1.normalizeUrl)([baseUrl, searchPagePath]),
|
|
36
|
+
component: '@theme/SearchPage',
|
|
37
|
+
exact: true,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
async postBuild() {
|
|
42
|
+
if ((0, opensearch_1.shouldCreateOpenSearchFile)({ context })) {
|
|
43
|
+
await (0, opensearch_1.createOpenSearchFile)({ context });
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
injectHtmlTags() {
|
|
47
|
+
if ((0, opensearch_1.shouldCreateOpenSearchFile)({ context })) {
|
|
48
|
+
return { headTags: (0, opensearch_1.createOpenSearchHeadTags)({ context }) };
|
|
49
|
+
}
|
|
50
|
+
return {};
|
|
51
|
+
},
|
|
52
|
+
configureWebpack() {
|
|
53
|
+
// TODO Docusaurus v4: remove after dropping DocSearch v3 support
|
|
54
|
+
if (docSearchVersion_1.docSearchV3) {
|
|
55
|
+
// These aliases ensure DocSearch v3 imports are compatible with
|
|
56
|
+
// the newly added DocSearch v4 entry points
|
|
57
|
+
// See https://github.com/algolia/docsearch/pull/2764
|
|
58
|
+
const docSearchV3Entry = require.resolve('@docsearch/react');
|
|
59
|
+
return {
|
|
60
|
+
resolve: {
|
|
61
|
+
alias: {
|
|
62
|
+
'@docsearch/react/version': docSearchV3Entry,
|
|
63
|
+
'@docsearch/react/useDocSearchKeyboardEvents': docSearchV3Entry,
|
|
64
|
+
'@docsearch/react/useTheme': docSearchV3Entry,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return undefined;
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
var validateThemeConfig_1 = require("./validateThemeConfig");
|
|
74
|
+
Object.defineProperty(exports, "validateThemeConfig", { enumerable: true, get: function () { return validateThemeConfig_1.validateThemeConfig; } });
|
|
@@ -0,0 +1,16 @@
|
|
|
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 type { HtmlTags, LoadContext } from '@docusaurus/types';
|
|
8
|
+
export declare function shouldCreateOpenSearchFile({ context, }: {
|
|
9
|
+
context: LoadContext;
|
|
10
|
+
}): boolean;
|
|
11
|
+
export declare function createOpenSearchFile({ context, }: {
|
|
12
|
+
context: LoadContext;
|
|
13
|
+
}): Promise<void>;
|
|
14
|
+
export declare function createOpenSearchHeadTags({ context, }: {
|
|
15
|
+
context: LoadContext;
|
|
16
|
+
}): HtmlTags;
|
|
@@ -0,0 +1,66 @@
|
|
|
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.shouldCreateOpenSearchFile = shouldCreateOpenSearchFile;
|
|
10
|
+
exports.createOpenSearchFile = createOpenSearchFile;
|
|
11
|
+
exports.createOpenSearchHeadTags = createOpenSearchHeadTags;
|
|
12
|
+
const tslib_1 = require("tslib");
|
|
13
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
14
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
15
|
+
const eta_1 = require("eta");
|
|
16
|
+
const utils_1 = require("@docusaurus/utils");
|
|
17
|
+
const fs_1 = require("@docusaurus/fs");
|
|
18
|
+
const opensearch_1 = tslib_1.__importDefault(require("./templates/opensearch"));
|
|
19
|
+
const eta = new eta_1.Eta();
|
|
20
|
+
const getCompiledOpenSearchTemplate = lodash_1.default.memoize(() => eta.compile(opensearch_1.default.trim()));
|
|
21
|
+
function renderOpenSearchTemplate(data) {
|
|
22
|
+
const compiled = getCompiledOpenSearchTemplate();
|
|
23
|
+
return eta.render(compiled, data);
|
|
24
|
+
}
|
|
25
|
+
const OPEN_SEARCH_FILENAME = 'opensearch.xml';
|
|
26
|
+
function shouldCreateOpenSearchFile({ context, }) {
|
|
27
|
+
const { siteConfig: { themeConfig, future: { experimental_router: router }, }, } = context;
|
|
28
|
+
const { algolia: { searchPagePath }, } = themeConfig;
|
|
29
|
+
return !!searchPagePath && router !== 'hash';
|
|
30
|
+
}
|
|
31
|
+
function createOpenSearchFileContent({ context, searchPagePath, }) {
|
|
32
|
+
const { baseUrl, siteConfig: { title, url, favicon }, } = context;
|
|
33
|
+
const siteUrl = (0, utils_1.normalizeUrl)([url, baseUrl]);
|
|
34
|
+
return renderOpenSearchTemplate({
|
|
35
|
+
title,
|
|
36
|
+
siteUrl,
|
|
37
|
+
searchUrl: (0, utils_1.normalizeUrl)([siteUrl, searchPagePath]),
|
|
38
|
+
faviconUrl: favicon ? (0, utils_1.normalizeUrl)([siteUrl, favicon]) : null,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async function createOpenSearchFile({ context, }) {
|
|
42
|
+
const { outDir, siteConfig: { themeConfig }, } = context;
|
|
43
|
+
const { algolia: { searchPagePath }, } = themeConfig;
|
|
44
|
+
if (!searchPagePath) {
|
|
45
|
+
throw new Error('no searchPagePath provided in themeConfig.algolia');
|
|
46
|
+
}
|
|
47
|
+
const fileContent = createOpenSearchFileContent({ context, searchPagePath });
|
|
48
|
+
try {
|
|
49
|
+
await fs_1.fs.writeFile(node_path_1.default.join(outDir, OPEN_SEARCH_FILENAME), fileContent);
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
throw new Error('Generating OpenSearch file failed.', { cause: err });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function createOpenSearchHeadTags({ context, }) {
|
|
56
|
+
const { baseUrl, siteConfig: { title }, } = context;
|
|
57
|
+
return {
|
|
58
|
+
tagName: 'link',
|
|
59
|
+
attributes: {
|
|
60
|
+
rel: 'search',
|
|
61
|
+
type: 'application/opensearchdescription+xml',
|
|
62
|
+
title,
|
|
63
|
+
href: (0, utils_1.normalizeUrl)([baseUrl, OPEN_SEARCH_FILENAME]),
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -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
|
+
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
|
+
export default _default;
|
|
@@ -0,0 +1,23 @@
|
|
|
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.default = `
|
|
10
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
11
|
+
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
|
|
12
|
+
xmlns:moz="http://www.mozilla.org/2006/browser/search/">
|
|
13
|
+
<ShortName><%= it.title %></ShortName>
|
|
14
|
+
<Description>Search <%= it.title %></Description>
|
|
15
|
+
<InputEncoding>UTF-8</InputEncoding>
|
|
16
|
+
<% if (it.faviconUrl) { _%>
|
|
17
|
+
<Image width="16" height="16" type="image/x-icon"><%= it.faviconUrl %></Image>
|
|
18
|
+
<% } _%>
|
|
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
|
+
</OpenSearchDescription>
|
|
23
|
+
`;
|
|
@@ -0,0 +1,24 @@
|
|
|
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 { type ReactNode } from 'react';
|
|
8
|
+
import type { DocSearchModalProps, DocSearchTranslations } from '@docsearch/react';
|
|
9
|
+
import type { ThemeConfigAlgolia } from '@docusaurus/theme-search-algolia';
|
|
10
|
+
type DocSearchProps = Omit<DocSearchModalProps, 'onClose' | 'initialScrollY'> & {
|
|
11
|
+
contextualSearch?: string;
|
|
12
|
+
externalUrlRegex?: string;
|
|
13
|
+
searchPagePath: boolean | string;
|
|
14
|
+
askAi?: Exclude<(DocSearchModalProps & {
|
|
15
|
+
askAi: unknown;
|
|
16
|
+
})['askAi'], string | undefined>;
|
|
17
|
+
};
|
|
18
|
+
interface DocSearchV4Props extends Omit<DocSearchProps, 'askAi'> {
|
|
19
|
+
indexName: string;
|
|
20
|
+
askAi?: ThemeConfigAlgolia['askAi'];
|
|
21
|
+
translations?: DocSearchTranslations;
|
|
22
|
+
}
|
|
23
|
+
export default function SearchBar(props: Partial<DocSearchV4Props>): ReactNode;
|
|
24
|
+
export {};
|