@easyops-cn/docusaurus-search-local 0.34.0 → 0.35.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/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.35.0](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.34.0...v0.35.0) (2023-03-04)
6
+
7
+
8
+ ### Features
9
+
10
+ * improve no results UI when searching in context ([#323](https://github.com/easyops-cn/docusaurus-search-local/issues/323)) ([1a70835](https://github.com/easyops-cn/docusaurus-search-local/commit/1a708353d5fc6edae0f6e7d16bbd6e32381a9ea1))
11
+
5
12
  ## [0.34.0](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.33.6...v0.34.0) (2023-02-16)
6
13
 
7
14
 
@@ -102,6 +102,53 @@ export default function SearchBar({ handleSearchBarToggle, }) {
102
102
  fetchIndexes(versionUrl, searchContext),
103
103
  fetchAutoCompleteJS(),
104
104
  ]);
105
+ const searchFooterLinkElement = ({ query, isEmpty, }) => {
106
+ const a = document.createElement("a");
107
+ const params = new URLSearchParams();
108
+ const seeAllResultsText = translate({
109
+ id: "theme.SearchBar.seeAll",
110
+ message: "See all results",
111
+ });
112
+ const seeAllResultsOutsideContextText = translate({
113
+ id: "theme.SearchBar.seeAllOutsideContext",
114
+ message: "See results outside {context}",
115
+ }, { context: searchContext });
116
+ const seeAllResultsInContextText = translate({
117
+ id: "theme.SearchBar.searchInContext",
118
+ message: "See all results in {context}",
119
+ }, { context: searchContext });
120
+ params.set("q", query);
121
+ let linkText;
122
+ if (searchContext && isEmpty) {
123
+ linkText = seeAllResultsOutsideContextText;
124
+ }
125
+ else if (searchContext) {
126
+ linkText = seeAllResultsInContextText;
127
+ }
128
+ else {
129
+ linkText = seeAllResultsText;
130
+ }
131
+ if (Array.isArray(searchContextByPaths) && !isEmpty) {
132
+ params.set("ctx", searchContext);
133
+ }
134
+ if (versionUrl !== baseUrl) {
135
+ if (!versionUrl.startsWith(baseUrl)) {
136
+ throw new Error(`Version url '${versionUrl}' does not start with base url '${baseUrl}', this is a bug of \`@easyops-cn/docusaurus-search-local\`, please report it.`);
137
+ }
138
+ params.set("version", versionUrl.substring(baseUrl.length));
139
+ }
140
+ const url = `${baseUrl}search?${params.toString()}`;
141
+ a.href = url;
142
+ a.textContent = linkText;
143
+ a.addEventListener("click", (e) => {
144
+ if (!e.ctrlKey && !e.metaKey) {
145
+ e.preventDefault();
146
+ search.current?.autocomplete.close();
147
+ history.push(url);
148
+ }
149
+ });
150
+ return a;
151
+ };
105
152
  search.current = autoComplete(searchBarRef.current, {
106
153
  hint: false,
107
154
  autoselect: true,
@@ -127,39 +174,10 @@ export default function SearchBar({ handleSearchBarToggle, }) {
127
174
  suggestion: SuggestionTemplate,
128
175
  empty: EmptyTemplate,
129
176
  footer: ({ query, isEmpty }) => {
130
- if (isEmpty) {
177
+ if (isEmpty && !searchContext) {
131
178
  return;
132
179
  }
133
- const a = document.createElement("a");
134
- const params = new URLSearchParams();
135
- params.set("q", query);
136
- if (Array.isArray(searchContextByPaths)) {
137
- params.set("ctx", searchContext);
138
- }
139
- if (versionUrl !== baseUrl) {
140
- if (!versionUrl.startsWith(baseUrl)) {
141
- throw new Error(`Version url '${versionUrl}' does not start with base url '${baseUrl}', this is a bug of \`@easyops-cn/docusaurus-search-local\`, please report it.`);
142
- }
143
- params.set("version", versionUrl.substring(baseUrl.length));
144
- }
145
- const url = `${baseUrl}search?${params.toString()}`;
146
- a.href = url;
147
- a.textContent = searchContext
148
- ? translate({
149
- id: "theme.SearchBar.searchInContext",
150
- message: "See all results in {context}",
151
- }, { context: searchContext })
152
- : translate({
153
- id: "theme.SearchBar.seeAll",
154
- message: "See all results",
155
- });
156
- a.addEventListener("click", (e) => {
157
- if (!e.ctrlKey && !e.metaKey) {
158
- e.preventDefault();
159
- search.current?.autocomplete.close();
160
- history.push(url);
161
- }
162
- });
180
+ const a = searchFooterLinkElement({ query, isEmpty });
163
181
  const div = document.createElement("div");
164
182
  div.className = styles.hitFooter;
165
183
  div.appendChild(a);
@@ -86,14 +86,15 @@ function SearchPageContent() {
86
86
  <h1>{pageTitle}</h1>
87
87
 
88
88
  <div className="row">
89
- <div className={clsx("col", styles.searchQueryColumn, {
89
+ <div className={clsx("col", {
90
+ [styles.searchQueryColumn]: Array.isArray(searchContextByPaths),
90
91
  "col--9": Array.isArray(searchContextByPaths),
91
92
  "col--12": !Array.isArray(searchContextByPaths),
92
93
  })}>
93
94
  <input type="search" name="q" className={styles.searchQueryInput} aria-label="Search" onChange={handleSearchInputChange} value={searchQuery} autoComplete="off" autoFocus/>
94
95
  </div>
95
- {Array.isArray(searchContextByPaths) ? (<div className={clsx("col", "col--3", "padding-left--none", styles.searchVersionColumn)}>
96
- <select name="search-context" className={styles.searchVersionInput} id="context-selector" value={searchContext} onChange={(e) => updateSearchContext(e.target.value)}>
96
+ {Array.isArray(searchContextByPaths) ? (<div className={clsx("col", "col--3", "padding-left--none", styles.searchContextColumn)}>
97
+ <select name="search-context" className={styles.searchContextInput} id="context-selector" value={searchContext} onChange={(e) => updateSearchContext(e.target.value)}>
97
98
  <option value="">
98
99
  {useAllContextsWithNoSearchContext
99
100
  ? translate({
@@ -1,4 +1,4 @@
1
- .searchVersionInput,
1
+ .searchContextInput,
2
2
  .searchQueryInput {
3
3
  border-radius: var(--ifm-global-radius);
4
4
  border: var(--ifm-global-border-width) solid
@@ -30,3 +30,24 @@
30
30
  font-style: italic;
31
31
  margin: 0.5rem 0px 0px;
32
32
  }
33
+
34
+ @media only screen and (max-width: 996px) {
35
+ .searchQueryColumn {
36
+ max-width: 60% !important;
37
+ }
38
+
39
+ .searchContextColumn {
40
+ max-width: 40% !important;
41
+ }
42
+ }
43
+
44
+ @media screen and (max-width: 576px) {
45
+ .searchQueryColumn {
46
+ max-width: 100% !important;
47
+ }
48
+
49
+ .searchContextColumn {
50
+ max-width: 100% !important;
51
+ padding-left: var(--ifm-spacing-horizontal) !important;
52
+ }
53
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyops-cn/docusaurus-search-local",
3
- "version": "0.34.0",
3
+ "version": "0.35.0",
4
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",