@easyops-cn/docusaurus-search-local 0.33.5 → 0.34.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 +14 -0
- package/README.md +0 -1
- package/dist/client/client/theme/SearchBar/SearchBar.jsx +15 -9
- package/dist/client/client/theme/SearchPage/SearchPage.jsx +26 -3
- package/dist/client/client/theme/SearchPage/SearchPage.module.css +1 -0
- package/dist/client/client/theme/hooks/useSearchQuery.js +7 -0
- package/dist/locales/vi.json +6 -6
- package/dist/server/server/utils/generate.js +2 -1
- package/dist/server/server/utils/postBuildFactory.js +4 -2
- package/dist/server/server/utils/validateOptions.js +1 -0
- package/dist/types/index.d.ts +9 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
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.34.0](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.33.6...v0.34.0) (2023-02-16)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* improve search context feature [#319](https://github.com/easyops-cn/docusaurus-search-local/issues/319) ([a9578cc](https://github.com/easyops-cn/docusaurus-search-local/commit/a9578cc34856031d5b9a16ed6edd29b6dcb922c3))
|
|
11
|
+
|
|
12
|
+
## [0.33.6](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.33.5...v0.33.6) (2022-11-28)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* use key instead of code for keyboard events ([5e919f4](https://github.com/easyops-cn/docusaurus-search-local/commit/5e919f4e23b2b97380ca6fc8622254bcf3ff4fa0)), closes [#298](https://github.com/easyops-cn/docusaurus-search-local/issues/298)
|
|
18
|
+
|
|
5
19
|
## [0.33.5](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.33.4...v0.33.5) (2022-10-24)
|
|
6
20
|
|
|
7
21
|
|
package/README.md
CHANGED
|
@@ -144,10 +144,15 @@ export default function SearchBar({ handleSearchBarToggle, }) {
|
|
|
144
144
|
}
|
|
145
145
|
const url = `${baseUrl}search?${params.toString()}`;
|
|
146
146
|
a.href = url;
|
|
147
|
-
a.textContent =
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
147
|
+
a.textContent = searchContext
|
|
148
|
+
? translate({
|
|
149
|
+
id: "theme.SearchBar.searchInContext",
|
|
150
|
+
message: "See all results in {context}",
|
|
151
|
+
}, { context: searchContext })
|
|
152
|
+
: translate({
|
|
153
|
+
id: "theme.SearchBar.seeAll",
|
|
154
|
+
message: "See all results",
|
|
155
|
+
});
|
|
151
156
|
a.addEventListener("click", (e) => {
|
|
152
157
|
if (!e.ctrlKey && !e.metaKey) {
|
|
153
158
|
e.preventDefault();
|
|
@@ -247,7 +252,8 @@ export default function SearchBar({ handleSearchBarToggle, }) {
|
|
|
247
252
|
}
|
|
248
253
|
// Add shortcuts command/ctrl + K
|
|
249
254
|
const handleShortcut = (event) => {
|
|
250
|
-
if ((isMac ? event.metaKey : event.ctrlKey) &&
|
|
255
|
+
if ((isMac ? event.metaKey : event.ctrlKey) &&
|
|
256
|
+
(event.key === "k" || event.key === "K")) {
|
|
251
257
|
event.preventDefault();
|
|
252
258
|
searchBarRef.current?.focus();
|
|
253
259
|
onInputFocus();
|
|
@@ -286,9 +292,9 @@ export default function SearchBar({ handleSearchBarToggle, }) {
|
|
|
286
292
|
searchBarShortcutHint &&
|
|
287
293
|
(inputValue !== "" ? (<button className={styles.searchClearButton} onClick={onClearSearch}>
|
|
288
294
|
✕
|
|
289
|
-
</button>) : (<div className={styles.searchHintContainer}>
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
295
|
+
</button>) : (ExecutionEnvironment.canUseDOM && (<div className={styles.searchHintContainer}>
|
|
296
|
+
<kbd className={styles.searchHint}>{isMac ? "⌘" : "ctrl"}</kbd>
|
|
297
|
+
<kbd className={styles.searchHint}>K</kbd>
|
|
298
|
+
</div>)))}
|
|
293
299
|
</div>);
|
|
294
300
|
}
|
|
@@ -5,6 +5,7 @@ import Head from "@docusaurus/Head";
|
|
|
5
5
|
import Link from "@docusaurus/Link";
|
|
6
6
|
import { translate } from "@docusaurus/Translate";
|
|
7
7
|
import { usePluralForm } from "@docusaurus/theme-common";
|
|
8
|
+
import clsx from "clsx";
|
|
8
9
|
import useSearchQuery from "../hooks/useSearchQuery";
|
|
9
10
|
import { fetchIndexes } from "../SearchBar/fetchIndexes";
|
|
10
11
|
import { SearchSourceFactory } from "../../utils/SearchSourceFactory";
|
|
@@ -13,7 +14,7 @@ import { highlightStemmed } from "../../utils/highlightStemmed";
|
|
|
13
14
|
import { getStemmedPositions } from "../../utils/getStemmedPositions";
|
|
14
15
|
import LoadingRing from "../LoadingRing/LoadingRing";
|
|
15
16
|
import { concatDocumentPath } from "../../utils/concatDocumentPath";
|
|
16
|
-
import { Mark } from "../../utils/proxiedGenerated";
|
|
17
|
+
import { Mark, searchContextByPaths, useAllContextsWithNoSearchContext, } from "../../utils/proxiedGenerated";
|
|
17
18
|
import styles from "./SearchPage.module.css";
|
|
18
19
|
export default function SearchPage() {
|
|
19
20
|
return (<Layout>
|
|
@@ -23,7 +24,7 @@ export default function SearchPage() {
|
|
|
23
24
|
function SearchPageContent() {
|
|
24
25
|
const { siteConfig: { baseUrl }, } = useDocusaurusContext();
|
|
25
26
|
const { selectMessage } = usePluralForm();
|
|
26
|
-
const { searchValue, searchContext, searchVersion, updateSearchPath } = useSearchQuery();
|
|
27
|
+
const { searchValue, searchContext, searchVersion, updateSearchPath, updateSearchContext, } = useSearchQuery();
|
|
27
28
|
const [searchQuery, setSearchQuery] = useState(searchValue);
|
|
28
29
|
const [searchSource, setSearchSource] = useState();
|
|
29
30
|
const [searchResults, setSearchResults] = useState();
|
|
@@ -84,7 +85,29 @@ function SearchPageContent() {
|
|
|
84
85
|
<div className="container margin-vert--lg">
|
|
85
86
|
<h1>{pageTitle}</h1>
|
|
86
87
|
|
|
87
|
-
<
|
|
88
|
+
<div className="row">
|
|
89
|
+
<div className={clsx("col", styles.searchQueryColumn, {
|
|
90
|
+
"col--9": Array.isArray(searchContextByPaths),
|
|
91
|
+
"col--12": !Array.isArray(searchContextByPaths),
|
|
92
|
+
})}>
|
|
93
|
+
<input type="search" name="q" className={styles.searchQueryInput} aria-label="Search" onChange={handleSearchInputChange} value={searchQuery} autoComplete="off" autoFocus/>
|
|
94
|
+
</div>
|
|
95
|
+
{Array.isArray(searchContextByPaths) ? (<div className={clsx("col", "col--3", "padding-left--none", styles.searchVersionColumn)}>
|
|
96
|
+
<select name="search-context" className={styles.searchVersionInput} id="context-selector" value={searchContext} onChange={(e) => updateSearchContext(e.target.value)}>
|
|
97
|
+
<option value="">
|
|
98
|
+
{useAllContextsWithNoSearchContext
|
|
99
|
+
? translate({
|
|
100
|
+
id: "theme.SearchPage.searchContext.everywhere",
|
|
101
|
+
message: "everywhere",
|
|
102
|
+
})
|
|
103
|
+
: ""}
|
|
104
|
+
</option>
|
|
105
|
+
{searchContextByPaths.map((context) => (<option key={context} value={context}>
|
|
106
|
+
{context}
|
|
107
|
+
</option>))}
|
|
108
|
+
</select>
|
|
109
|
+
</div>) : null}
|
|
110
|
+
</div>
|
|
88
111
|
|
|
89
112
|
{!searchSource && searchQuery && (<div>
|
|
90
113
|
<LoadingRing />
|
|
@@ -38,6 +38,13 @@ function useSearchQuery() {
|
|
|
38
38
|
search: searchParams.toString(),
|
|
39
39
|
});
|
|
40
40
|
},
|
|
41
|
+
updateSearchContext: (searchContext) => {
|
|
42
|
+
const searchParams = new URLSearchParams(location.search);
|
|
43
|
+
searchParams.set(SEARCH_PARAM_CONTEXT, searchContext);
|
|
44
|
+
history.replace({
|
|
45
|
+
search: searchParams.toString(),
|
|
46
|
+
});
|
|
47
|
+
},
|
|
41
48
|
generateSearchPageLink: (searchValue) => {
|
|
42
49
|
const searchParams = getSearchParams(searchValue);
|
|
43
50
|
// Refer to https://github.com/facebook/docusaurus/pull/2838
|
package/dist/locales/vi.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
|
-
"theme.SearchBar.label": "Tìm",
|
|
3
|
-
"theme.SearchBar.seeAll": "Xem tất cả",
|
|
4
|
-
"theme.SearchBar.noResultsText": "Không tìm thấy",
|
|
5
|
-
"theme.SearchPage.existingResultsTitle": "“{query}”
|
|
6
|
-
"theme.SearchPage.emptyResultsTitle": "
|
|
7
|
-
"theme.SearchPage.documentsFound.plurals": "Có {count} kết quả",
|
|
2
|
+
"theme.SearchBar.label": "Tìm kiếm...",
|
|
3
|
+
"theme.SearchBar.seeAll": "Xem tất cả kết quả được tìm thấy",
|
|
4
|
+
"theme.SearchBar.noResultsText": "Không tìm thấy kết quả nào",
|
|
5
|
+
"theme.SearchPage.existingResultsTitle": "Tìm kiếm theo tiêu đề: “{query}”",
|
|
6
|
+
"theme.SearchPage.emptyResultsTitle": "Tìm kiếm theo tiêu đề",
|
|
7
|
+
"theme.SearchPage.documentsFound.plurals": "Có {count} kết quả được tìm thấy",
|
|
8
8
|
"theme.SearchPage.noResultsText": "Không tìm thấy kết quả nào"
|
|
9
9
|
}
|
|
@@ -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, removeDefaultStemmer, highlightSearchTermsOnTargetPage, searchResultLimits, searchResultContextMaxLength, explicitSearchResultPath, searchBarShortcut, searchBarShortcutHint, searchBarPosition, docsPluginIdForPreferredVersion, indexDocs, searchContextByPaths, hideSearchBarWithNoSearchContext, } = config;
|
|
9
|
+
const { language, removeDefaultStopWordFilter, removeDefaultStemmer, highlightSearchTermsOnTargetPage, searchResultLimits, searchResultContextMaxLength, explicitSearchResultPath, searchBarShortcut, searchBarShortcutHint, searchBarPosition, docsPluginIdForPreferredVersion, indexDocs, searchContextByPaths, hideSearchBarWithNoSearchContext, useAllContextsWithNoSearchContext, } = config;
|
|
10
10
|
const indexHash = (0, getIndexHash_1.getIndexHash)(config);
|
|
11
11
|
const contents = [
|
|
12
12
|
`import lunr from ${JSON.stringify(require.resolve("lunr"))};`,
|
|
@@ -60,6 +60,7 @@ function generate(config, dir) {
|
|
|
60
60
|
? searchContextByPaths
|
|
61
61
|
: null)};`);
|
|
62
62
|
contents.push(`export const hideSearchBarWithNoSearchContext = ${JSON.stringify(!!hideSearchBarWithNoSearchContext)};`);
|
|
63
|
+
contents.push(`export const useAllContextsWithNoSearchContext = ${JSON.stringify(!!useAllContextsWithNoSearchContext)};`);
|
|
63
64
|
fs_1.default.writeFileSync(path_1.default.join(dir, "generated.js"), contents.join("\n"));
|
|
64
65
|
return searchIndexFilename;
|
|
65
66
|
}
|
|
@@ -21,7 +21,7 @@ function postBuildFactory(config, searchIndexFilename) {
|
|
|
21
21
|
const allDocuments = yield (0, scanDocuments_1.scanDocuments)(versionData.paths);
|
|
22
22
|
(0, debug_1.debugInfo)("building index");
|
|
23
23
|
const docsByDirMap = new Map();
|
|
24
|
-
const { searchContextByPaths, hideSearchBarWithNoSearchContext } = config;
|
|
24
|
+
const { searchContextByPaths, hideSearchBarWithNoSearchContext, useAllContextsWithNoSearchContext, } = config;
|
|
25
25
|
if (searchContextByPaths) {
|
|
26
26
|
const { baseUrl } = buildData;
|
|
27
27
|
const rootAllDocs = [];
|
|
@@ -46,7 +46,9 @@ function postBuildFactory(config, searchIndexFilename) {
|
|
|
46
46
|
dirAllDocs[docIndex] = dirDocs = [];
|
|
47
47
|
}
|
|
48
48
|
dirDocs.push(doc);
|
|
49
|
-
|
|
49
|
+
if (!useAllContextsWithNoSearchContext) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
50
52
|
}
|
|
51
53
|
}
|
|
52
54
|
rootAllDocs[docIndex].push(doc);
|
|
@@ -30,6 +30,7 @@ const schema = utils_validation_1.Joi.object({
|
|
|
30
30
|
zhUserDictPath: utils_validation_1.Joi.string(),
|
|
31
31
|
searchContextByPaths: utils_validation_1.Joi.array().items(utils_validation_1.Joi.string()),
|
|
32
32
|
hideSearchBarWithNoSearchContext: utils_validation_1.Joi.boolean().default(false),
|
|
33
|
+
useAllContextsWithNoSearchContext: utils_validation_1.Joi.boolean().default(false),
|
|
33
34
|
});
|
|
34
35
|
function validateOptions({ options, validate, }) {
|
|
35
36
|
return validate(schema, options || {});
|
package/dist/types/index.d.ts
CHANGED
|
@@ -149,4 +149,13 @@ export interface PluginOptions {
|
|
|
149
149
|
* @default false
|
|
150
150
|
*/
|
|
151
151
|
hideSearchBarWithNoSearchContext?: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Whether to show results from all the contexts if no context is provided.
|
|
154
|
+
*
|
|
155
|
+
* This option should not be used with `hideSearchBarWithNoSearchContext` set to `true` as this would show results
|
|
156
|
+
* when there is no search context.
|
|
157
|
+
*
|
|
158
|
+
* @default false
|
|
159
|
+
*/
|
|
160
|
+
useAllContextsWithNoSearchContext?: boolean;
|
|
152
161
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easyops-cn/docusaurus-search-local",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0",
|
|
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",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"@types/jest": "^28.0.0",
|
|
55
55
|
"@types/klaw-sync": "^6.0.0",
|
|
56
56
|
"@types/lunr": "^2.3.3",
|
|
57
|
-
"@types/node": "^
|
|
57
|
+
"@types/node": "^18.0.0",
|
|
58
58
|
"@types/react": "^18.0.0",
|
|
59
59
|
"@types/react-helmet": "^6.1.0",
|
|
60
60
|
"@types/react-router-dom": "^5.1.6",
|