@easyops-cn/docusaurus-search-local 0.19.0 → 0.21.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,6 +2,36 @@
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.21.1](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.21.0...v0.21.1) (2021-12-07)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * 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)
11
+
12
+ ## [0.21.0](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.20.0...v0.21.0) (2021-12-04)
13
+
14
+
15
+ ### Features
16
+
17
+ * add shortcut (cmd/ctrl + K) support ([f12403f](https://www.github.com/easyops-cn/docusaurus-search-local/commit/f12403fc6bc48b489d8ef170aecad2262f3a4ebc))
18
+
19
+ ## [0.20.0](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.19.1...v0.20.0) (2021-11-12)
20
+
21
+
22
+ ### Features
23
+
24
+ * remove nodejieba from peerDependencies ([e76bb64](https://www.github.com/easyops-cn/docusaurus-search-local/commit/e76bb6490b749cab6b17607349ab04f226d8eee4))
25
+
26
+ ### [0.19.1](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.19.0...v0.19.1) (2021-08-03)
27
+
28
+
29
+ ### Bug Fixes
30
+
31
+ * fix docsRouteBasePath or blogRouteBasePath set to "/" ([a1b1df6](https://www.github.com/easyops-cn/docusaurus-search-local/commit/a1b1df6d59ab309ca68c18494ac72f8aa6a1b370))
32
+ * fix search page ignore ([9841cc8](https://www.github.com/easyops-cn/docusaurus-search-local/commit/9841cc8b910d5a1b2ea9fe896ec5acdde0b2faf0))
33
+ * refine get site config ([e215a1a](https://www.github.com/easyops-cn/docusaurus-search-local/commit/e215a1a5ceef1751233996e5a48c57fa9ca25d1e))
34
+
5
35
  ## [0.19.0](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.18.1...v0.19.0) (2021-08-03)
6
36
 
7
37
 
package/README.md CHANGED
@@ -67,7 +67,7 @@ module.exports = {
67
67
 
68
68
  > Notice!
69
69
  >
70
- > When applying `"zh"` in language, please also install `nodejieba` in your project, it became a peer dependency since v0.7.0.
70
+ > When applying `"zh"` in language, please also install `nodejieba` in your project, which is required for tokenizing Chinese words. It is removed from peerDependencies since v0.20.0, so you have to install it manually even if you're using npm v7+.
71
71
 
72
72
  ```shell
73
73
  npm install nodejieba
@@ -152,10 +152,34 @@ export default function SearchBar({ handleSearchBarToggle, }) {
152
152
  setInputChanged(true);
153
153
  }
154
154
  }, []);
155
+ // Implement hint icons for the search shortcuts on mac and the rest operating systems.
156
+ const isMac = ExecutionEnvironment.canUseDOM
157
+ ? /mac/i.test(navigator.userAgentData?.platform ?? navigator.platform)
158
+ : false;
159
+ useEffect(() => {
160
+ // Add shortcuts command/ctrl + K
161
+ function handleShortcut(event) {
162
+ if ((isMac ? event.metaKey : event.ctrlKey) && event.code === "KeyK") {
163
+ event.preventDefault();
164
+ searchBarRef.current?.focus();
165
+ }
166
+ }
167
+ // "keydown" is the only way to capture the "command" key on mac.
168
+ // Then we use the metaKey boolean prop to see if the "command" key was pressed.
169
+ const eventType = isMac ? "keydown" : "keypress";
170
+ document.addEventListener(eventType, handleShortcut);
171
+ return () => {
172
+ document.removeEventListener(eventType, handleShortcut);
173
+ };
174
+ }, [isMac]);
155
175
  return (<div className={clsx("navbar__search", styles.searchBarContainer, {
156
176
  [styles.searchIndexLoading]: loading && inputChanged,
157
177
  })}>
158
178
  <input placeholder={translations.search_placeholder} aria-label="Search" className="navbar__search-input" onMouseEnter={onInputMouseEnter} onFocus={onInputFocus} onBlur={onInputBlur} onChange={onInputChange} ref={searchBarRef}/>
159
179
  <LoadingRing className={styles.searchBarLoadingRing}/>
180
+ <div className={styles.searchHintContainer}>
181
+ <kbd className={styles.searchHint}>{isMac ? "⌘" : "ctrl"}</kbd>
182
+ <kbd className={styles.searchHint}>K</kbd>
183
+ </div>
160
184
  </div>);
161
185
  }
@@ -189,7 +189,7 @@ html[data-theme="dark"] .noResultsIcon {
189
189
  .searchBarContainer .searchBarLoadingRing {
190
190
  display: none;
191
191
  position: absolute;
192
- left: calc(var(--ifm-navbar-padding-horizontal) + 10px);
192
+ left: 10px;
193
193
  top: 6px;
194
194
  }
195
195
 
@@ -205,6 +205,28 @@ html[data-theme="dark"] .noResultsIcon {
205
205
  display: inline-block;
206
206
  }
207
207
 
208
+ .searchHintContainer {
209
+ position: absolute;
210
+ right: 10px;
211
+ top: 0px;
212
+ display: flex;
213
+ align-items: center;
214
+ justify-content: center;
215
+ height: 100%;
216
+ pointer-events: none;
217
+ gap: 4px;
218
+ }
219
+
220
+ .searchHint {
221
+ color: var(--ifm-navbar-search-input-placeholder-color);
222
+ }
223
+
224
+ @media (max-width: 576px) {
225
+ .searchHintContainer {
226
+ display: none;
227
+ }
228
+ }
229
+
208
230
  /* For autocomplete.js only. */
209
231
  .input {
210
232
  }
@@ -5,7 +5,8 @@
5
5
  font-size: var(--ifm-font-size-base);
6
6
  padding: 0.5rem;
7
7
  width: 100%;
8
- background: #fff;
8
+ background: var(--ifm-background-color);
9
+ color: var(--ifm-font-color-base);
9
10
  margin-bottom: 1rem;
10
11
  }
11
12
 
@@ -21,7 +21,7 @@ function DocusaurusSearchLocalPlugin(context, options) {
21
21
  getThemePath() {
22
22
  return themePath;
23
23
  },
24
- postBuild: postBuildFactory_1.postBuildFactory(config, context.siteConfig),
24
+ postBuild: postBuildFactory_1.postBuildFactory(config),
25
25
  getPathsToWatch() {
26
26
  return [pagePath];
27
27
  },
@@ -10,11 +10,11 @@ const debug_1 = require("./debug");
10
10
  const processDocInfos_1 = require("./processDocInfos");
11
11
  const scanDocuments_1 = require("./scanDocuments");
12
12
  const writeFileAsync = util_1.default.promisify(fs_1.default.writeFile);
13
- function postBuildFactory(config, siteConfig) {
13
+ function postBuildFactory(config) {
14
14
  return function postBuild(buildData) {
15
15
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
16
16
  debug_1.debugInfo("gathering documents");
17
- const data = processDocInfos_1.processDocInfos(buildData, config, siteConfig);
17
+ const data = processDocInfos_1.processDocInfos(buildData, config);
18
18
  debug_1.debugInfo("parsing documents");
19
19
  // Give every index entry a unique id so that the index does not need to store long URLs.
20
20
  const allDocuments = yield scanDocuments_1.scanDocuments(data);
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processDocInfos = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const path_1 = tslib_1.__importDefault(require("path"));
6
- function processDocInfos({ routesPaths, outDir, baseUrl }, { indexDocs, indexBlog, indexPages, docsRouteBasePath, blogRouteBasePath, ignoreFiles, }, siteConfig) {
6
+ function processDocInfos({ routesPaths, outDir, baseUrl, siteConfig }, { indexDocs, indexBlog, indexPages, docsRouteBasePath, blogRouteBasePath, ignoreFiles, }) {
7
7
  return routesPaths
8
8
  .map((url) => {
9
9
  // istanbul ignore next
@@ -12,12 +12,7 @@ function processDocInfos({ routesPaths, outDir, baseUrl }, { indexDocs, indexBlo
12
12
  }
13
13
  const route = url.substr(baseUrl.length).replace(/\/$/, "");
14
14
  // Do not index homepage, error page and search page.
15
- if (route === "" ||
16
- route === "404.html" ||
17
- route ===
18
- (siteConfig.trailingSlash === false
19
- ? "search.html"
20
- : "search/index.html")) {
15
+ if (route === "" || route === "404.html" || route === "search") {
21
16
  return;
22
17
  }
23
18
  // ignore files
@@ -32,7 +27,7 @@ function processDocInfos({ routesPaths, outDir, baseUrl }, { indexDocs, indexBlo
32
27
  if (indexBlog &&
33
28
  blogRouteBasePath.some((basePath) => isSameOrSubRoute(route, basePath))) {
34
29
  if (blogRouteBasePath.some((basePath) => isSameRoute(route, basePath) ||
35
- isSameOrSubRoute(route, `${basePath}/tags`))) {
30
+ isSameOrSubRoute(route, path_1.default.posix.join(basePath, "tags")))) {
36
31
  // Do not index list of blog posts and tags filter pages
37
32
  return;
38
33
  }
@@ -61,7 +56,8 @@ function isSameRoute(routeA, routeB) {
61
56
  return addTrailingSlash(routeA) === addTrailingSlash(routeB);
62
57
  }
63
58
  function isSameOrSubRoute(childRoute, parentRoute) {
64
- return addTrailingSlash(childRoute).startsWith(addTrailingSlash(parentRoute));
59
+ return (parentRoute === "" ||
60
+ addTrailingSlash(childRoute).startsWith(addTrailingSlash(parentRoute)));
65
61
  }
66
62
  // The input route must not end with a slash.
67
63
  function addTrailingSlash(route) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyops-cn/docusaurus-search-local",
3
- "version": "0.19.0",
3
+ "version": "0.21.1",
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",
@@ -78,8 +78,5 @@
78
78
  "rimraf": "^3.0.2",
79
79
  "standard-version": "^9.0.0",
80
80
  "typescript": "^4.0.3"
81
- },
82
- "peerDependencies": {
83
- "nodejieba": "^2.4.1"
84
81
  }
85
82
  }