@easyops-cn/docusaurus-search-local 0.23.0 → 0.23.3

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.3](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.23.2...v0.23.3) (2022-05-18)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * 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))
11
+
12
+ ### [0.23.2](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.23.1...v0.23.2) (2022-04-25)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * install cheerio types ([0a45f41](https://www.github.com/easyops-cn/docusaurus-search-local/commit/0a45f41bd02d8305328705bcc6582b92ed2ccf78))
18
+
19
+ ### [0.23.1](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.23.0...v0.23.1) (2022-04-07)
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * parse `h1` from the whole `article` ([aeb063a](https://www.github.com/easyops-cn/docusaurus-search-local/commit/aeb063af9dbac9778e3436aa261e0c131a2ef8c2))
25
+
5
26
  ## [0.23.0](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.22.0...v0.23.0) (2022-03-10)
6
27
 
7
28
 
package/README.md CHANGED
@@ -73,7 +73,7 @@ module.exports = {
73
73
  | indexDocs | boolean | `true` | Whether to index docs. |
74
74
  | indexBlog | boolean | `true` | Whether to index blog. |
75
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. |
76
+ | 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., `"/"`. |
77
77
  | blogRouteBasePath | string \| string[] | `"/blog"` | Base route path(s) of blog. Slash at beginning is not required. |
78
78
  | language | string \| string[] | `"en"` | All [lunr-languages](https://github.com/MihaiValentin/lunr-languages) supported languages, + `zh` 🔥. |
79
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) |
@@ -83,6 +83,7 @@ module.exports = {
83
83
  | highlightSearchTermsOnTargetPage | boolean | `false` | Highlight search terms on target page. |
84
84
  | searchResultLimits | number | `8` | Limit the search results. |
85
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. |
86
87
  | translations | TranslationMap | - | Set translations of this theme, see [docs below](#translations). |
87
88
  | ignoreFiles | string \| RegExp \| (string \| RegExp)[] | /**meta**\$/ | Set the match rules to ignore some files. |
88
89
 
@@ -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
  }
@@ -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(...klaw_sync_1.default(dir, { nodir: true, filter: markdownFilter, traverseAll: true }));
26
26
  }
27
27
  }
28
28
  }
@@ -48,5 +48,5 @@ function getIndexHash(config) {
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
  }
@@ -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 = [];
@@ -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.23.0",
3
+ "version": "0.23.3",
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",
@@ -37,8 +38,7 @@
37
38
  "lunr": "^2.3.9",
38
39
  "lunr-languages": "^1.4.0",
39
40
  "mark.js": "^8.11.1",
40
- "tslib": "^2.2.0",
41
- "@node-rs/jieba": "^1.6.0"
41
+ "tslib": "^2.2.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@babel/core": "^7.12.3",
@@ -47,6 +47,7 @@
47
47
  "@babel/preset-typescript": "^7.12.1",
48
48
  "@docusaurus/module-type-aliases": "^2.0.0-beta.4",
49
49
  "@tsconfig/docusaurus": "^1.0.2",
50
+ "@types/cheerio": "^0.22.31",
50
51
  "@types/debug": "^4.1.5",
51
52
  "@types/enzyme": "^3.10.7",
52
53
  "@types/enzyme-adapter-react-16": "^1.0.6",