@easyops-cn/docusaurus-search-local 0.24.1 → 0.26.1

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,146 +2,149 @@
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.24.1](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.24.0...v0.24.1) (2022-05-19)
5
+ ### [0.26.1](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.26.0...v0.26.1) (2022-05-25)
6
6
 
7
7
 
8
8
  ### Bug Fixes
9
9
 
10
- * fix indexing content between h1 and h2 ([f38b307](https://github.com/easyops-cn/docusaurus-search-local/commit/f38b307a669b582b8571fd2430b4454b49323c85))
10
+ * fix i18n id of `theme.SearchPage.noResultsText` ([fe530f3](https://github.com/easyops-cn/docusaurus-search-local/commit/fe530f35da0b11c78c9d68cb6a7fea5871919e00))
11
11
 
12
- ## [0.24.0](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.23.3...v0.24.0) (2022-05-18)
12
+ ## [0.26.0](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.26.0...v0.26.0) (2022-05-24)
13
+
14
+ ### Features
15
+
16
+ * add a clear button to the search bar [#170](https://github.com/easyops-cn/docusaurus-search-local/issues/170) ([f516123](https://github.com/easyops-cn/docusaurus-search-local/commit/f5161238cb7466fe7309e9166037d681e647f910))
13
17
 
18
+ ## [0.25.0](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.24.1...v0.25.0) (2022-05-19)
19
+
20
+ ### ⚠ BREAKING CHANGES
21
+
22
+ - drop `translations` in options
14
23
 
15
24
  ### Features
16
25
 
17
- * Add option to disable the default lunr stemmer ([ff8e9a2](https://github.com/easyops-cn/docusaurus-search-local/commit/ff8e9a2e3162dd847cbef11036772578c41a8828))
26
+ - on board docusaurus i18n system ([70868c3](https://github.com/easyops-cn/docusaurus-search-local/commit/70868c333bace7fbdb27380730031311ae75748a)), closes [#160](https://github.com/easyops-cn/docusaurus-search-local/issues/160)
18
27
 
28
+ ### [0.24.1](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.24.0...v0.24.1) (2022-05-19)
19
29
 
20
30
  ### Bug Fixes
21
31
 
22
- * **deps:** update dependency fs-extra to v10 ([96c9220](https://github.com/easyops-cn/docusaurus-search-local/commit/96c92206bcff35b529400c19d5bcf66e1abd4d81))
23
- * Fix parsing of top level pages when using docs only mode ([ff8e9a2](https://github.com/easyops-cn/docusaurus-search-local/commit/ff8e9a2e3162dd847cbef11036772578c41a8828))
24
- * Fix passing of top sections for versions of docusaurus with breadcrumbs ([ff8e9a2](https://github.com/easyops-cn/docusaurus-search-local/commit/ff8e9a2e3162dd847cbef11036772578c41a8828))
25
- * Fix search term highlighting when reusing the same search string ([ff8e9a2](https://github.com/easyops-cn/docusaurus-search-local/commit/ff8e9a2e3162dd847cbef11036772578c41a8828))
32
+ - fix indexing content between h1 and h2 ([f38b307](https://github.com/easyops-cn/docusaurus-search-local/commit/f38b307a669b582b8571fd2430b4454b49323c85))
26
33
 
27
- ### [0.23.3](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.23.2...v0.23.3) (2022-05-18)
34
+ ## [0.24.0](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.23.3...v0.24.0) (2022-05-18)
35
+
36
+ ### Features
28
37
 
38
+ - Add option to disable the default lunr stemmer ([ff8e9a2](https://github.com/easyops-cn/docusaurus-search-local/commit/ff8e9a2e3162dd847cbef11036772578c41a8828))
29
39
 
30
40
  ### Bug Fixes
31
41
 
32
- * Update getIndexHash.ts to support mdx and traverseAll ([#172](https://www.github.com/easyops-cn/docusaurus-search-local/issues/172)) ([717942e](https://www.github.com/easyops-cn/docusaurus-search-local/commit/717942e9caf36e37a0f119d9fdaa50e591339d9c))
42
+ - **deps:** update dependency fs-extra to v10 ([96c9220](https://github.com/easyops-cn/docusaurus-search-local/commit/96c92206bcff35b529400c19d5bcf66e1abd4d81))
43
+ - Fix parsing of top level pages when using docs only mode ([ff8e9a2](https://github.com/easyops-cn/docusaurus-search-local/commit/ff8e9a2e3162dd847cbef11036772578c41a8828))
44
+ - Fix passing of top sections for versions of docusaurus with breadcrumbs ([ff8e9a2](https://github.com/easyops-cn/docusaurus-search-local/commit/ff8e9a2e3162dd847cbef11036772578c41a8828))
45
+ - Fix search term highlighting when reusing the same search string ([ff8e9a2](https://github.com/easyops-cn/docusaurus-search-local/commit/ff8e9a2e3162dd847cbef11036772578c41a8828))
33
46
 
34
- ### [0.23.2](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.23.1...v0.23.2) (2022-04-25)
47
+ ### [0.23.3](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.23.2...v0.23.3) (2022-05-18)
48
+
49
+ ### Bug Fixes
35
50
 
51
+ - Update getIndexHash.ts to support mdx and traverseAll ([#172](https://www.github.com/easyops-cn/docusaurus-search-local/issues/172)) ([717942e](https://www.github.com/easyops-cn/docusaurus-search-local/commit/717942e9caf36e37a0f119d9fdaa50e591339d9c))
52
+
53
+ ### [0.23.2](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.23.1...v0.23.2) (2022-04-25)
36
54
 
37
55
  ### Bug Fixes
38
56
 
39
- * install cheerio types ([0a45f41](https://www.github.com/easyops-cn/docusaurus-search-local/commit/0a45f41bd02d8305328705bcc6582b92ed2ccf78))
57
+ - install cheerio types ([0a45f41](https://www.github.com/easyops-cn/docusaurus-search-local/commit/0a45f41bd02d8305328705bcc6582b92ed2ccf78))
40
58
 
41
59
  ### [0.23.1](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.23.0...v0.23.1) (2022-04-07)
42
60
 
43
-
44
61
  ### Bug Fixes
45
62
 
46
- * parse `h1` from the whole `article` ([aeb063a](https://www.github.com/easyops-cn/docusaurus-search-local/commit/aeb063af9dbac9778e3436aa261e0c131a2ef8c2))
63
+ - parse `h1` from the whole `article` ([aeb063a](https://www.github.com/easyops-cn/docusaurus-search-local/commit/aeb063af9dbac9778e3436aa261e0c131a2ef8c2))
47
64
 
48
65
  ## [0.23.0](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.22.0...v0.23.0) (2022-03-10)
49
66
 
50
-
51
67
  ### Features
52
68
 
53
- * replace nodejieba with @node-rs/jieba ([f3f7594](https://www.github.com/easyops-cn/docusaurus-search-local/commit/f3f7594d0a97075a4aefa19e15f2d1f961bbb824))
69
+ - replace nodejieba with @node-rs/jieba ([f3f7594](https://www.github.com/easyops-cn/docusaurus-search-local/commit/f3f7594d0a97075a4aefa19e15f2d1f961bbb824))
54
70
 
55
71
  ## [0.22.0](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.21.4...v0.22.0) (2022-02-28)
56
72
 
57
-
58
73
  ### Features
59
74
 
60
- * improve focus for search bar ([e4ede16](https://www.github.com/easyops-cn/docusaurus-search-local/commit/e4ede1650883e326bcbc7ff17c5ed3d37b279d17))
75
+ - improve focus for search bar ([e4ede16](https://www.github.com/easyops-cn/docusaurus-search-local/commit/e4ede1650883e326bcbc7ff17c5ed3d37b279d17))
61
76
 
62
77
  ### [0.21.4](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.21.3...v0.21.4) (2021-12-15)
63
78
 
64
-
65
79
  ### Bug Fixes
66
80
 
67
- * set max-width for dropdown on small screen ([cec8c39](https://www.github.com/easyops-cn/docusaurus-search-local/commit/cec8c3924beacd900d880fd66edaf52dbdbdd952)), closes [#135](https://www.github.com/easyops-cn/docusaurus-search-local/issues/135)
81
+ - set max-width for dropdown on small screen ([cec8c39](https://www.github.com/easyops-cn/docusaurus-search-local/commit/cec8c3924beacd900d880fd66edaf52dbdbdd952)), closes [#135](https://www.github.com/easyops-cn/docusaurus-search-local/issues/135)
68
82
 
69
83
  ### [0.21.3](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.21.2...v0.21.3) (2021-12-14)
70
84
 
71
-
72
85
  ### Bug Fixes
73
86
 
74
- * use keydown instead of keypress ([d871f0b](https://www.github.com/easyops-cn/docusaurus-search-local/commit/d871f0bbb1e1c6fe191341f7166b89b6aeb11bf2)), closes [#132](https://www.github.com/easyops-cn/docusaurus-search-local/issues/132)
87
+ - use keydown instead of keypress ([d871f0b](https://www.github.com/easyops-cn/docusaurus-search-local/commit/d871f0bbb1e1c6fe191341f7166b89b6aeb11bf2)), closes [#132](https://www.github.com/easyops-cn/docusaurus-search-local/issues/132)
75
88
 
76
89
  ### [0.21.2](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.21.1...v0.21.2) (2021-12-13)
77
90
 
78
-
79
91
  ### Bug Fixes
80
92
 
81
- * refine styles with dark navbar ([e3c9eef](https://www.github.com/easyops-cn/docusaurus-search-local/commit/e3c9eef41ffd9d51bb57b05fd199f7dc32541e79)), closes [#128](https://www.github.com/easyops-cn/docusaurus-search-local/issues/128)
93
+ - refine styles with dark navbar ([e3c9eef](https://www.github.com/easyops-cn/docusaurus-search-local/commit/e3c9eef41ffd9d51bb57b05fd199f7dc32541e79)), closes [#128](https://www.github.com/easyops-cn/docusaurus-search-local/issues/128)
82
94
 
83
95
  ### [0.21.1](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.21.0...v0.21.1) (2021-12-07)
84
96
 
85
-
86
97
  ### Bug Fixes
87
98
 
88
- * fix input box style of search page in dark mode ([f233bce](https://www.github.com/easyops-cn/docusaurus-search-local/commit/f233bcedb4d79cba9b8d21f700ca79f2297f0ec9)), closes [#125](https://www.github.com/easyops-cn/docusaurus-search-local/issues/125)
99
+ - fix input box style of search page in dark mode ([f233bce](https://www.github.com/easyops-cn/docusaurus-search-local/commit/f233bcedb4d79cba9b8d21f700ca79f2297f0ec9)), closes [#125](https://www.github.com/easyops-cn/docusaurus-search-local/issues/125)
89
100
 
90
101
  ## [0.21.0](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.20.0...v0.21.0) (2021-12-04)
91
102
 
92
-
93
103
  ### Features
94
104
 
95
- * add shortcut (cmd/ctrl + K) support ([f12403f](https://www.github.com/easyops-cn/docusaurus-search-local/commit/f12403fc6bc48b489d8ef170aecad2262f3a4ebc))
105
+ - add shortcut (cmd/ctrl + K) support ([f12403f](https://www.github.com/easyops-cn/docusaurus-search-local/commit/f12403fc6bc48b489d8ef170aecad2262f3a4ebc))
96
106
 
97
107
  ## [0.20.0](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.19.1...v0.20.0) (2021-11-12)
98
108
 
99
-
100
109
  ### Features
101
110
 
102
- * remove nodejieba from peerDependencies ([e76bb64](https://www.github.com/easyops-cn/docusaurus-search-local/commit/e76bb6490b749cab6b17607349ab04f226d8eee4))
111
+ - remove nodejieba from peerDependencies ([e76bb64](https://www.github.com/easyops-cn/docusaurus-search-local/commit/e76bb6490b749cab6b17607349ab04f226d8eee4))
103
112
 
104
113
  ### [0.19.1](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.19.0...v0.19.1) (2021-08-03)
105
114
 
106
-
107
115
  ### Bug Fixes
108
116
 
109
- * fix docsRouteBasePath or blogRouteBasePath set to "/" ([a1b1df6](https://www.github.com/easyops-cn/docusaurus-search-local/commit/a1b1df6d59ab309ca68c18494ac72f8aa6a1b370))
110
- * fix search page ignore ([9841cc8](https://www.github.com/easyops-cn/docusaurus-search-local/commit/9841cc8b910d5a1b2ea9fe896ec5acdde0b2faf0))
111
- * refine get site config ([e215a1a](https://www.github.com/easyops-cn/docusaurus-search-local/commit/e215a1a5ceef1751233996e5a48c57fa9ca25d1e))
117
+ - fix docsRouteBasePath or blogRouteBasePath set to "/" ([a1b1df6](https://www.github.com/easyops-cn/docusaurus-search-local/commit/a1b1df6d59ab309ca68c18494ac72f8aa6a1b370))
118
+ - fix search page ignore ([9841cc8](https://www.github.com/easyops-cn/docusaurus-search-local/commit/9841cc8b910d5a1b2ea9fe896ec5acdde0b2faf0))
119
+ - refine get site config ([e215a1a](https://www.github.com/easyops-cn/docusaurus-search-local/commit/e215a1a5ceef1751233996e5a48c57fa9ca25d1e))
112
120
 
113
121
  ## [0.19.0](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.18.1...v0.19.0) (2021-08-03)
114
122
 
115
-
116
123
  ### Features
117
124
 
118
- * depends on docusaurus 2.0.0-beta.4 ([69ea575](https://www.github.com/easyops-cn/docusaurus-search-local/commit/69ea5757d6b4ef6158033d1cf766abc65d5e76d4))
119
-
125
+ - depends on docusaurus 2.0.0-beta.4 ([69ea575](https://www.github.com/easyops-cn/docusaurus-search-local/commit/69ea5757d6b4ef6158033d1cf766abc65d5e76d4))
120
126
 
121
127
  ### Bug Fixes
122
128
 
123
- * handle trailingSlash config ([16aa10f](https://www.github.com/easyops-cn/docusaurus-search-local/commit/16aa10f8117f1ceb5de4e1df3f18fe89c8b0c4ba)), closes [#100](https://www.github.com/easyops-cn/docusaurus-search-local/issues/100)
129
+ - handle trailingSlash config ([16aa10f](https://www.github.com/easyops-cn/docusaurus-search-local/commit/16aa10f8117f1ceb5de4e1df3f18fe89c8b0c4ba)), closes [#100](https://www.github.com/easyops-cn/docusaurus-search-local/issues/100)
124
130
 
125
131
  ### [0.18.1](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.18.0...v0.18.1) (2021-06-05)
126
132
 
127
-
128
133
  ### Bug Fixes
129
134
 
130
- * fix an issue of highlighting in code blocks ([3378b9c](https://www.github.com/easyops-cn/docusaurus-search-local/commit/3378b9c3a0db4e649184dd735b0761f991dc44f4)), closes [#92](https://www.github.com/easyops-cn/docusaurus-search-local/issues/92)
135
+ - fix an issue of highlighting in code blocks ([3378b9c](https://www.github.com/easyops-cn/docusaurus-search-local/commit/3378b9c3a0db4e649184dd735b0761f991dc44f4)), closes [#92](https://www.github.com/easyops-cn/docusaurus-search-local/issues/92)
131
136
 
132
137
  ## [0.18.0](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.17.0...v0.18.0) (2021-06-05)
133
138
 
134
-
135
139
  ### Features
136
140
 
137
- * support docusaurus 2.0.0-beta.0 ([a144b7f](https://www.github.com/easyops-cn/docusaurus-search-local/commit/a144b7f35ebefc1791a6057a163056d9a902f736))
141
+ - support docusaurus 2.0.0-beta.0 ([a144b7f](https://www.github.com/easyops-cn/docusaurus-search-local/commit/a144b7f35ebefc1791a6057a163056d9a902f736))
138
142
 
139
143
  ## [0.17.0](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.16.3...v0.17.0) (2021-05-28)
140
144
 
141
-
142
145
  ### Features
143
146
 
144
- * ignore search files by config ([#88](https://www.github.com/easyops-cn/docusaurus-search-local/issues/88)) ([a7b1b3a](https://www.github.com/easyops-cn/docusaurus-search-local/commit/a7b1b3a98bda9c72859ebc762efa5eb874dbd7e9))
147
+ - ignore search files by config ([#88](https://www.github.com/easyops-cn/docusaurus-search-local/issues/88)) ([a7b1b3a](https://www.github.com/easyops-cn/docusaurus-search-local/commit/a7b1b3a98bda9c72859ebc762efa5eb874dbd7e9))
145
148
 
146
149
  ### [0.16.3](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.16.1...v0.16.3) (2021-05-13)
147
150
 
@@ -1,9 +1,12 @@
1
- import { translations } from "../../utils/proxiedGenerated";
1
+ import { translate } from "@docusaurus/Translate";
2
2
  import { iconNoResults } from "./icons";
3
3
  import styles from "./SearchBar.module.css";
4
4
  export function EmptyTemplate() {
5
5
  if (process.env.NODE_ENV === "production") {
6
- return `<span class="${styles.noResults}"><span class="${styles.noResultsIcon}">${iconNoResults}</span><span>${translations.no_results}</span></span>`;
6
+ return `<span class="${styles.noResults}"><span class="${styles.noResultsIcon}">${iconNoResults}</span><span>${translate({
7
+ id: "theme.SearchBar.noResultsText",
8
+ message: "No results",
9
+ })}</span></span>`;
7
10
  }
8
11
  return `<span class="${styles.noResults}">⚠️ The search index is only available when you run docusaurus build!</span>`;
9
12
  }
@@ -3,11 +3,12 @@ import clsx from "clsx";
3
3
  import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
4
4
  import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment";
5
5
  import { useHistory, useLocation } from "@docusaurus/router";
6
+ import { translate } from "@docusaurus/Translate";
6
7
  import { fetchIndexes } from "./fetchIndexes";
7
8
  import { SearchSourceFactory } from "../../utils/SearchSourceFactory";
8
9
  import { SuggestionTemplate } from "./SuggestionTemplate";
9
10
  import { EmptyTemplate } from "./EmptyTemplate";
10
- import { searchResultLimits, Mark, translations, } from "../../utils/proxiedGenerated";
11
+ import { searchResultLimits, Mark } from "../../utils/proxiedGenerated";
11
12
  import LoadingRing from "../LoadingRing/LoadingRing";
12
13
  import styles from "./SearchBar.module.css";
13
14
  async function fetchAutoCompleteJS() {
@@ -34,6 +35,8 @@ export default function SearchBar({ handleSearchBarToggle, }) {
34
35
  const focusAfterIndexLoaded = useRef(false);
35
36
  const [loading, setLoading] = useState(false);
36
37
  const [inputChanged, setInputChanged] = useState(false);
38
+ const [inputValue, setInputValue] = useState("");
39
+ const search = useRef(null);
37
40
  const loadIndex = useCallback(async () => {
38
41
  if (indexState.current !== "empty") {
39
42
  // Do not load the index (again) if its already loaded or in the process of being loaded.
@@ -45,7 +48,7 @@ export default function SearchBar({ handleSearchBarToggle, }) {
45
48
  fetchIndexes(baseUrl),
46
49
  fetchAutoCompleteJS(),
47
50
  ]);
48
- const search = autoComplete(searchBarRef.current, {
51
+ search.current = autoComplete(searchBarRef.current, {
49
52
  hint: false,
50
53
  autoselect: true,
51
54
  openOnFocus: true,
@@ -74,11 +77,14 @@ export default function SearchBar({ handleSearchBarToggle, }) {
74
77
  const a = document.createElement("a");
75
78
  const url = `${baseUrl}search?q=${encodeURIComponent(query)}`;
76
79
  a.href = url;
77
- a.textContent = translations.see_all_results;
80
+ a.textContent = translate({
81
+ id: "theme.SearchBar.seeAll",
82
+ message: "See all results",
83
+ });
78
84
  a.addEventListener("click", (e) => {
79
85
  if (!e.ctrlKey && !e.metaKey) {
80
86
  e.preventDefault();
81
- search.autocomplete.close();
87
+ search.current.autocomplete.close();
82
88
  history.push(url);
83
89
  }
84
90
  });
@@ -113,7 +119,7 @@ export default function SearchBar({ handleSearchBarToggle, }) {
113
119
  if (focusAfterIndexLoaded.current) {
114
120
  const input = searchBarRef.current;
115
121
  if (input.value) {
116
- search.autocomplete.open();
122
+ search.current.autocomplete.open();
117
123
  }
118
124
  input.focus();
119
125
  }
@@ -125,9 +131,6 @@ export default function SearchBar({ handleSearchBarToggle, }) {
125
131
  const keywords = ExecutionEnvironment.canUseDOM
126
132
  ? new URLSearchParams(location.search).getAll(SEARCH_PARAM_HIGHLIGHT)
127
133
  : [];
128
- if (keywords.length === 0) {
129
- return;
130
- }
131
134
  // A workaround to fix an issue of highlighting in code blocks.
132
135
  // See https://github.com/easyops-cn/docusaurus-search-local/issues/92
133
136
  // Code blocks will be re-rendered after this `useEffect` ran.
@@ -139,7 +142,12 @@ export default function SearchBar({ handleSearchBarToggle, }) {
139
142
  }
140
143
  const mark = new Mark(root);
141
144
  mark.unmark();
142
- mark.mark(keywords);
145
+ if (keywords.length !== 0) {
146
+ mark.mark(keywords);
147
+ }
148
+ // Apply any keywords to the search input so that we can clear marks in case we loaded a page with a highlight in the url
149
+ setInputValue(keywords.join(" "));
150
+ search.current?.autocomplete.setVal(keywords.join(" "));
143
151
  });
144
152
  }, [location.search, location.pathname]);
145
153
  const onInputFocus = useCallback(() => {
@@ -154,6 +162,7 @@ export default function SearchBar({ handleSearchBarToggle, }) {
154
162
  loadIndex();
155
163
  }, [loadIndex]);
156
164
  const onInputChange = useCallback((event) => {
165
+ setInputValue(event.target.value);
157
166
  if (event.target.value) {
158
167
  setInputChanged(true);
159
168
  }
@@ -176,14 +185,32 @@ export default function SearchBar({ handleSearchBarToggle, }) {
176
185
  document.removeEventListener("keydown", handleShortcut);
177
186
  };
178
187
  }, [isMac, onInputFocus]);
188
+ const onClearSearch = useCallback(() => {
189
+ const params = new URLSearchParams(location.search);
190
+ params.delete(SEARCH_PARAM_HIGHLIGHT);
191
+ let paramsStr = params.toString();
192
+ let searchUrl = location.pathname + (paramsStr != "" ? `?${paramsStr}` : "") + location.hash;
193
+ if (searchUrl != location.pathname + location.search + location.hash) {
194
+ history.push(searchUrl);
195
+ }
196
+ // We always clear these here because in case no match was selected the above history push wont happen
197
+ setInputValue("");
198
+ search.current?.autocomplete.setVal("");
199
+ }, [location.pathname, location.search, location.hash]);
179
200
  return (<div className={clsx("navbar__search", styles.searchBarContainer, {
180
201
  [styles.searchIndexLoading]: loading && inputChanged,
181
202
  })}>
182
- <input placeholder={translations.search_placeholder} aria-label="Search" className="navbar__search-input" onMouseEnter={onInputMouseEnter} onFocus={onInputFocus} onBlur={onInputBlur} onChange={onInputChange} ref={searchBarRef}/>
203
+ <input placeholder={translate({
204
+ id: "theme.SearchBar.label",
205
+ message: "Search",
206
+ description: "The ARIA label and placeholder for search button",
207
+ })} aria-label="Search" className="navbar__search-input" onMouseEnter={onInputMouseEnter} onFocus={onInputFocus} onBlur={onInputBlur} onChange={onInputChange} ref={searchBarRef} value={inputValue}/>
183
208
  <LoadingRing className={styles.searchBarLoadingRing}/>
184
- <div className={styles.searchHintContainer}>
185
- <kbd className={styles.searchHint}>{isMac ? "⌘" : "ctrl"}</kbd>
186
- <kbd className={styles.searchHint}>K</kbd>
187
- </div>
209
+ {inputValue !== "" ? (<button className={styles.searchClearButton} onClick={onClearSearch}>
210
+
211
+ </button>) : (<div className={styles.searchHintContainer}>
212
+ <kbd className={styles.searchHint}>{isMac ? "⌘" : "ctrl"}</kbd>
213
+ <kbd className={styles.searchHint}>K</kbd>
214
+ </div>)}
188
215
  </div>);
189
216
  }
@@ -194,6 +194,17 @@ html[data-theme="dark"] .noResultsIcon {
194
194
  top: 6px;
195
195
  }
196
196
 
197
+ .searchBarContainer .searchClearButton {
198
+ position: absolute;
199
+ right: 0.8rem;
200
+ top: 50%;
201
+ transform: translate(0, -50%);
202
+ padding: 0;
203
+ background: none;
204
+ border: none;
205
+ line-height: 1rem;
206
+ }
207
+
197
208
  :global(.navbar__search) {
198
209
  position: relative;
199
210
  }
@@ -23,7 +23,9 @@ export function SuggestionTemplate({ document, type, page, metadata, tokens, isI
23
23
  const needsExplicitHitPath = !isInterOfTree && !isLastOfTree && explicitSearchResultPath;
24
24
  if (needsExplicitHitPath) {
25
25
  const pathItems = page
26
- ? (page.b ?? []).concat(page.t).concat(!document.s || document.s === page.t ? [] : document.s)
26
+ ? (page.b ?? [])
27
+ .concat(page.t)
28
+ .concat(!document.s || document.s === page.t ? [] : document.s)
27
29
  : document.b;
28
30
  wrapped.push(`<span class="${styles.hitPath}">${concatDocumentPath(pathItems ?? [])}</span>`);
29
31
  }
@@ -3,6 +3,8 @@ import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
3
3
  import Layout from "@theme/Layout";
4
4
  import Head from "@docusaurus/Head";
5
5
  import Link from "@docusaurus/Link";
6
+ import { translate } from "@docusaurus/Translate";
7
+ import { usePluralForm } from "@docusaurus/theme-common";
6
8
  import useSearchQuery from "../hooks/useSearchQuery";
7
9
  import { fetchIndexes } from "../SearchBar/fetchIndexes";
8
10
  import { SearchSourceFactory } from "../../utils/SearchSourceFactory";
@@ -10,21 +12,28 @@ import { highlight } from "../../utils/highlight";
10
12
  import { highlightStemmed } from "../../utils/highlightStemmed";
11
13
  import { getStemmedPositions } from "../../utils/getStemmedPositions";
12
14
  import LoadingRing from "../LoadingRing/LoadingRing";
13
- import { translations } from "../../utils/proxiedGenerated";
14
- import { simpleTemplate } from "../../utils/simpleTemplate";
15
15
  import styles from "./SearchPage.module.css";
16
16
  import { concatDocumentPath } from "../../utils/concatDocumentPath";
17
17
  export default function SearchPage() {
18
18
  const { siteConfig: { baseUrl }, } = useDocusaurusContext();
19
+ const { selectMessage } = usePluralForm();
19
20
  const { searchValue, updateSearchPath } = useSearchQuery();
20
21
  const [searchQuery, setSearchQuery] = useState(searchValue);
21
22
  const [searchSource, setSearchSource] = useState();
22
23
  const [searchResults, setSearchResults] = useState();
23
24
  const pageTitle = useMemo(() => searchQuery
24
- ? simpleTemplate(translations.search_results_for, {
25
- keyword: searchQuery,
25
+ ? translate({
26
+ id: "theme.SearchPage.existingResultsTitle",
27
+ message: 'Search results for "{query}"',
28
+ description: "The search page title for non-empty query",
29
+ }, {
30
+ query: searchQuery,
26
31
  })
27
- : translations.search_the_documentation, [searchQuery]);
32
+ : translate({
33
+ id: "theme.SearchPage.emptyResultsTitle",
34
+ message: "Search the documentation",
35
+ description: "The search page title for empty query",
36
+ }), [searchQuery]);
28
37
  useEffect(() => {
29
38
  updateSearchPath(searchQuery);
30
39
  if (searchSource) {
@@ -76,12 +85,18 @@ export default function SearchPage() {
76
85
 
77
86
  {searchResults &&
78
87
  (searchResults.length > 0 ? (<p>
79
- {simpleTemplate(searchResults.length === 1
80
- ? translations.count_documents_found
81
- : translations.count_documents_found_plural, {
82
- count: searchResults.length,
88
+ {selectMessage(searchResults.length, translate({
89
+ id: "theme.SearchPage.documentsFound.plurals",
90
+ message: "1 document found|{count} documents found",
91
+ description: 'Pluralized label for "{count} documents found". Use as much plural forms (separated by "|") as your language support (see https://www.unicode.org/cldr/cldr-aux/charts/34/supplemental/language_plural_rules.html)',
92
+ }, { count: searchResults.length }))}
93
+ </p>) : process.env.NODE_ENV === "production" ? (<p>
94
+ {translate({
95
+ id: "theme.SearchPage.noResultsText",
96
+ message: "No documents were found",
97
+ description: "The paragraph for empty search result",
83
98
  })}
84
- </p>) : process.env.NODE_ENV === "production" ? (<p>{translations.no_documents_were_found}</p>) : (<p>
99
+ </p>) : (<p>
85
100
  ⚠️ The search index is only available when you run docusaurus
86
101
  build!
87
102
  </p>))}
@@ -5,16 +5,6 @@ export const indexHash = "abc";
5
5
  export const searchResultLimits = 8;
6
6
  export const searchResultContextMaxLength = 50;
7
7
  export const explicitSearchResultPath = false;
8
- export const translations = {
9
- search_placeholder: "Search",
10
- see_all_results: "See all results",
11
- no_results: "No results.",
12
- search_results_for: 'Search results for "{{ keyword }}"',
13
- search_the_documentation: "Search the documentation",
14
- count_documents_found: "{{ count }} document found",
15
- count_documents_found_plural: "{{ count }} documents found",
16
- no_documents_were_found: "No documents were found",
17
- };
18
8
  export function __setLanguage(value) {
19
9
  language = value;
20
10
  }
@@ -1,2 +1 @@
1
1
  "use strict";
2
- // import { TranslationMap } from "./shared/interfaces";
@@ -0,0 +1,9 @@
1
+ {
2
+ "theme.SearchBar.label": "搜索",
3
+ "theme.SearchBar.seeAll": "查看全部结果",
4
+ "theme.SearchBar.noResultsText": "没有找到任何文档",
5
+ "theme.SearchPage.existingResultsTitle": "“{query}” 的搜索结果",
6
+ "theme.SearchPage.emptyResultsTitle": "搜索文档",
7
+ "theme.SearchPage.documentsFound.plurals": "共找到 {count} 篇文档",
8
+ "theme.SearchPage.noResultsText": "没有找到任何文档"
9
+ }
@@ -1,2 +1 @@
1
1
  "use strict";
2
- // import { TranslationMap } from "./shared/interfaces";
@@ -5,6 +5,7 @@ const tslib_1 = require("tslib");
5
5
  const path_1 = tslib_1.__importDefault(require("path"));
6
6
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
7
7
  const utils_1 = require("@docusaurus/utils");
8
+ const theme_translations_1 = require("@docusaurus/theme-translations");
8
9
  const processPluginOptions_1 = require("./utils/processPluginOptions");
9
10
  const postBuildFactory_1 = require("./utils/postBuildFactory");
10
11
  const generate_1 = require("./utils/generate");
@@ -25,6 +26,21 @@ function DocusaurusSearchLocalPlugin(context, options) {
25
26
  getPathsToWatch() {
26
27
  return [pagePath];
27
28
  },
29
+ getDefaultCodeTranslationMessages() {
30
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
31
+ const dirPath = path_1.default.join(__dirname, "../../locales");
32
+ const localesToTry = (0, theme_translations_1.codeTranslationLocalesToTry)(context.i18n.currentLocale);
33
+ // Return the content of the first file that match
34
+ // fr_FR.json => fr.json => nothing
35
+ for (const locale of localesToTry) {
36
+ const filePath = path_1.default.resolve(dirPath, `${locale}.json`);
37
+ if (yield fs_extra_1.default.pathExists(filePath)) {
38
+ return fs_extra_1.default.readJSON(filePath);
39
+ }
40
+ }
41
+ return {};
42
+ });
43
+ },
28
44
  contentLoaded({ actions: { addRoute } }) {
29
45
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
30
46
  addRoute({
@@ -6,7 +6,7 @@ const fs_1 = tslib_1.__importDefault(require("fs"));
6
6
  const path_1 = tslib_1.__importDefault(require("path"));
7
7
  const getIndexHash_1 = require("./getIndexHash");
8
8
  function generate(config, dir) {
9
- const { language, removeDefaultStopWordFilter, removeDefaultStemmer, highlightSearchTermsOnTargetPage, searchResultLimits, searchResultContextMaxLength, explicitSearchResultPath, translations, } = config;
9
+ const { language, removeDefaultStopWordFilter, removeDefaultStemmer, highlightSearchTermsOnTargetPage, searchResultLimits, searchResultContextMaxLength, explicitSearchResultPath, } = config;
10
10
  const indexHash = (0, getIndexHash_1.getIndexHash)(config);
11
11
  const contents = [
12
12
  `import lunr from ${JSON.stringify(require.resolve("lunr"))};`,
@@ -38,7 +38,6 @@ function generate(config, dir) {
38
38
  contents.push(`export const indexHash = ${JSON.stringify(indexHash)};`);
39
39
  contents.push(`export const searchResultLimits = ${JSON.stringify(searchResultLimits)};`, `export const searchResultContextMaxLength = ${JSON.stringify(searchResultContextMaxLength)};`);
40
40
  contents.push(`export const explicitSearchResultPath = ${JSON.stringify(explicitSearchResultPath)};`);
41
- contents.push(`export const translations = ${JSON.stringify(translations)};`);
42
41
  fs_1.default.writeFileSync(path_1.default.join(dir, "generated.js"), contents.join("\n"));
43
42
  }
44
43
  exports.generate = generate;
@@ -22,7 +22,11 @@ function getIndexHash(config) {
22
22
  console.warn(`Warn: \`${dirField}\` is not a directory: "${dir}".`);
23
23
  }
24
24
  else {
25
- files.push(...(0, klaw_sync_1.default)(dir, { nodir: true, filter: markdownFilter, traverseAll: true }));
25
+ files.push(...(0, klaw_sync_1.default)(dir, {
26
+ nodir: true,
27
+ filter: markdownFilter,
28
+ traverseAll: true,
29
+ }));
26
30
  }
27
31
  }
28
32
  }
@@ -21,18 +21,6 @@ const schema = utils_validation_1.Joi.object({
21
21
  searchResultContextMaxLength: utils_validation_1.Joi.number().default(50),
22
22
  explicitSearchResultPath: utils_validation_1.Joi.boolean().default(false),
23
23
  ignoreFiles: isArrayOfStringsOrRegExpsOrStringOrRegExp.default([]),
24
- translations: utils_validation_1.Joi.object({
25
- search_placeholder: utils_validation_1.Joi.string().default("Search"),
26
- see_all_results: utils_validation_1.Joi.string().default("See all results"),
27
- no_results: utils_validation_1.Joi.string().default("No results."),
28
- search_results_for: utils_validation_1.Joi.string().default('Search results for "{{ keyword }}"'),
29
- search_the_documentation: utils_validation_1.Joi.string().default("Search the documentation"),
30
- count_documents_found_plural: utils_validation_1.Joi.string().default((parent) => { var _a; return (_a = parent.count_documents_found) !== null && _a !== void 0 ? _a : "{{ count }} documents found"; }),
31
- count_documents_found: utils_validation_1.Joi.string().default("{{ count }} document found"),
32
- no_documents_were_found: utils_validation_1.Joi.string().default("No documents were found"),
33
- })
34
- .default()
35
- .unknown(false),
36
24
  });
37
25
  function validateOptions({ options, validate, }) {
38
26
  return validate(schema, options || {});
package/package.json CHANGED
@@ -1,20 +1,17 @@
1
1
  {
2
2
  "name": "@easyops-cn/docusaurus-search-local",
3
- "version": "0.24.1",
4
- "description": "An offline/local search plugin for Docusaurus v2.",
3
+ "version": "0.26.1",
4
+ "description": "An offline/local search plugin for Docusaurus v2",
5
5
  "repository": "https://github.com/easyops-cn/docusaurus-search-local",
6
6
  "homepage": "https://github.com/easyops-cn/docusaurus-search-local",
7
7
  "scripts": {
8
- "test": "jest",
9
- "start": "concurrently -k -n client,server \"npm run start:client\" \"npm run start:server\"",
8
+ "start": "concurrently -k -n client,server \"yarn run start:client\" \"yarn run start:server\"",
10
9
  "start:client": "tsc --watch --project tsconfig.client.json",
11
10
  "start:server": "tsc --watch --project tsconfig.server.json",
12
- "prebuild": "rimraf dist",
13
- "build": "npm run build:client && npm run build:server",
11
+ "build": "rimraf dist && yarn run build:client && yarn run build:server && yarn run copy-static-files",
14
12
  "build:client": "tsc --project tsconfig.client.json",
15
13
  "build:server": "tsc --project tsconfig.server.json",
16
- "postbuild": "copyfiles -u 3 \"src/client/theme/**/*.css\" dist/client/client/theme",
17
- "release": "standard-version"
14
+ "copy-static-files": "copyfiles -u 3 \"src/client/theme/**/*.css\" dist/client/client/theme && copyfiles -u 1 \"locales/*.json\" dist/locales"
18
15
  },
19
16
  "main": "dist/server/server/index.js",
20
17
  "files": [
@@ -26,9 +23,11 @@
26
23
  },
27
24
  "license": "MIT",
28
25
  "dependencies": {
29
- "@docusaurus/utils": "^2.0.0-beta.4",
26
+ "@docusaurus/theme-common": "^2.0.0-beta.20",
27
+ "@docusaurus/theme-translations": "^2.0.0-beta.20",
28
+ "@docusaurus/utils": "^2.0.0-beta.20",
30
29
  "@docusaurus/utils-common": "^2.0.0-beta.20",
31
- "@docusaurus/utils-validation": "^2.0.0-beta.4",
30
+ "@docusaurus/utils-validation": "^2.0.0-beta.20",
32
31
  "@easyops-cn/autocomplete.js": "^0.38.1",
33
32
  "@node-rs/jieba": "^1.6.0",
34
33
  "cheerio": "^1.0.0-rc.3",
@@ -42,44 +41,25 @@
42
41
  "tslib": "^2.4.0"
43
42
  },
44
43
  "devDependencies": {
45
- "@babel/core": "^7.12.3",
46
- "@babel/preset-env": "^7.12.1",
47
- "@babel/preset-react": "^7.12.1",
48
- "@babel/preset-typescript": "^7.12.1",
49
- "@docusaurus/module-type-aliases": "^2.0.0-beta.4",
44
+ "@docusaurus/module-type-aliases": "^2.0.0-beta.20",
45
+ "@docusaurus/types": "^2.0.0-beta.20",
50
46
  "@tsconfig/docusaurus": "^1.0.2",
51
47
  "@types/cheerio": "^0.22.31",
52
48
  "@types/debug": "^4.1.5",
53
- "@types/enzyme": "^3.10.7",
54
- "@types/enzyme-adapter-react-16": "^1.0.6",
55
49
  "@types/fs-extra": "^9.0.2",
56
50
  "@types/jest": "^27.0.0",
57
51
  "@types/klaw-sync": "^6.0.0",
58
52
  "@types/lunr": "^2.3.3",
59
- "@types/react": "^16.9.55",
60
- "@types/react-dom": "^16.9.8",
53
+ "@types/node": "^17.0.34",
54
+ "@types/react": "^18.0.0",
61
55
  "@types/react-helmet": "^6.1.0",
62
56
  "@types/react-router-dom": "^5.1.6",
63
- "@typescript-eslint/eslint-plugin": "^5.0.0",
64
- "@typescript-eslint/parser": "^5.0.0",
65
- "babel-jest": "^28.0.0",
66
57
  "concurrently": "^7.0.0",
67
58
  "copyfiles": "^2.4.0",
68
- "enzyme": "^3.11.0",
69
- "enzyme-adapter-react-16": "^1.15.5",
70
- "enzyme-to-json": "^3.6.1",
71
- "eslint": "^8.0.0",
72
- "eslint-config-prettier": "^8.0.0",
73
- "eslint-plugin-react": "^7.21.4",
74
- "eslint-plugin-react-hooks": "^4.1.2",
75
- "husky": "^8.0.0",
76
- "identity-obj-proxy": "^3.0.0",
77
- "jest": "^28.0.0",
78
- "jest-environment-jsdom": "^28.1.0",
79
- "lint-staged": "^12.0.0",
80
- "prettier": "^2.1.2",
81
59
  "rimraf": "^3.0.2",
82
- "standard-version": "^9.0.0",
83
60
  "typescript": "^4.6.4"
61
+ },
62
+ "peerDependencies": {
63
+ "react": "^16.14.0 || 17 || 18"
84
64
  }
85
- }
65
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2020 优维科技
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/README.md DELETED
@@ -1,166 +0,0 @@
1
- # @easyops-cn/docusaurus-search-local
2
-
3
- [![Npm Version](https://img.shields.io/npm/v/@easyops-cn/docusaurus-search-local)](https://www.npmjs.com/package/@easyops-cn/docusaurus-search-local)
4
- [![CI Status](https://github.com/easyops-cn/docusaurus-search-local/workflows/CI/badge.svg?event=push)](https://github.com/easyops-cn/docusaurus-search-local/actions?query=workflow%3ACI)
5
- [![Coverage Status](https://coveralls.io/repos/github/easyops-cn/docusaurus-search-local/badge.svg?branch=master)](https://coveralls.io/github/easyops-cn/docusaurus-search-local?branch=master)
6
-
7
- An offline/local search plugin/theme for [Docusaurus v2](https://v2.docusaurus.io/), which supports multiple languages, especially optimized for language of zh.
8
-
9
- > Originally forked from [cmfcmf/docusaurus-search-local](https://github.com/cmfcmf/docusaurus-search-local).
10
- >
11
- > Then later fully rewritten with TypeScript 💪, styles polished 💅, language of Chinese supported 🇨🇳, and tests covered ✅.
12
-
13
- - [Live Demo](#live-demo)
14
- - [Screen Shots](#screen-shots)
15
- - [Installation](#installation)
16
- - [Usage](#usage)
17
- - [Theme Options](#theme-options)
18
- - [Custom Styles](#custom-styles)
19
- - [Trouble Shooting](#trouble-shooting)
20
- - [Further Reading](#further-reading)
21
- - [Contributing](#contributing)
22
-
23
- ## Live Demo
24
-
25
- https://easyops-cn.github.io/docusaurus-search-example/
26
-
27
- ## Screen Shots
28
-
29
- ![Screen Shot EN](screen-shots/screen-shot-en.png)
30
-
31
- ![Screen Shot ZH](screen-shots/screen-shot-zh.png)
32
-
33
- ## Installation
34
-
35
- ```shell
36
- npm install --save @easyops-cn/docusaurus-search-local
37
- # or
38
- yarn add @easyops-cn/docusaurus-search-local
39
- ```
40
-
41
- ## Usage
42
-
43
- Add `@easyops-cn/docusaurus-search-local` into your docusaurus themes.
44
-
45
- ````js
46
- // In your `docusaurus.config.js`:
47
- module.exports = {
48
- // ... Your other configurations.
49
- themes: [
50
- // ... Your other themes.
51
- [
52
- require.resolve("@easyops-cn/docusaurus-search-local"),
53
- {
54
- // ... Your options.
55
- // `hashed` is recommended as long-term-cache of index file is possible.
56
- hashed: true,
57
- explicitSearchResultPath: true,
58
- // For Docs using Chinese, The `language` is recommended to set to:
59
- // ```
60
- // language: ["en", "zh"],
61
- // ```
62
- },
63
- ],
64
- ],
65
- };
66
- ````
67
-
68
- > Notice: We present this as a theme instead of plugin now, see [this comment](https://github.com/facebook/docusaurus/issues/6488#issuecomment-1024124096).
69
-
70
- ## Theme Options
71
-
72
- | Name | Type | Default | Description |
73
- | -------------------------------- | ---------------------------------------- | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
74
- | indexDocs | boolean | `true` | Whether to index docs. |
75
- | indexBlog | boolean | `true` | Whether to index blog. |
76
- | indexPages | boolean | `false` | Whether to index pages. |
77
- | docsRouteBasePath | string \| string[] | `"/docs"` | Base route path(s) of docs. Slash at beginning is not required. Note: for [docs-only mode](https://docusaurus.io/docs/docs-introduction#docs-only-mode), this needs to be the same as `routeBasePath` in your `@docusaurus/preset-classic` config e.g., `"/"`. |
78
- | blogRouteBasePath | string \| string[] | `"/blog"` | Base route path(s) of blog. Slash at beginning is not required. |
79
- | language | string \| string[] | `"en"` | All [lunr-languages](https://github.com/MihaiValentin/lunr-languages) supported languages, + `zh` 🔥. |
80
- | hashed | boolean | `false` | Whether to add a hashed query when fetching index (based on the content hash of all indexed `*.md` in `docsDir` and `blogDir` if applicable) |
81
- | docsDir | string \| string[] | `"docs"` | The dir(s) of docs to get the content hash, it's relative to the dir of your project. |
82
- | blogDir | string \| string[] | `"blog"` | Just like the `docsDir` but applied to blog. |
83
- | removeDefaultStopWordFilter | boolean | `false` | Sometimes people (E.g., us) want to keep the English stop words as indexed, since they maybe are relevant in programming docs. |
84
- | removeDefaultStemmer | boolean | `false` | Enable this if you want to be able to search for any partial word at the cost of search performance. |
85
- | highlightSearchTermsOnTargetPage | boolean | `false` | Highlight search terms on target page. |
86
- | searchResultLimits | number | `8` | Limit the search results. |
87
- | searchResultContextMaxLength | number | `50` | Set the max length of characters of each search result to show. |
88
- | explicitSearchResultPath | boolean | false | Whether an explicit path to a heading should be presented on a suggestion template. |
89
- | translations | TranslationMap | - | Set translations of this theme, see [docs below](#translations). |
90
- | ignoreFiles | string \| RegExp \| (string \| RegExp)[] | /**meta**\$/ | Set the match rules to ignore some files. |
91
-
92
- ### Translations
93
-
94
- To make this theme localized, pass a `translations` option which defaults to:
95
-
96
- ```json
97
- {
98
- "search_placeholder": "Search",
99
- "see_all_results": "See all results",
100
- "no_results": "No results.",
101
- "search_results_for": "Search results for \"{{ keyword }}\"",
102
- "search_the_documentation": "Search the documentation",
103
- "count_documents_found": "{{ count }} document found",
104
- "count_documents_found_plural": "{{ count }} documents found",
105
- "no_documents_were_found": "No documents were found"
106
- }
107
- ```
108
-
109
- Note that `*_plural` can be omitted if it is the same as singular.
110
-
111
- ## Custom Styles
112
-
113
- This theme is shipped with polished styles just like the Algolia Search on the Docusaurus v2 website. Feel free to override these css custom properties (css variables) below.
114
-
115
- | Var | Default (light) | Default (dark) |
116
- | -------------------------------- | ---------------------------------------------------------------------- | ------------------------------------------------------- |
117
- | --search-local-modal-background | `#f5f6f7` | `var(--ifm-background-color)` |
118
- | --search-local-modal-shadow | `inset 1px 1px 0 0 hsla(0, 0%, 100%, 0.5),`<br />`0 3px 8px 0 #555a64` | `inset 1px 1px 0 0 #2c2e40,`<br />`0 3px 8px 0 #000309` |
119
- | --search-local-modal-width | `560px` | - |
120
- | --search-local-modal-width-sm | `340px` | - |
121
- | --search-local-spacing | `12px` | - |
122
- | --search-local-hit-background | `#fff` | `var(--ifm-color-emphasis-100)` |
123
- | --search-local-hit-shadow | `0 1px 3px 0 #d4d9e1` | `none` |
124
- | --search-local-hit-color | `#444950` | `var(--ifm-font-color-base)` |
125
- | --search-local-hit-height | `56px` | - |
126
- | --search-local-highlight-color | `var(--ifm-color-primary)` | - |
127
- | --search-local-muted-color | `#969faf` | `var(--ifm-color-secondary-darkest)` |
128
- | --search-local-icon-stroke-width | `1.4` | - |
129
- | --search-local-hit-active-color | `var(--ifm-color-white)` | - |
130
-
131
- E.g.:
132
-
133
- ```css
134
- :root {
135
- --search-local-modal-width: 480px;
136
- --search-local-highlight-color: #5468ff;
137
- }
138
-
139
- html[data-theme="dark"] {
140
- --search-local-highlight-color: #d23669;
141
- }
142
- ```
143
-
144
- ## Trouble Shooting
145
-
146
- When building your docs project, Set the env `DEBUG=search-local:*` to enable [debug](https://github.com/visionmedia/debug) logs.
147
-
148
- ```shell
149
- # In your docs project:
150
- DEBUG=search-local:* yarn build
151
- ```
152
-
153
- In case some specific errors occurred:
154
-
155
- - `Error: Cannot mix different versions of joi schemas`:
156
- - Try using @easyops-cn/docusaurus-search-local >= v0.16.0 with Docusaurus >= v2.0.0-alpha.73
157
- - Try using @easyops-cn/docusaurus-search-local between v0.14.0 and v0.15.1 with Docusaurus between v2.0.0-alpha.68 and v2.0.0-alpha.72
158
- - Or try using @easyops-cn/docusaurus-search-local <= v0.13.1 with Docusaurus <= v2.0.0-alpha.66
159
-
160
- ## Further Reading
161
-
162
- - [多语言全文搜索](https://wangshenwei.com/multilingual-full-text-search/)
163
-
164
- ## Contributing
165
-
166
- See [contributing guide](CONTRIBUTING.md).
@@ -1,8 +0,0 @@
1
- export function simpleTemplate(template, params) {
2
- return template.replace(/\{\{\s*(\w+)\s*\}\}/g, (raw, keyword) => {
3
- if (Object.prototype.hasOwnProperty.call(params, keyword)) {
4
- return String(params[keyword]);
5
- }
6
- return raw;
7
- });
8
- }