@easyops-cn/docusaurus-search-local 0.38.1 → 0.39.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.39.0](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.38.1...v0.39.0) (2023-12-15)
6
+
7
+
8
+ ### Features
9
+
10
+ * customize search context labels [#382](https://github.com/easyops-cn/docusaurus-search-local/issues/382) ([f7df7bb](https://github.com/easyops-cn/docusaurus-search-local/commit/f7df7bb95b47140091f640103830e6c0356bb072))
11
+
5
12
  ## [0.38.1](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.38.0...v0.38.1) (2023-11-28)
6
13
 
7
14
 
package/README.md CHANGED
@@ -1 +1 @@
1
- See https://github.com/easyops-cn/docusaurus-search-local#readme
1
+ See https://github.com/easyops-cn/docusaurus-search-local#readme.
@@ -76,7 +76,14 @@ export default function SearchBar({ handleSearchBarToggle, }) {
76
76
  let nextSearchContext = "";
77
77
  if (location.pathname.startsWith(versionUrl)) {
78
78
  const uri = location.pathname.substring(versionUrl.length);
79
- const matchedPath = searchContextByPaths.find((path) => uri === path || uri.startsWith(`${path}/`));
79
+ let matchedPath;
80
+ for (const _path of searchContextByPaths) {
81
+ const path = typeof _path === "string" ? _path : _path.path;
82
+ if (uri === path || uri.startsWith(`${path}/`)) {
83
+ matchedPath = path;
84
+ break;
85
+ }
86
+ }
80
87
  if (matchedPath) {
81
88
  nextSearchContext = matchedPath;
82
89
  }
@@ -103,9 +103,19 @@ function SearchPageContent() {
103
103
  })
104
104
  : ""}
105
105
  </option>
106
- {searchContextByPaths.map((context) => (<option key={context} value={context}>
107
- {context}
108
- </option>))}
106
+ {searchContextByPaths.map((context) => {
107
+ let label;
108
+ let path;
109
+ if (typeof context === "string") {
110
+ label = path = context;
111
+ }
112
+ else {
113
+ ({ label, path } = context);
114
+ }
115
+ return (<option key={path} value={path}>
116
+ {label}
117
+ </option>);
118
+ })}
109
119
  </select>
110
120
  </div>) : null}
111
121
  </div>
@@ -34,7 +34,14 @@ function postBuildFactory(config, searchIndexFilename) {
34
34
  for (const doc of documents) {
35
35
  if (doc.u.startsWith(baseUrl)) {
36
36
  const uri = doc.u.substring(baseUrl.length);
37
- const matchedPath = searchContextByPaths.find((path) => uri === path || uri.startsWith(`${path}/`));
37
+ let matchedPath;
38
+ for (const _path of searchContextByPaths) {
39
+ const path = typeof _path === "string" ? _path : _path.path;
40
+ if (uri === path || uri.startsWith(`${path}/`)) {
41
+ matchedPath = path;
42
+ break;
43
+ }
44
+ }
38
45
  if (matchedPath) {
39
46
  let dirAllDocs = docsByDirMap.get(matchedPath);
40
47
  if (!dirAllDocs) {
@@ -29,7 +29,10 @@ const schema = utils_validation_1.Joi.object({
29
29
  docsPluginIdForPreferredVersion: utils_validation_1.Joi.string(),
30
30
  zhUserDict: utils_validation_1.Joi.string(),
31
31
  zhUserDictPath: utils_validation_1.Joi.string(),
32
- searchContextByPaths: utils_validation_1.Joi.array().items(utils_validation_1.Joi.string()),
32
+ searchContextByPaths: utils_validation_1.Joi.array().items(utils_validation_1.Joi.alternatives().try(utils_validation_1.Joi.string(), utils_validation_1.Joi.object({
33
+ label: utils_validation_1.Joi.string(),
34
+ path: utils_validation_1.Joi.string(),
35
+ }))),
33
36
  hideSearchBarWithNoSearchContext: utils_validation_1.Joi.boolean().default(false),
34
37
  useAllContextsWithNoSearchContext: utils_validation_1.Joi.boolean().default(false),
35
38
  });
@@ -144,7 +144,10 @@ export interface PluginOptions {
144
144
  * Provide an list of sub-paths as separate search context, E.g.: `["docs", "community", "legacy/resources"]`.
145
145
  * It will create multiple search indexes by these paths.
146
146
  */
147
- searchContextByPaths?: string[];
147
+ searchContextByPaths?: (string | {
148
+ label: string;
149
+ path: string;
150
+ })[];
148
151
  /**
149
152
  * Whether to hide the search bar when no search context was matched.
150
153
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyops-cn/docusaurus-search-local",
3
- "version": "0.38.1",
3
+ "version": "0.39.0",
4
4
  "description": "An offline/local search plugin for Docusaurus v3",
5
5
  "repository": "https://github.com/easyops-cn/docusaurus-search-local",
6
6
  "homepage": "https://github.com/easyops-cn/docusaurus-search-local",