@docusaurus/theme-search-algolia 0.0.0-4203 → 0.0.0-4207

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
@@ -14,9 +14,7 @@ const eta_1 = require("eta");
14
14
  const utils_1 = require("@docusaurus/utils");
15
15
  const opensearch_1 = (0, tslib_1.__importDefault)(require("./templates/opensearch"));
16
16
  const lodash_1 = require("lodash");
17
- const getCompiledOpenSearchTemplate = (0, lodash_1.memoize)(() => {
18
- return (0, eta_1.compile)(opensearch_1.default.trim());
19
- });
17
+ const getCompiledOpenSearchTemplate = (0, lodash_1.memoize)(() => (0, eta_1.compile)(opensearch_1.default.trim()));
20
18
  function renderOpenSearchTemplate(data) {
21
19
  const compiled = getCompiledOpenSearchTemplate();
22
20
  return compiled(data, eta_1.defaultConfig);
@@ -93,21 +93,21 @@ function DocSearch({ contextualSearch, externalUrlRegex, ...props }) {
93
93
  }
94
94
  },
95
95
  }).current;
96
- const transformItems = useRef((items) => {
97
- return items.map((item) => {
98
- // If Algolia contains a external domain, we should navigate without relative URL
99
- if (isRegexpStringMatch(externalUrlRegex, item.url)) {
100
- return item;
101
- }
102
- // We transform the absolute URL into a relative URL.
103
- const url = new URL(item.url);
104
- return {
105
- ...item,
106
- url: withBaseUrl(`${url.pathname}${url.hash}`),
107
- };
108
- });
109
- }).current;
110
- const resultsFooterComponent = useMemo(() => (footerProps) => <ResultsFooter {...footerProps} onClose={onClose}/>, [onClose]);
96
+ const transformItems = useRef((items) => items.map((item) => {
97
+ // If Algolia contains a external domain, we should navigate without relative URL
98
+ if (isRegexpStringMatch(externalUrlRegex, item.url)) {
99
+ return item;
100
+ }
101
+ // We transform the absolute URL into a relative URL.
102
+ const url = new URL(item.url);
103
+ return {
104
+ ...item,
105
+ url: withBaseUrl(`${url.pathname}${url.hash}`),
106
+ };
107
+ })).current;
108
+ const resultsFooterComponent = useMemo(
109
+ // eslint-disable-next-line react/no-unstable-nested-components
110
+ () => (footerProps) => <ResultsFooter {...footerProps} onClose={onClose}/>, [onClose]);
111
111
  const transformSearchClient = useCallback((searchClient) => {
112
112
  searchClient.addAlgoliaAgent('docusaurus', siteMetadata.docusaurusVersion);
113
113
  return searchClient;
@@ -33,11 +33,10 @@ function useDocsSearchVersionsHelpers() {
33
33
  const allDocsData = useAllDocsData();
34
34
  // State of the version select menus / algolia facet filters
35
35
  // docsPluginId -> versionName map
36
- const [searchVersions, setSearchVersions] = useState(() => {
37
- return Object.entries(allDocsData).reduce((acc, [pluginId, pluginData]) => {
38
- return { ...acc, [pluginId]: pluginData.versions[0].name };
39
- }, {});
40
- });
36
+ const [searchVersions, setSearchVersions] = useState(() => Object.entries(allDocsData).reduce((acc, [pluginId, pluginData]) => ({
37
+ ...acc,
38
+ [pluginId]: pluginData.versions[0].name,
39
+ }), {}));
41
40
  // Set the value of a single select menu
42
41
  const setSearchVersion = (pluginId, searchVersion) => setSearchVersions((s) => ({ ...s, [pluginId]: searchVersion }));
43
42
  const versioningEnabled = Object.values(allDocsData).some((docsData) => docsData.versions.length > 1);
@@ -49,7 +48,7 @@ function useDocsSearchVersionsHelpers() {
49
48
  };
50
49
  }
51
50
  // We want to display one select per versioned docs plugin instance
52
- const SearchVersionSelectList = ({ docsSearchVersionsHelpers, }) => {
51
+ function SearchVersionSelectList({ docsSearchVersionsHelpers, }) {
53
52
  const versionedPluginEntries = Object.entries(docsSearchVersionsHelpers.allDocsData)
54
53
  // Do not show a version select for unversioned docs plugin instances
55
54
  .filter(([, docsData]) => docsData.versions.length > 1);
@@ -61,7 +60,7 @@ const SearchVersionSelectList = ({ docsSearchVersionsHelpers, }) => {
61
60
  </select>);
62
61
  })}
63
62
  </div>);
64
- };
63
+ }
65
64
  function SearchPage() {
66
65
  const { siteConfig: { themeConfig: {
67
66
  // @ts-ignore
@@ -120,14 +119,10 @@ function SearchPage() {
120
119
  searchResultStateDispatcher({ type: 'reset' });
121
120
  return;
122
121
  }
123
- const sanitizeValue = (value) => {
124
- return value.replace(/algolia-docsearch-suggestion--highlight/g, 'search-result-match');
125
- };
122
+ const sanitizeValue = (value) => value.replace(/algolia-docsearch-suggestion--highlight/g, 'search-result-match');
126
123
  const items = hits.map(({ url, _highlightResult: { hierarchy }, _snippetResult: snippet = {}, }) => {
127
124
  const parsedURL = new URL(url);
128
- const titles = Object.keys(hierarchy).map((key) => {
129
- return sanitizeValue(hierarchy[key].value);
130
- });
125
+ const titles = Object.keys(hierarchy).map((key) => sanitizeValue(hierarchy[key].value));
131
126
  return {
132
127
  title: titles.pop(),
133
128
  url: isRegexpStringMatch(externalUrlRegex, parsedURL.href)
@@ -31,10 +31,9 @@ function useSearchQuery() {
31
31
  });
32
32
  setSearchQueryState(newSearchQuery);
33
33
  }, [history]);
34
- const generateSearchPageLink = useCallback((targetSearchQuery) => {
35
- // Refer to https://github.com/facebook/docusaurus/pull/2838
36
- return `${baseUrl}search?q=${encodeURIComponent(targetSearchQuery)}`;
37
- }, [baseUrl]);
34
+ const generateSearchPageLink = useCallback((targetSearchQuery) =>
35
+ // Refer to https://github.com/facebook/docusaurus/pull/2838
36
+ `${baseUrl}search?q=${encodeURIComponent(targetSearchQuery)}`, [baseUrl]);
38
37
  return {
39
38
  searchQuery,
40
39
  setSearchQuery,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/theme-search-algolia",
3
- "version": "0.0.0-4203",
3
+ "version": "0.0.0-4207",
4
4
  "description": "Algolia search component for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/theme-search-algolia.d.ts",
@@ -21,10 +21,10 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@docsearch/react": "^3.0.0-alpha.39",
24
- "@docusaurus/core": "0.0.0-4203",
25
- "@docusaurus/theme-common": "0.0.0-4203",
26
- "@docusaurus/utils": "0.0.0-4203",
27
- "@docusaurus/utils-validation": "0.0.0-4203",
24
+ "@docusaurus/core": "0.0.0-4207",
25
+ "@docusaurus/theme-common": "0.0.0-4207",
26
+ "@docusaurus/utils": "0.0.0-4207",
27
+ "@docusaurus/utils-validation": "0.0.0-4207",
28
28
  "algoliasearch": "^4.10.5",
29
29
  "algoliasearch-helper": "^3.5.5",
30
30
  "clsx": "^1.1.1",
@@ -32,7 +32,7 @@
32
32
  "lodash": "^4.17.20"
33
33
  },
34
34
  "devDependencies": {
35
- "@docusaurus/module-type-aliases": "0.0.0-4203",
35
+ "@docusaurus/module-type-aliases": "0.0.0-4207",
36
36
  "fs-extra": "^10.0.0"
37
37
  },
38
38
  "peerDependencies": {
@@ -42,5 +42,5 @@
42
42
  "engines": {
43
43
  "node": ">=14"
44
44
  },
45
- "gitHead": "c593f92915e118d87c10015d5db2c42eda4b5ef3"
45
+ "gitHead": "63059ec789f63c76514839ed417d2ef58456666e"
46
46
  }
package/src/index.ts CHANGED
@@ -14,9 +14,9 @@ import {memoize} from 'lodash';
14
14
 
15
15
  import type {DocusaurusContext, Plugin} from '@docusaurus/types';
16
16
 
17
- const getCompiledOpenSearchTemplate = memoize(() => {
18
- return compile(openSearchTemplate.trim());
19
- });
17
+ const getCompiledOpenSearchTemplate = memoize(() =>
18
+ compile(openSearchTemplate.trim()),
19
+ );
20
20
 
21
21
  function renderOpenSearchTemplate(data: {
22
22
  title: string;
@@ -152,8 +152,8 @@ function DocSearch({
152
152
  }).current;
153
153
 
154
154
  const transformItems = useRef<DocSearchModalProps['transformItems']>(
155
- (items) => {
156
- return items.map((item) => {
155
+ (items) =>
156
+ items.map((item) => {
157
157
  // If Algolia contains a external domain, we should navigate without relative URL
158
158
  if (isRegexpStringMatch(externalUrlRegex, item.url)) {
159
159
  return item;
@@ -165,11 +165,11 @@ function DocSearch({
165
165
  ...item,
166
166
  url: withBaseUrl(`${url.pathname}${url.hash}`),
167
167
  };
168
- });
169
- },
168
+ }),
170
169
  ).current;
171
170
 
172
171
  const resultsFooterComponent = useMemo(
172
+ // eslint-disable-next-line react/no-unstable-nested-components
173
173
  () => (footerProps: ResultsFooterProps) =>
174
174
  <ResultsFooter {...footerProps} onClose={onClose} />,
175
175
  [onClose],
@@ -250,7 +250,7 @@ function DocSearch({
250
250
  );
251
251
  }
252
252
 
253
- function SearchBar() {
253
+ function SearchBar(): JSX.Element {
254
254
  const {siteConfig} = useDocusaurusContext();
255
255
  // @ts-ignore
256
256
  return <DocSearch {...siteConfig.themeConfig.algolia} />;
@@ -54,14 +54,14 @@ function useDocsSearchVersionsHelpers() {
54
54
  // State of the version select menus / algolia facet filters
55
55
  // docsPluginId -> versionName map
56
56
  const [searchVersions, setSearchVersions] = useState<Record<string, string>>(
57
- () => {
58
- return Object.entries(allDocsData).reduce(
59
- (acc, [pluginId, pluginData]) => {
60
- return {...acc, [pluginId]: pluginData.versions[0].name};
61
- },
57
+ () =>
58
+ Object.entries(allDocsData).reduce(
59
+ (acc, [pluginId, pluginData]) => ({
60
+ ...acc,
61
+ [pluginId]: pluginData.versions[0].name,
62
+ }),
62
63
  {},
63
- );
64
- },
64
+ ),
65
65
  );
66
66
 
67
67
  // Set the value of a single select menu
@@ -81,11 +81,11 @@ function useDocsSearchVersionsHelpers() {
81
81
  }
82
82
 
83
83
  // We want to display one select per versioned docs plugin instance
84
- const SearchVersionSelectList = ({
84
+ function SearchVersionSelectList({
85
85
  docsSearchVersionsHelpers,
86
86
  }: {
87
87
  docsSearchVersionsHelpers: ReturnType<typeof useDocsSearchVersionsHelpers>;
88
- }) => {
88
+ }) {
89
89
  const versionedPluginEntries = Object.entries(
90
90
  docsSearchVersionsHelpers.allDocsData,
91
91
  )
@@ -126,7 +126,7 @@ const SearchVersionSelectList = ({
126
126
  })}
127
127
  </div>
128
128
  );
129
- };
129
+ }
130
130
 
131
131
  type ResultDispatcherState = {
132
132
  items: {
@@ -225,12 +225,11 @@ function SearchPage(): JSX.Element {
225
225
  return;
226
226
  }
227
227
 
228
- const sanitizeValue = (value: string) => {
229
- return value.replace(
228
+ const sanitizeValue = (value: string) =>
229
+ value.replace(
230
230
  /algolia-docsearch-suggestion--highlight/g,
231
231
  'search-result-match',
232
232
  );
233
- };
234
233
 
235
234
  const items = hits.map(
236
235
  ({
@@ -239,9 +238,9 @@ function SearchPage(): JSX.Element {
239
238
  _snippetResult: snippet = {},
240
239
  }) => {
241
240
  const parsedURL = new URL(url);
242
- const titles = Object.keys(hierarchy).map((key) => {
243
- return sanitizeValue(hierarchy[key].value);
244
- });
241
+ const titles = Object.keys(hierarchy).map((key) =>
242
+ sanitizeValue(hierarchy[key].value),
243
+ );
245
244
 
246
245
  return {
247
246
  title: titles.pop()!,
@@ -47,10 +47,9 @@ function useSearchQuery(): SearchQuery {
47
47
  );
48
48
 
49
49
  const generateSearchPageLink = useCallback(
50
- (targetSearchQuery: string) => {
50
+ (targetSearchQuery: string) =>
51
51
  // Refer to https://github.com/facebook/docusaurus/pull/2838
52
- return `${baseUrl}search?q=${encodeURIComponent(targetSearchQuery)}`;
53
- },
52
+ `${baseUrl}search?q=${encodeURIComponent(targetSearchQuery)}`,
54
53
  [baseUrl],
55
54
  );
56
55