@easyops-cn/docusaurus-search-local 0.23.2 → 0.24.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,35 @@
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)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * fix indexing content between h1 and h2 ([f38b307](https://github.com/easyops-cn/docusaurus-search-local/commit/f38b307a669b582b8571fd2430b4454b49323c85))
11
+
12
+ ## [0.24.0](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.23.3...v0.24.0) (2022-05-18)
13
+
14
+
15
+ ### Features
16
+
17
+ * Add option to disable the default lunr stemmer ([ff8e9a2](https://github.com/easyops-cn/docusaurus-search-local/commit/ff8e9a2e3162dd847cbef11036772578c41a8828))
18
+
19
+
20
+ ### Bug Fixes
21
+
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))
26
+
27
+ ### [0.23.3](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.23.2...v0.23.3) (2022-05-18)
28
+
29
+
30
+ ### Bug Fixes
31
+
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))
33
+
5
34
  ### [0.23.2](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.23.1...v0.23.2) (2022-04-25)
6
35
 
7
36
 
package/README.md CHANGED
@@ -54,6 +54,7 @@ module.exports = {
54
54
  // ... Your options.
55
55
  // `hashed` is recommended as long-term-cache of index file is possible.
56
56
  hashed: true,
57
+ explicitSearchResultPath: true,
57
58
  // For Docs using Chinese, The `language` is recommended to set to:
58
59
  // ```
59
60
  // language: ["en", "zh"],
@@ -68,24 +69,25 @@ module.exports = {
68
69
 
69
70
  ## Theme Options
70
71
 
71
- | Name | Type | Default | Description |
72
- | -------------------------------- | ---------------------------------------- | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------- |
73
- | indexDocs | boolean | `true` | Whether to index docs. |
74
- | indexBlog | boolean | `true` | Whether to index blog. |
75
- | indexPages | boolean | `false` | Whether to index pages. |
76
- | docsRouteBasePath | string \| string[] | `"/docs"` | Base route path(s) of docs. Slash at beginning is not required. |
77
- | blogRouteBasePath | string \| string[] | `"/blog"` | Base route path(s) of blog. Slash at beginning is not required. |
78
- | language | string \| string[] | `"en"` | All [lunr-languages](https://github.com/MihaiValentin/lunr-languages) supported languages, + `zh` 🔥. |
79
- | 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) |
80
- | docsDir | string \| string[] | `"docs"` | The dir(s) of docs to get the content hash, it's relative to the dir of your project. |
81
- | blogDir | string \| string[] | `"blog"` | Just like the `docsDir` but applied to blog. |
82
- | 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. |
83
- | highlightSearchTermsOnTargetPage | boolean | `false` | Highlight search terms on target page. |
84
- | searchResultLimits | number | `8` | Limit the search results. |
85
- | searchResultContextMaxLength | number | `50` | Set the max length of characters of each search result to show. |
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). |
88
- | ignoreFiles | string \| RegExp \| (string \| RegExp)[] | /**meta**\$/ | Set the match rules to ignore some files. |
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. |
89
91
 
90
92
  ### Translations
91
93
 
@@ -141,7 +141,7 @@ export default function SearchBar({ handleSearchBarToggle, }) {
141
141
  mark.unmark();
142
142
  mark.mark(keywords);
143
143
  });
144
- }, [location.search]);
144
+ }, [location.search, location.pathname]);
145
145
  const onInputFocus = useCallback(() => {
146
146
  focusAfterIndexLoaded.current = true;
147
147
  loadIndex();
@@ -177,8 +177,8 @@ export default function SearchBar({ handleSearchBarToggle, }) {
177
177
  };
178
178
  }, [isMac, onInputFocus]);
179
179
  return (<div className={clsx("navbar__search", styles.searchBarContainer, {
180
- [styles.searchIndexLoading]: loading && inputChanged,
181
- })}>
180
+ [styles.searchIndexLoading]: loading && inputChanged,
181
+ })}>
182
182
  <input placeholder={translations.search_placeholder} aria-label="Search" className="navbar__search-input" onMouseEnter={onInputMouseEnter} onFocus={onInputFocus} onBlur={onInputBlur} onChange={onInputChange} ref={searchBarRef}/>
183
183
  <LoadingRing className={styles.searchBarLoadingRing}/>
184
184
  <div className={styles.searchHintContainer}>
@@ -23,7 +23,7 @@ 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 ?? [])
26
+ ? (page.b ?? []).concat(page.t).concat(!document.s || document.s === page.t ? [] : document.s)
27
27
  : document.b;
28
28
  wrapped.push(`<span class="${styles.hitPath}">${concatDocumentPath(pathItems ?? [])}</span>`);
29
29
  }
@@ -57,7 +57,10 @@ export default function SearchPage() {
57
57
  }, [baseUrl]);
58
58
  return (<Layout>
59
59
  <Head>
60
-
60
+ {/*
61
+ We should not index search pages
62
+ See https://github.com/facebook/docusaurus/pull/3233
63
+ */}
61
64
  <meta property="robots" content="noindex, follow"/>
62
65
  <title>{pageTitle}</title>
63
66
  </Head>
@@ -72,12 +75,12 @@ export default function SearchPage() {
72
75
  </div>)}
73
76
 
74
77
  {searchResults &&
75
- (searchResults.length > 0 ? (<p>
78
+ (searchResults.length > 0 ? (<p>
76
79
  {simpleTemplate(searchResults.length === 1
77
- ? translations.count_documents_found
78
- : translations.count_documents_found_plural, {
79
- count: searchResults.length,
80
- })}
80
+ ? translations.count_documents_found
81
+ : translations.count_documents_found_plural, {
82
+ count: searchResults.length,
83
+ })}
81
84
  </p>) : process.env.NODE_ENV === "production" ? (<p>{translations.no_documents_were_found}</p>) : (<p>
82
85
  ⚠️ The search index is only available when you run docusaurus
83
86
  build!
@@ -85,7 +88,7 @@ export default function SearchPage() {
85
88
 
86
89
  <section>
87
90
  {searchResults &&
88
- searchResults.map((item) => (<SearchResultItem key={item.document.i} searchResult={item}/>))}
91
+ searchResults.map((item) => (<SearchResultItem key={item.document.i} searchResult={item}/>))}
89
92
  </section>
90
93
  </div>
91
94
  </Layout>);
@@ -101,16 +104,16 @@ function SearchResultItem({ searchResult: { document, type, page, tokens, metada
101
104
  return (<article className={styles.searchResultItem}>
102
105
  <h2>
103
106
  <Link to={document.u + (document.h || "")} dangerouslySetInnerHTML={{
104
- __html: isContent
105
- ? highlight(articleTitle, tokens)
106
- : highlightStemmed(articleTitle, getStemmedPositions(metadata, "t"), tokens, 100),
107
- }}></Link>
107
+ __html: isContent
108
+ ? highlight(articleTitle, tokens)
109
+ : highlightStemmed(articleTitle, getStemmedPositions(metadata, "t"), tokens, 100),
110
+ }}></Link>
108
111
  </h2>
109
112
  {pathItems.length > 0 && (<p className={styles.searchResultItemPath}>
110
113
  {concatDocumentPath(pathItems)}
111
114
  </p>)}
112
115
  {isContent && (<p className={styles.searchResultItemSummary} dangerouslySetInnerHTML={{
113
- __html: highlightStemmed(document.t, getStemmedPositions(metadata, "t"), tokens, 100),
114
- }}/>)}
116
+ __html: highlightStemmed(document.t, getStemmedPositions(metadata, "t"), tokens, 100),
117
+ }}/>)}
115
118
  </article>);
116
119
  }
@@ -1,5 +1,6 @@
1
1
  export let language = ["en", "zh"];
2
2
  export let removeDefaultStopWordFilter = false;
3
+ export let removeDefaultStemmer = false;
3
4
  export const indexHash = "abc";
4
5
  export const searchResultLimits = 8;
5
6
  export const searchResultContextMaxLength = 50;
@@ -20,3 +21,6 @@ export function __setLanguage(value) {
20
21
  export function __setRemoveDefaultStopWordFilter(value) {
21
22
  removeDefaultStopWordFilter = value;
22
23
  }
24
+ export function __setRemoveDefaultStemmer(value) {
25
+ removeDefaultStemmer = value;
26
+ }
@@ -10,10 +10,10 @@ const postBuildFactory_1 = require("./utils/postBuildFactory");
10
10
  const generate_1 = require("./utils/generate");
11
11
  const PLUGIN_NAME = "@easyops-cn/docusaurus-search-local";
12
12
  function DocusaurusSearchLocalPlugin(context, options) {
13
- const config = processPluginOptions_1.processPluginOptions(options, context.siteDir);
13
+ const config = (0, processPluginOptions_1.processPluginOptions)(options, context.siteDir);
14
14
  const dir = path_1.default.join(context.generatedFilesDir, PLUGIN_NAME, "default");
15
15
  fs_extra_1.default.ensureDirSync(dir);
16
- generate_1.generate(config, dir);
16
+ (0, generate_1.generate)(config, dir);
17
17
  const themePath = path_1.default.resolve(__dirname, "../../client/client/theme");
18
18
  const pagePath = path_1.default.join(themePath, "SearchPage/index.js");
19
19
  return {
@@ -21,14 +21,14 @@ function DocusaurusSearchLocalPlugin(context, options) {
21
21
  getThemePath() {
22
22
  return themePath;
23
23
  },
24
- postBuild: postBuildFactory_1.postBuildFactory(config),
24
+ postBuild: (0, postBuildFactory_1.postBuildFactory)(config),
25
25
  getPathsToWatch() {
26
26
  return [pagePath];
27
27
  },
28
28
  contentLoaded({ actions: { addRoute } }) {
29
29
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
30
30
  addRoute({
31
- path: utils_1.normalizeUrl([context.baseUrl, "search"]),
31
+ path: (0, utils_1.normalizeUrl)([context.baseUrl, "search"]),
32
32
  component: "@theme/SearchPage",
33
33
  exact: true,
34
34
  });
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildIndex = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const lunr_1 = tslib_1.__importDefault(require("lunr"));
6
- function buildIndex(allDocuments, { language, removeDefaultStopWordFilter }) {
6
+ function buildIndex(allDocuments, { language, removeDefaultStopWordFilter, removeDefaultStemmer, }) {
7
7
  if (language.length > 1 || language.some((item) => item !== "en")) {
8
8
  // eslint-disable-next-line @typescript-eslint/no-var-requires
9
9
  require("lunr-languages/lunr.stemmer.support")(lunr_1.default);
@@ -28,7 +28,7 @@ function buildIndex(allDocuments, { language, removeDefaultStopWordFilter }) {
28
28
  }
29
29
  return allDocuments.map((documents) => ({
30
30
  documents,
31
- index: lunr_1.default(function () {
31
+ index: (0, lunr_1.default)(function () {
32
32
  if (language.length > 1) {
33
33
  this.use(lunr_1.default.multiLanguage(...language));
34
34
  }
@@ -40,6 +40,9 @@ function buildIndex(allDocuments, { language, removeDefaultStopWordFilter }) {
40
40
  // since they are almost all programming code.
41
41
  this.pipeline.remove(lunr_1.default.stopWordFilter);
42
42
  }
43
+ if (removeDefaultStemmer) {
44
+ this.pipeline.remove(lunr_1.default.stemmer);
45
+ }
43
46
  // Override tokenizer when language `zh` is enabled.
44
47
  if (language.includes("zh")) {
45
48
  this.tokenizer = lunr_1.default.zh.tokenizer;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.debugWarn = exports.debugInfo = exports.debugVerbose = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const debug_1 = tslib_1.__importDefault(require("debug"));
6
- const debug = debug_1.default("search-local");
6
+ const debug = (0, debug_1.default)("search-local");
7
7
  exports.debugVerbose = debug.extend("verbose");
8
8
  exports.debugInfo = debug.extend("info");
9
9
  exports.debugWarn = debug.extend("warn");
@@ -6,8 +6,8 @@ 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, explicitSearchResultPath, translations, } = config;
10
- const indexHash = getIndexHash_1.getIndexHash(config);
9
+ const { language, removeDefaultStopWordFilter, removeDefaultStemmer, highlightSearchTermsOnTargetPage, searchResultLimits, searchResultContextMaxLength, explicitSearchResultPath, translations, } = config;
10
+ const indexHash = (0, getIndexHash_1.getIndexHash)(config);
11
11
  const contents = [
12
12
  `import lunr from ${JSON.stringify(require.resolve("lunr"))};`,
13
13
  ];
@@ -28,6 +28,7 @@ function generate(config, dir) {
28
28
  }
29
29
  contents.push(`export const language = ${JSON.stringify(language)};`);
30
30
  contents.push(`export const removeDefaultStopWordFilter = ${JSON.stringify(removeDefaultStopWordFilter)};`);
31
+ contents.push(`export const removeDefaultStemmer = ${JSON.stringify(removeDefaultStemmer)};`);
31
32
  if (highlightSearchTermsOnTargetPage) {
32
33
  contents.push(`export { default as Mark } from ${JSON.stringify(require.resolve("mark.js"))}`);
33
34
  }
@@ -22,7 +22,7 @@ function getIndexHash(config) {
22
22
  console.warn(`Warn: \`${dirField}\` is not a directory: "${dir}".`);
23
23
  }
24
24
  else {
25
- files.push(...klaw_sync_1.default(dir, { nodir: true, filter: markdownFilter }));
25
+ files.push(...(0, klaw_sync_1.default)(dir, { nodir: true, filter: markdownFilter, traverseAll: true }));
26
26
  }
27
27
  }
28
28
  }
@@ -35,18 +35,18 @@ function getIndexHash(config) {
35
35
  // since the index maybe changed between versions.
36
36
  // eslint-disable-next-line @typescript-eslint/no-var-requires
37
37
  const pluginVersion = require(path_1.default.resolve(__dirname, "../../../../package.json")).version;
38
- debug_1.debugInfo("using @easyops-cn/docusaurus-search-local v%s", pluginVersion);
38
+ (0, debug_1.debugInfo)("using @easyops-cn/docusaurus-search-local v%s", pluginVersion);
39
39
  md5sum.update(pluginVersion, "utf8");
40
40
  for (const item of files) {
41
41
  md5sum.update(fs_1.default.readFileSync(item.path));
42
42
  }
43
43
  const indexHash = md5sum.digest("hex").substring(0, 8);
44
- debug_1.debugInfo("the index hash is %j", indexHash);
44
+ (0, debug_1.debugInfo)("the index hash is %j", indexHash);
45
45
  return indexHash;
46
46
  }
47
47
  return null;
48
48
  }
49
49
  exports.getIndexHash = getIndexHash;
50
50
  function markdownFilter(item) {
51
- return item.path.endsWith(".md");
51
+ return item.path.endsWith(".md") || item.path.endsWith(".mdx");
52
52
  }
@@ -16,8 +16,8 @@ function parse(html, type, url) {
16
16
  .remove();
17
17
  }
18
18
  if (type === "page") {
19
- return parsePage_1.parsePage($, url);
19
+ return (0, parsePage_1.parsePage)($, url);
20
20
  }
21
- return parseDocument_1.parseDocument($);
21
+ return (0, parseDocument_1.parseDocument)($);
22
22
  }
23
23
  exports.parse = parse;
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseDocument = void 0;
4
+ const utils_common_1 = require("@docusaurus/utils-common");
4
5
  const getCondensedText_1 = require("./getCondensedText");
5
6
  const HEADINGS = "h1, h2, h3";
7
+ // const SUB_HEADINGS = "h2, h3";
6
8
  function parseDocument($) {
7
9
  const $pageTitle = $("article h1").first();
8
10
  const pageTitle = $pageTitle.text();
@@ -32,22 +34,48 @@ function parseDocument($) {
32
34
  // <a aria-hidden="true" tabindex="-1" class="hash-link" href="#first-subheader" title="Direct link to heading">#</a>
33
35
  const title = $h.contents().not("a.hash-link").text().trim();
34
36
  const hash = $h.find("a.hash-link").attr("href") || "";
35
- let $sectionElements;
37
+ // Find all content between h1 and h2/h3,
38
+ // which is considered as the content section of page title.
39
+ let $sectionElements = $([]);
36
40
  if ($h.is($pageTitle)) {
37
- const $firstElement = $("article")
38
- .children() // div.markdown, header
39
- .not("header") // div.markdown
40
- .children() // h1, p, p, h2, ...
41
- .first(); // h1 || p
42
- if ($firstElement.filter(HEADINGS).length > 0) {
43
- return;
41
+ const $header = $h.parent();
42
+ let $firstElement;
43
+ if ($header.is("header")) {
44
+ $firstElement = $header;
45
+ }
46
+ else {
47
+ $firstElement = $h;
48
+ }
49
+ const blogPost = $(`#${utils_common_1.blogPostContainerID}`);
50
+ if (blogPost.length) {
51
+ // Simplify blog post.
52
+ $firstElement = blogPost.children().first();
53
+ $sectionElements = $firstElement.nextUntil(HEADINGS).addBack();
54
+ }
55
+ else {
56
+ const $nextElements = $firstElement.nextAll();
57
+ const $headings = $nextElements.filter(HEADINGS);
58
+ if ($headings.length) {
59
+ $sectionElements = $firstElement.nextUntil(HEADINGS);
60
+ }
61
+ else {
62
+ for (const next of $nextElements.get()) {
63
+ const $heading = $(next).find(HEADINGS);
64
+ if ($heading.length) {
65
+ $sectionElements = $sectionElements.add($heading.first().prevAll());
66
+ break;
67
+ }
68
+ else {
69
+ $sectionElements = $sectionElements.add(next);
70
+ }
71
+ }
72
+ }
44
73
  }
45
- $sectionElements = $firstElement.nextUntil(HEADINGS).addBack();
46
74
  }
47
75
  else {
48
76
  $sectionElements = $h.nextUntil(HEADINGS);
49
77
  }
50
- const content = getCondensedText_1.getCondensedText($sectionElements.get(), $);
78
+ const content = (0, getCondensedText_1.getCondensedText)($sectionElements.get(), $);
51
79
  sections.push({
52
80
  title,
53
81
  hash,
@@ -12,7 +12,7 @@ function parsePage($, url) {
12
12
  const pageTitle = $pageTitle.text();
13
13
  const $main = $("main");
14
14
  if ($main.length === 0) {
15
- debug_1.debugWarn("page has no <main>, therefore no content was indexed for this page %o", url);
15
+ (0, debug_1.debugWarn)("page has no <main>, therefore no content was indexed for this page %o", url);
16
16
  }
17
17
  return {
18
18
  pageTitle,
@@ -20,7 +20,7 @@ function parsePage($, url) {
20
20
  {
21
21
  title: pageTitle,
22
22
  hash: "",
23
- content: $main.length > 0 ? getCondensedText_1.getCondensedText($main.get(0), $).trim() : "",
23
+ content: $main.length > 0 ? (0, getCondensedText_1.getCondensedText)($main.get(0), $).trim() : "",
24
24
  },
25
25
  ],
26
26
  breadcrumb: [],
@@ -13,16 +13,16 @@ const writeFileAsync = util_1.default.promisify(fs_1.default.writeFile);
13
13
  function postBuildFactory(config) {
14
14
  return function postBuild(buildData) {
15
15
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
16
- debug_1.debugInfo("gathering documents");
17
- const data = processDocInfos_1.processDocInfos(buildData, config);
18
- debug_1.debugInfo("parsing documents");
16
+ (0, debug_1.debugInfo)("gathering documents");
17
+ const data = (0, processDocInfos_1.processDocInfos)(buildData, config);
18
+ (0, 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
- const allDocuments = yield scanDocuments_1.scanDocuments(data);
21
- debug_1.debugInfo("building index");
22
- const searchIndex = buildIndex_1.buildIndex(allDocuments, config);
23
- debug_1.debugInfo("writing index to disk");
20
+ const allDocuments = yield (0, scanDocuments_1.scanDocuments)(data);
21
+ (0, debug_1.debugInfo)("building index");
22
+ const searchIndex = (0, buildIndex_1.buildIndex)(allDocuments, config);
23
+ (0, debug_1.debugInfo)("writing index to disk");
24
24
  yield writeFileAsync(path_1.default.join(buildData.outDir, "search-index.json"), JSON.stringify(searchIndex), { encoding: "utf8" });
25
- debug_1.debugInfo("index written to disk successfully!");
25
+ (0, debug_1.debugInfo)("index written to disk successfully!");
26
26
  });
27
27
  };
28
28
  }
@@ -12,7 +12,9 @@ function processDocInfos({ routesPaths, outDir, baseUrl, siteConfig }, { indexDo
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 === "" || route === "404.html" || route === "search") {
15
+ if (((!docsRouteBasePath || docsRouteBasePath[0] !== "") && route === "") ||
16
+ route === "404.html" ||
17
+ route === "search") {
16
18
  return;
17
19
  }
18
20
  // ignore files
@@ -19,9 +19,9 @@ function scanDocuments(DocInfoWithFilePathList) {
19
19
  const contentDocuments = [];
20
20
  const allDocuments = [titleDocuments, headingDocuments, contentDocuments];
21
21
  yield Promise.all(DocInfoWithFilePathList.map(({ filePath, url, type }) => tslib_1.__awaiter(this, void 0, void 0, function* () {
22
- debug_1.debugVerbose(`parsing %s file %o of %o`, type, path_1.default.relative(process.cwd(), filePath), url);
22
+ (0, debug_1.debugVerbose)(`parsing %s file %o of %o`, type, path_1.default.relative(process.cwd(), filePath), url);
23
23
  const html = yield readFileAsync(filePath, { encoding: "utf8" });
24
- const { pageTitle, sections, breadcrumb } = parse_1.parse(html, type, url);
24
+ const { pageTitle, sections, breadcrumb } = (0, parse_1.parse)(html, type, url);
25
25
  const titleId = getNextDocId();
26
26
  titleDocuments.push({
27
27
  i: titleId,
@@ -30,7 +30,7 @@ function tokenizer(input, metadata) {
30
30
  if (/\w/.test(word[0])) {
31
31
  tokens.push(new lunr_1.default.Token(word, Object.assign(Object.assign({}, lunr_1.default.utils.clone(metadata)), { position: [start, word.length], index: tokens.length })));
32
32
  // Try to cut `api_gateway` to `api` and `gateway`.
33
- const subWords = cutWordByUnderscore_1.cutWordByUnderscore(word);
33
+ const subWords = (0, cutWordByUnderscore_1.cutWordByUnderscore)(word);
34
34
  if (subWords.length > 1) {
35
35
  let i = 0;
36
36
  for (const subWord of subWords) {
@@ -15,6 +15,7 @@ const schema = utils_validation_1.Joi.object({
15
15
  docsDir: isStringOrArrayOfStrings.default(["docs"]),
16
16
  blogDir: isStringOrArrayOfStrings.default(["blog"]),
17
17
  removeDefaultStopWordFilter: utils_validation_1.Joi.boolean().default(false),
18
+ removeDefaultStemmer: utils_validation_1.Joi.boolean().default(false),
18
19
  highlightSearchTermsOnTargetPage: utils_validation_1.Joi.boolean().default(false),
19
20
  searchResultLimits: utils_validation_1.Joi.number().default(8),
20
21
  searchResultContextMaxLength: utils_validation_1.Joi.number().default(50),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyops-cn/docusaurus-search-local",
3
- "version": "0.23.2",
3
+ "version": "0.24.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",
@@ -27,18 +27,19 @@
27
27
  "license": "MIT",
28
28
  "dependencies": {
29
29
  "@docusaurus/utils": "^2.0.0-beta.4",
30
+ "@docusaurus/utils-common": "^2.0.0-beta.20",
30
31
  "@docusaurus/utils-validation": "^2.0.0-beta.4",
31
32
  "@easyops-cn/autocomplete.js": "^0.38.1",
32
33
  "@node-rs/jieba": "^1.6.0",
33
34
  "cheerio": "^1.0.0-rc.3",
34
35
  "clsx": "^1.1.1",
35
36
  "debug": "^4.2.0",
36
- "fs-extra": "^9.0.1",
37
+ "fs-extra": "^10.0.0",
37
38
  "klaw-sync": "^6.0.0",
38
39
  "lunr": "^2.3.9",
39
40
  "lunr-languages": "^1.4.0",
40
41
  "mark.js": "^8.11.1",
41
- "tslib": "^2.2.0"
42
+ "tslib": "^2.4.0"
42
43
  },
43
44
  "devDependencies": {
44
45
  "@babel/core": "^7.12.3",
@@ -52,32 +53,33 @@
52
53
  "@types/enzyme": "^3.10.7",
53
54
  "@types/enzyme-adapter-react-16": "^1.0.6",
54
55
  "@types/fs-extra": "^9.0.2",
55
- "@types/jest": "^26.0.14",
56
+ "@types/jest": "^27.0.0",
56
57
  "@types/klaw-sync": "^6.0.0",
57
58
  "@types/lunr": "^2.3.3",
58
59
  "@types/react": "^16.9.55",
59
60
  "@types/react-dom": "^16.9.8",
60
61
  "@types/react-helmet": "^6.1.0",
61
62
  "@types/react-router-dom": "^5.1.6",
62
- "@typescript-eslint/eslint-plugin": "^4.4.1",
63
- "@typescript-eslint/parser": "^4.4.1",
64
- "babel-jest": "^26.5.2",
65
- "concurrently": "^6.0.0",
63
+ "@typescript-eslint/eslint-plugin": "^5.0.0",
64
+ "@typescript-eslint/parser": "^5.0.0",
65
+ "babel-jest": "^28.0.0",
66
+ "concurrently": "^7.0.0",
66
67
  "copyfiles": "^2.4.0",
67
68
  "enzyme": "^3.11.0",
68
69
  "enzyme-adapter-react-16": "^1.15.5",
69
70
  "enzyme-to-json": "^3.6.1",
70
- "eslint": "^7.11.0",
71
- "eslint-config-prettier": "^7.0.0",
71
+ "eslint": "^8.0.0",
72
+ "eslint-config-prettier": "^8.0.0",
72
73
  "eslint-plugin-react": "^7.21.4",
73
74
  "eslint-plugin-react-hooks": "^4.1.2",
74
- "husky": "^4.3.0",
75
+ "husky": "^8.0.0",
75
76
  "identity-obj-proxy": "^3.0.0",
76
- "jest": "^26.5.3",
77
- "lint-staged": "^10.4.1",
77
+ "jest": "^28.0.0",
78
+ "jest-environment-jsdom": "^28.1.0",
79
+ "lint-staged": "^12.0.0",
78
80
  "prettier": "^2.1.2",
79
81
  "rimraf": "^3.0.2",
80
82
  "standard-version": "^9.0.0",
81
- "typescript": "^4.0.3"
83
+ "typescript": "^4.6.4"
82
84
  }
83
85
  }