@easyops-cn/docusaurus-search-local 0.22.0 → 0.23.2

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,27 @@
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.23.2](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.23.1...v0.23.2) (2022-04-25)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * install cheerio types ([0a45f41](https://www.github.com/easyops-cn/docusaurus-search-local/commit/0a45f41bd02d8305328705bcc6582b92ed2ccf78))
11
+
12
+ ### [0.23.1](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.23.0...v0.23.1) (2022-04-07)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * parse `h1` from the whole `article` ([aeb063a](https://www.github.com/easyops-cn/docusaurus-search-local/commit/aeb063af9dbac9778e3436aa261e0c131a2ef8c2))
18
+
19
+ ## [0.23.0](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.22.0...v0.23.0) (2022-03-10)
20
+
21
+
22
+ ### Features
23
+
24
+ * replace nodejieba with @node-rs/jieba ([f3f7594](https://www.github.com/easyops-cn/docusaurus-search-local/commit/f3f7594d0a97075a4aefa19e15f2d1f961bbb824))
25
+
5
26
  ## [0.22.0](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.21.4...v0.22.0) (2022-02-28)
6
27
 
7
28
 
package/README.md CHANGED
@@ -58,24 +58,13 @@ module.exports = {
58
58
  // ```
59
59
  // language: ["en", "zh"],
60
60
  // ```
61
- // When applying `zh` in language, please install `nodejieba` in your project.
62
61
  },
63
62
  ],
64
63
  ],
65
64
  };
66
65
  ````
67
66
 
68
- > Notice!
69
- >
70
- > - We present this as a theme instead of plugin now, see [this comment](https://github.com/facebook/docusaurus/issues/6488#issuecomment-1024124096).
71
- >
72
- > - 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+.
73
-
74
- ```shell
75
- npm install nodejieba
76
- # or
77
- yarn add nodejieba
78
- ```
67
+ > Notice: We present this as a theme instead of plugin now, see [this comment](https://github.com/facebook/docusaurus/issues/6488#issuecomment-1024124096).
79
68
 
80
69
  ## Theme Options
81
70
 
@@ -94,7 +83,8 @@ yarn add nodejieba
94
83
  | highlightSearchTermsOnTargetPage | boolean | `false` | Highlight search terms on target page. |
95
84
  | searchResultLimits | number | `8` | Limit the search results. |
96
85
  | searchResultContextMaxLength | number | `50` | Set the max length of characters of each search result to show. |
97
- | translations | TranslationMap | - | Set translations of this theme, see [docs below](#translations). |
86
+ | explicitSearchResultPath | boolean | false | Whether an explicit path to a heading should be presented on a suggestion template. |
87
+ | translations | TranslationMap | - | Set translations of this theme, see [docs below](#translations). |
98
88
  | ignoreFiles | string \| RegExp \| (string \| RegExp)[] | /**meta**\$/ | Set the match rules to ignore some files. |
99
89
 
100
90
  ### Translations
@@ -164,9 +154,6 @@ In case some specific errors occurred:
164
154
  - Try using @easyops-cn/docusaurus-search-local >= v0.16.0 with Docusaurus >= v2.0.0-alpha.73
165
155
  - 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
166
156
  - Or try using @easyops-cn/docusaurus-search-local <= v0.13.1 with Docusaurus <= v2.0.0-alpha.66
167
- - `Error: Command failed with signal "SIGSEGV"`:
168
- - This is probably caused by a [known issue](https://github.com/yanyiwu/nodejieba/issues/187) introduced by `nodejieba@2.5.2`, if you enabled language of zh.
169
- - Try downgrading `nodejieba` to `2.4.2` and it will work again, see discussions in [#47](https://github.com/easyops-cn/docusaurus-search-local/issues/47).
170
157
 
171
158
  ## Further Reading
172
159
 
@@ -1,7 +1,9 @@
1
+ import { concatDocumentPath } from "../../utils/concatDocumentPath";
2
+ import { getStemmedPositions } from "../../utils/getStemmedPositions";
1
3
  import { highlight } from "../../utils/highlight";
2
4
  import { highlightStemmed } from "../../utils/highlightStemmed";
3
- import { getStemmedPositions } from "../../utils/getStemmedPositions";
4
- import { iconTitle, iconHeading, iconContent, iconAction, iconTreeInter, iconTreeLast, } from "./icons";
5
+ import { explicitSearchResultPath } from "../../utils/proxiedGenerated";
6
+ import { iconAction, iconContent, iconHeading, iconTitle, iconTreeInter, iconTreeLast, } from "./icons";
5
7
  import styles from "./SearchBar.module.css";
6
8
  export function SuggestionTemplate({ document, type, page, metadata, tokens, isInterOfTree, isLastOfTree, }) {
7
9
  const isTitle = type === 0;
@@ -18,7 +20,14 @@ export function SuggestionTemplate({ document, type, page, metadata, tokens, isI
18
20
  const wrapped = [
19
21
  `<span class="${styles.hitTitle}">${highlightStemmed(document.t, getStemmedPositions(metadata, "t"), tokens)}</span>`,
20
22
  ];
21
- if (!isTitle) {
23
+ const needsExplicitHitPath = !isInterOfTree && !isLastOfTree && explicitSearchResultPath;
24
+ if (needsExplicitHitPath) {
25
+ const pathItems = page
26
+ ? (page.b ?? []).concat(page.t).concat(document.s ?? [])
27
+ : document.b;
28
+ wrapped.push(`<span class="${styles.hitPath}">${concatDocumentPath(pathItems ?? [])}</span>`);
29
+ }
30
+ else if (!isTitle) {
22
31
  wrapped.push(`<span class="${styles.hitPath}">${highlight(page.t ||
23
32
  // Todo(weareoutman): This is for EasyOps only.
24
33
  // istanbul ignore next
@@ -13,6 +13,7 @@ import LoadingRing from "../LoadingRing/LoadingRing";
13
13
  import { translations } from "../../utils/proxiedGenerated";
14
14
  import { simpleTemplate } from "../../utils/simpleTemplate";
15
15
  import styles from "./SearchPage.module.css";
16
+ import { concatDocumentPath } from "../../utils/concatDocumentPath";
16
17
  export default function SearchPage() {
17
18
  const { siteConfig: { baseUrl }, } = useDocusaurusContext();
18
19
  const { searchValue, updateSearchPath } = useSearchQuery();
@@ -54,10 +55,11 @@ export default function SearchPage() {
54
55
  }
55
56
  doFetchIndexes();
56
57
  }, [baseUrl]);
57
- return (<Layout title={pageTitle}>
58
+ return (<Layout>
58
59
  <Head>
59
60
 
60
61
  <meta property="robots" content="noindex, follow"/>
62
+ <title>{pageTitle}</title>
61
63
  </Head>
62
64
 
63
65
  <div className="container margin-vert--lg">
@@ -91,9 +93,7 @@ export default function SearchPage() {
91
93
  function SearchResultItem({ searchResult: { document, type, page, tokens, metadata }, }) {
92
94
  const isTitle = type === 0;
93
95
  const isContent = type === 2;
94
- const pathItems = (isTitle
95
- ? document.b
96
- : page.b).slice();
96
+ const pathItems = (isTitle ? document.b : page.b).slice();
97
97
  const articleTitle = (isContent ? document.s : document.t);
98
98
  if (!isTitle) {
99
99
  pathItems.push(page.t);
@@ -106,7 +106,9 @@ function SearchResultItem({ searchResult: { document, type, page, tokens, metada
106
106
  : highlightStemmed(articleTitle, getStemmedPositions(metadata, "t"), tokens, 100),
107
107
  }}></Link>
108
108
  </h2>
109
- {pathItems.length > 0 && (<p className={styles.searchResultItemPath}>{pathItems.join(" › ")}</p>)}
109
+ {pathItems.length > 0 && (<p className={styles.searchResultItemPath}>
110
+ {concatDocumentPath(pathItems)}
111
+ </p>)}
110
112
  {isContent && (<p className={styles.searchResultItemSummary} dangerouslySetInnerHTML={{
111
113
  __html: highlightStemmed(document.t, getStemmedPositions(metadata, "t"), tokens, 100),
112
114
  }}/>)}
@@ -3,15 +3,16 @@ export let removeDefaultStopWordFilter = false;
3
3
  export const indexHash = "abc";
4
4
  export const searchResultLimits = 8;
5
5
  export const searchResultContextMaxLength = 50;
6
+ export const explicitSearchResultPath = false;
6
7
  export const translations = {
7
- "search_placeholder": "Search",
8
- "see_all_results": "See all results",
9
- "no_results": "No results.",
10
- "search_results_for": "Search results for \"{{ keyword }}\"",
11
- "search_the_documentation": "Search the documentation",
12
- "count_documents_found": "{{ count }} document found",
13
- "count_documents_found_plural": "{{ count }} documents found",
14
- "no_documents_were_found": "No documents were found"
8
+ search_placeholder: "Search",
9
+ see_all_results: "See all results",
10
+ no_results: "No results.",
11
+ search_results_for: 'Search results for "{{ keyword }}"',
12
+ search_the_documentation: "Search the documentation",
13
+ count_documents_found: "{{ count }} document found",
14
+ count_documents_found_plural: "{{ count }} documents found",
15
+ no_documents_were_found: "No documents were found",
15
16
  };
16
17
  export function __setLanguage(value) {
17
18
  language = value;
@@ -0,0 +1,3 @@
1
+ export function concatDocumentPath(pathItems) {
2
+ return pathItems.join(" › ");
3
+ }
@@ -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, highlightSearchTermsOnTargetPage, searchResultLimits, searchResultContextMaxLength, translations, } = config;
9
+ const { language, removeDefaultStopWordFilter, highlightSearchTermsOnTargetPage, searchResultLimits, searchResultContextMaxLength, explicitSearchResultPath, translations, } = config;
10
10
  const indexHash = getIndexHash_1.getIndexHash(config);
11
11
  const contents = [
12
12
  `import lunr from ${JSON.stringify(require.resolve("lunr"))};`,
@@ -36,6 +36,7 @@ function generate(config, dir) {
36
36
  }
37
37
  contents.push(`export const indexHash = ${JSON.stringify(indexHash)};`);
38
38
  contents.push(`export const searchResultLimits = ${JSON.stringify(searchResultLimits)};`, `export const searchResultContextMaxLength = ${JSON.stringify(searchResultContextMaxLength)};`);
39
+ contents.push(`export const explicitSearchResultPath = ${JSON.stringify(explicitSearchResultPath)};`);
39
40
  contents.push(`export const translations = ${JSON.stringify(translations)};`);
40
41
  fs_1.default.writeFileSync(path_1.default.join(dir, "generated.js"), contents.join("\n"));
41
42
  }
@@ -4,7 +4,7 @@ exports.parseDocument = void 0;
4
4
  const getCondensedText_1 = require("./getCondensedText");
5
5
  const HEADINGS = "h1, h2, h3";
6
6
  function parseDocument($) {
7
- const $pageTitle = $("article header h1").first();
7
+ const $pageTitle = $("article h1").first();
8
8
  const pageTitle = $pageTitle.text();
9
9
  const sections = [];
10
10
  const breadcrumb = [];
@@ -3,11 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.tokenizer = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const lunr_1 = tslib_1.__importDefault(require("lunr"));
6
- const nodejieba_1 = tslib_1.__importDefault(require("nodejieba"));
6
+ const jieba_1 = tslib_1.__importDefault(require("@node-rs/jieba"));
7
7
  const cutWordByUnderscore_1 = require("./cutWordByUnderscore");
8
8
  // https://zhuanlan.zhihu.com/p/33335629
9
9
  const RegExpConsecutiveWord = /\w+|\p{Unified_Ideograph}+/u;
10
- nodejieba_1.default.load();
11
10
  function tokenizer(input, metadata) {
12
11
  if (input == null) {
13
12
  return [];
@@ -44,7 +43,7 @@ function tokenizer(input, metadata) {
44
43
  start += word.length;
45
44
  }
46
45
  else {
47
- for (const zhWord of nodejieba_1.default.cut(word)) {
46
+ for (const zhWord of jieba_1.default.cut(word)) {
48
47
  tokens.push(new lunr_1.default.Token(zhWord, Object.assign(Object.assign({}, lunr_1.default.utils.clone(metadata)), { position: [start, zhWord.length], index: tokens.length })));
49
48
  start += zhWord.length;
50
49
  }
@@ -18,6 +18,7 @@ const schema = utils_validation_1.Joi.object({
18
18
  highlightSearchTermsOnTargetPage: utils_validation_1.Joi.boolean().default(false),
19
19
  searchResultLimits: utils_validation_1.Joi.number().default(8),
20
20
  searchResultContextMaxLength: utils_validation_1.Joi.number().default(50),
21
+ explicitSearchResultPath: utils_validation_1.Joi.boolean().default(false),
21
22
  ignoreFiles: isArrayOfStringsOrRegExpsOrStringOrRegExp.default([]),
22
23
  translations: utils_validation_1.Joi.object({
23
24
  search_placeholder: utils_validation_1.Joi.string().default("Search"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyops-cn/docusaurus-search-local",
3
- "version": "0.22.0",
3
+ "version": "0.23.2",
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",
@@ -29,6 +29,7 @@
29
29
  "@docusaurus/utils": "^2.0.0-beta.4",
30
30
  "@docusaurus/utils-validation": "^2.0.0-beta.4",
31
31
  "@easyops-cn/autocomplete.js": "^0.38.1",
32
+ "@node-rs/jieba": "^1.6.0",
32
33
  "cheerio": "^1.0.0-rc.3",
33
34
  "clsx": "^1.1.1",
34
35
  "debug": "^4.2.0",
@@ -46,6 +47,7 @@
46
47
  "@babel/preset-typescript": "^7.12.1",
47
48
  "@docusaurus/module-type-aliases": "^2.0.0-beta.4",
48
49
  "@tsconfig/docusaurus": "^1.0.2",
50
+ "@types/cheerio": "^0.22.31",
49
51
  "@types/debug": "^4.1.5",
50
52
  "@types/enzyme": "^3.10.7",
51
53
  "@types/enzyme-adapter-react-16": "^1.0.6",
@@ -73,7 +75,6 @@
73
75
  "identity-obj-proxy": "^3.0.0",
74
76
  "jest": "^26.5.3",
75
77
  "lint-staged": "^10.4.1",
76
- "nodejieba": "^2.4.1",
77
78
  "prettier": "^2.1.2",
78
79
  "rimraf": "^3.0.2",
79
80
  "standard-version": "^9.0.0",