@easyops-cn/docusaurus-search-local 0.37.2 → 0.37.3
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/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [0.37.3](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.37.2...v0.37.3) (2023-11-12)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* fix SSR warning, closes [#364](https://github.com/easyops-cn/docusaurus-search-local/issues/364) ([69378e6](https://github.com/easyops-cn/docusaurus-search-local/commit/69378e67944ca3abd15e179621b5ca53903eecce))
|
|
11
|
+
|
|
5
12
|
## [0.37.2](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.37.1...v0.37.2) (2023-11-09)
|
|
6
13
|
|
|
7
14
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useRef, useState, } from "react";
|
|
2
2
|
import clsx from "clsx";
|
|
3
3
|
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
|
|
4
|
-
import
|
|
4
|
+
import useIsBrowser from "@docusaurus/useIsBrowser";
|
|
5
5
|
import { useHistory, useLocation } from "@docusaurus/router";
|
|
6
6
|
import { translate } from "@docusaurus/Translate";
|
|
7
7
|
import { ReactContextError, useDocsPreferredVersion, } from "@docusaurus/theme-common";
|
|
@@ -28,6 +28,7 @@ async function fetchAutoCompleteJS() {
|
|
|
28
28
|
}
|
|
29
29
|
const SEARCH_PARAM_HIGHLIGHT = "_highlight";
|
|
30
30
|
export default function SearchBar({ handleSearchBarToggle, }) {
|
|
31
|
+
const isBrowser = useIsBrowser();
|
|
31
32
|
const { siteConfig: { baseUrl }, } = useDocusaurusContext();
|
|
32
33
|
// It returns undefined for non-docs pages
|
|
33
34
|
const activePlugin = useActivePlugin();
|
|
@@ -218,7 +219,7 @@ export default function SearchBar({ handleSearchBarToggle, }) {
|
|
|
218
219
|
if (!Mark) {
|
|
219
220
|
return;
|
|
220
221
|
}
|
|
221
|
-
const keywords =
|
|
222
|
+
const keywords = isBrowser
|
|
222
223
|
? new URLSearchParams(location.search).getAll(SEARCH_PARAM_HIGHLIGHT)
|
|
223
224
|
: [];
|
|
224
225
|
// A workaround to fix an issue of highlighting in code blocks.
|
|
@@ -239,7 +240,7 @@ export default function SearchBar({ handleSearchBarToggle, }) {
|
|
|
239
240
|
setInputValue(keywords.join(" "));
|
|
240
241
|
search.current?.autocomplete.setVal(keywords.join(" "));
|
|
241
242
|
});
|
|
242
|
-
}, [location.search, location.pathname]);
|
|
243
|
+
}, [isBrowser, location.search, location.pathname]);
|
|
243
244
|
const [focused, setFocused] = useState(false);
|
|
244
245
|
const onInputFocus = useCallback(() => {
|
|
245
246
|
focusAfterIndexLoaded.current = true;
|
|
@@ -261,7 +262,7 @@ export default function SearchBar({ handleSearchBarToggle, }) {
|
|
|
261
262
|
}
|
|
262
263
|
}, []);
|
|
263
264
|
// Implement hint icons for the search shortcuts on mac and the rest operating systems.
|
|
264
|
-
const isMac =
|
|
265
|
+
const isMac = isBrowser
|
|
265
266
|
? /mac/i.test(navigator.userAgentData?.platform ?? navigator.platform)
|
|
266
267
|
: false;
|
|
267
268
|
useEffect(() => {
|
|
@@ -310,7 +311,7 @@ export default function SearchBar({ handleSearchBarToggle, }) {
|
|
|
310
311
|
searchBarShortcutHint &&
|
|
311
312
|
(inputValue !== "" ? (<button className={styles.searchClearButton} onClick={onClearSearch}>
|
|
312
313
|
✕
|
|
313
|
-
</button>) : (
|
|
314
|
+
</button>) : (isBrowser && (<div className={styles.searchHintContainer}>
|
|
314
315
|
<kbd className={styles.searchHint}>{isMac ? "⌘" : "ctrl"}</kbd>
|
|
315
316
|
<kbd className={styles.searchHint}>K</kbd>
|
|
316
317
|
</div>)))}
|
|
@@ -5,16 +5,17 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import { useHistory, useLocation } from "@docusaurus/router";
|
|
8
|
-
import
|
|
8
|
+
import useIsBrowser from "@docusaurus/useIsBrowser";
|
|
9
9
|
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
|
|
10
10
|
const SEARCH_PARAM_QUERY = "q";
|
|
11
11
|
const SEARCH_PARAM_CONTEXT = "ctx";
|
|
12
12
|
const SEARCH_PARAM_VERSION = "version";
|
|
13
13
|
function useSearchQuery() {
|
|
14
|
+
const isBrowser = useIsBrowser();
|
|
14
15
|
const history = useHistory();
|
|
15
16
|
const location = useLocation();
|
|
16
17
|
const { siteConfig: { baseUrl }, } = useDocusaurusContext();
|
|
17
|
-
const params =
|
|
18
|
+
const params = isBrowser ? new URLSearchParams(location.search) : null;
|
|
18
19
|
const searchValue = params?.get(SEARCH_PARAM_QUERY) || "";
|
|
19
20
|
const searchContext = params?.get(SEARCH_PARAM_CONTEXT) || "";
|
|
20
21
|
const searchVersion = params?.get(SEARCH_PARAM_VERSION) || "";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easyops-cn/docusaurus-search-local",
|
|
3
|
-
"version": "0.37.
|
|
3
|
+
"version": "0.37.3",
|
|
4
4
|
"description": "An offline/local search plugin for Docusaurus v3",
|
|
5
5
|
"repository": "https://github.com/easyops-cn/docusaurus-search-local",
|
|
6
6
|
"homepage": "https://github.com/easyops-cn/docusaurus-search-local",
|