@easyops-cn/docusaurus-search-local 0.27.1 → 0.27.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,32 +2,39 @@
|
|
|
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.27.
|
|
5
|
+
## [0.27.2](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.27.1...v0.27.2) (2022-06-21)
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
### Bug Fixes
|
|
9
9
|
|
|
10
|
-
*
|
|
10
|
+
* search page for non latest doc versions ([15f6161](https://github.com/easyops-cn/docusaurus-search-local/commit/15f61612f8d59dde0ba401e15d76d080865d8e8b))
|
|
11
|
+
* use the active plugin id when getting the current docs version ([824e134](https://github.com/easyops-cn/docusaurus-search-local/commit/824e1347f3f571b45e1e39f708ffd75c01f13339))
|
|
12
|
+
* fix active plugin may be undefined ([0bfbbb2](https://github.com/easyops-cn/docusaurus-search-local/commit/0bfbbb29cee66fcbb3be589da226caef6210fa5a))
|
|
13
|
+
* make `@docusaurus/theme-common` as peer ([68dc812](https://github.com/easyops-cn/docusaurus-search-local/commit/68dc812c84451c68dc9f9448c4a2b39a3f8f3bcc))
|
|
11
14
|
|
|
12
|
-
## [0.27.
|
|
15
|
+
## [0.27.1](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.27.0...v0.27.1) (2022-06-13)
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
- properly support no trailing slashes after fixing indexing top level pages ([999bd8b](https://github.com/easyops-cn/docusaurus-search-local/commit/999bd8bec8abe73f12abe20f58f8030be46c9ecd)), closes [#212](https://github.com/easyops-cn/docusaurus-search-local/issues/212)
|
|
13
20
|
|
|
21
|
+
## [0.27.0](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.26.1...v0.27.0) (2022-05-29)
|
|
14
22
|
|
|
15
23
|
### Features
|
|
16
24
|
|
|
17
|
-
|
|
25
|
+
- versioned search ([6865e7c](https://github.com/easyops-cn/docusaurus-search-local/commit/6865e7c3eee416e53648877359cdf206119be043)), closes [#66](https://github.com/easyops-cn/docusaurus-search-local/issues/66)
|
|
18
26
|
|
|
19
27
|
### [0.26.1](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.26.0...v0.26.1) (2022-05-25)
|
|
20
28
|
|
|
21
|
-
|
|
22
29
|
### Bug Fixes
|
|
23
30
|
|
|
24
|
-
|
|
31
|
+
- fix i18n id of `theme.SearchPage.noResultsText` ([fe530f3](https://github.com/easyops-cn/docusaurus-search-local/commit/fe530f35da0b11c78c9d68cb6a7fea5871919e00))
|
|
25
32
|
|
|
26
33
|
## [0.26.0](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.26.0...v0.26.0) (2022-05-24)
|
|
27
34
|
|
|
28
35
|
### Features
|
|
29
36
|
|
|
30
|
-
|
|
37
|
+
- add a clear button to the search bar [#170](https://github.com/easyops-cn/docusaurus-search-local/issues/170) ([f516123](https://github.com/easyops-cn/docusaurus-search-local/commit/f5161238cb7466fe7309e9166037d681e647f910))
|
|
31
38
|
|
|
32
39
|
## [0.25.0](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.24.1...v0.25.0) (2022-05-19)
|
|
33
40
|
|
|
@@ -4,7 +4,8 @@ import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
|
|
|
4
4
|
import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment";
|
|
5
5
|
import { useHistory, useLocation } from "@docusaurus/router";
|
|
6
6
|
import { translate } from "@docusaurus/Translate";
|
|
7
|
-
import {
|
|
7
|
+
import { useDocsPreferredVersion } from "@docusaurus/theme-common";
|
|
8
|
+
import { useActivePlugin } from "@docusaurus/plugin-content-docs/client";
|
|
8
9
|
import { fetchIndexes } from "./fetchIndexes";
|
|
9
10
|
import { SearchSourceFactory } from "../../utils/SearchSourceFactory";
|
|
10
11
|
import { SuggestionTemplate } from "./SuggestionTemplate";
|
|
@@ -27,10 +28,17 @@ async function fetchAutoCompleteJS() {
|
|
|
27
28
|
}
|
|
28
29
|
const SEARCH_PARAM_HIGHLIGHT = "_highlight";
|
|
29
30
|
export default function SearchBar({ handleSearchBarToggle, }) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
const { siteConfig: { baseUrl }, } = useDocusaurusContext();
|
|
32
|
+
// It returns undefined for non-docs pages
|
|
33
|
+
const activePlugin = useActivePlugin();
|
|
34
|
+
let versionUrl = baseUrl;
|
|
35
|
+
// For non-docs pages while using plugin-content-docs with custom ids,
|
|
36
|
+
// this will throw an error of:
|
|
37
|
+
// > Docusaurus plugin global data not found for "docusaurus-plugin-content-docs" plugin with id "default".
|
|
38
|
+
// It seems that we can not get the correct id for non-docs pages.
|
|
39
|
+
const { preferredVersion } = useDocsPreferredVersion(activePlugin?.pluginId);
|
|
40
|
+
if (preferredVersion && !preferredVersion.isLast) {
|
|
41
|
+
versionUrl = preferredVersion.path + "/";
|
|
34
42
|
}
|
|
35
43
|
const history = useHistory();
|
|
36
44
|
const location = useLocation();
|
|
@@ -50,7 +58,7 @@ export default function SearchBar({ handleSearchBarToggle, }) {
|
|
|
50
58
|
indexState.current = "loading";
|
|
51
59
|
setLoading(true);
|
|
52
60
|
const [{ wrappedIndexes, zhDictionary }, autoComplete] = await Promise.all([
|
|
53
|
-
fetchIndexes(
|
|
61
|
+
fetchIndexes(versionUrl),
|
|
54
62
|
fetchAutoCompleteJS(),
|
|
55
63
|
]);
|
|
56
64
|
search.current = autoComplete(searchBarRef.current, {
|
|
@@ -128,7 +136,7 @@ export default function SearchBar({ handleSearchBarToggle, }) {
|
|
|
128
136
|
}
|
|
129
137
|
input.focus();
|
|
130
138
|
}
|
|
131
|
-
}, [baseUrl, history]);
|
|
139
|
+
}, [baseUrl, versionUrl, history]);
|
|
132
140
|
useEffect(() => {
|
|
133
141
|
if (!Mark) {
|
|
134
142
|
return;
|
|
@@ -193,15 +201,17 @@ export default function SearchBar({ handleSearchBarToggle, }) {
|
|
|
193
201
|
const onClearSearch = useCallback(() => {
|
|
194
202
|
const params = new URLSearchParams(location.search);
|
|
195
203
|
params.delete(SEARCH_PARAM_HIGHLIGHT);
|
|
196
|
-
|
|
197
|
-
|
|
204
|
+
const paramsStr = params.toString();
|
|
205
|
+
const searchUrl = location.pathname +
|
|
206
|
+
(paramsStr != "" ? `?${paramsStr}` : "") +
|
|
207
|
+
location.hash;
|
|
198
208
|
if (searchUrl != location.pathname + location.search + location.hash) {
|
|
199
209
|
history.push(searchUrl);
|
|
200
210
|
}
|
|
201
211
|
// We always clear these here because in case no match was selected the above history push wont happen
|
|
202
212
|
setInputValue("");
|
|
203
213
|
search.current?.autocomplete.setVal("");
|
|
204
|
-
}, [location.pathname, location.search, location.hash]);
|
|
214
|
+
}, [location.pathname, location.search, location.hash, history]);
|
|
205
215
|
return (<div className={clsx("navbar__search", styles.searchBarContainer, {
|
|
206
216
|
[styles.searchIndexLoading]: loading && inputChanged,
|
|
207
217
|
})}>
|
|
@@ -4,7 +4,8 @@ import Layout from "@theme/Layout";
|
|
|
4
4
|
import Head from "@docusaurus/Head";
|
|
5
5
|
import Link from "@docusaurus/Link";
|
|
6
6
|
import { translate } from "@docusaurus/Translate";
|
|
7
|
-
import { usePluralForm } from "@docusaurus/theme-common";
|
|
7
|
+
import { usePluralForm, useDocsPreferredVersion, } from "@docusaurus/theme-common";
|
|
8
|
+
import { useActivePlugin } from "@docusaurus/plugin-content-docs/client";
|
|
8
9
|
import useSearchQuery from "../hooks/useSearchQuery";
|
|
9
10
|
import { fetchIndexes } from "../SearchBar/fetchIndexes";
|
|
10
11
|
import { SearchSourceFactory } from "../../utils/SearchSourceFactory";
|
|
@@ -15,7 +16,20 @@ import LoadingRing from "../LoadingRing/LoadingRing";
|
|
|
15
16
|
import styles from "./SearchPage.module.css";
|
|
16
17
|
import { concatDocumentPath } from "../../utils/concatDocumentPath";
|
|
17
18
|
export default function SearchPage() {
|
|
19
|
+
return (<Layout>
|
|
20
|
+
<SearchPageContent />
|
|
21
|
+
</Layout>);
|
|
22
|
+
}
|
|
23
|
+
function SearchPageContent() {
|
|
18
24
|
const { siteConfig: { baseUrl }, } = useDocusaurusContext();
|
|
25
|
+
// It returns undefined for non-docs pages.
|
|
26
|
+
const activePlugin = useActivePlugin();
|
|
27
|
+
let versionUrl = baseUrl;
|
|
28
|
+
// There is an issue, see `SearchBar.tsx`.
|
|
29
|
+
const { preferredVersion } = useDocsPreferredVersion(activePlugin?.pluginId);
|
|
30
|
+
if (preferredVersion && !preferredVersion.isLast) {
|
|
31
|
+
versionUrl = preferredVersion.path + "/";
|
|
32
|
+
}
|
|
19
33
|
const { selectMessage } = usePluralForm();
|
|
20
34
|
const { searchValue, updateSearchPath } = useSearchQuery();
|
|
21
35
|
const [searchQuery, setSearchQuery] = useState(searchValue);
|
|
@@ -59,12 +73,12 @@ export default function SearchPage() {
|
|
|
59
73
|
}, [searchValue]);
|
|
60
74
|
useEffect(() => {
|
|
61
75
|
async function doFetchIndexes() {
|
|
62
|
-
const { wrappedIndexes, zhDictionary } = await fetchIndexes(
|
|
76
|
+
const { wrappedIndexes, zhDictionary } = await fetchIndexes(versionUrl);
|
|
63
77
|
setSearchSource(() => SearchSourceFactory(wrappedIndexes, zhDictionary, 100));
|
|
64
78
|
}
|
|
65
79
|
doFetchIndexes();
|
|
66
|
-
}, [
|
|
67
|
-
return (<
|
|
80
|
+
}, [versionUrl]);
|
|
81
|
+
return (<React.Fragment>
|
|
68
82
|
<Head>
|
|
69
83
|
{/*
|
|
70
84
|
We should not index search pages
|
|
@@ -106,7 +120,7 @@ export default function SearchPage() {
|
|
|
106
120
|
searchResults.map((item) => (<SearchResultItem key={item.document.i} searchResult={item}/>))}
|
|
107
121
|
</section>
|
|
108
122
|
</div>
|
|
109
|
-
</
|
|
123
|
+
</React.Fragment>);
|
|
110
124
|
}
|
|
111
125
|
function SearchResultItem({ searchResult: { document, type, page, tokens, metadata }, }) {
|
|
112
126
|
const isTitle = type === 0;
|
|
@@ -7,12 +7,12 @@ function processDocInfos({ routesPaths, outDir, baseUrl, siteConfig, plugins },
|
|
|
7
7
|
const emptySet = new Set();
|
|
8
8
|
let versionData = [{ versionOutDir: outDir, docs: emptySet }];
|
|
9
9
|
if (plugins) {
|
|
10
|
-
const docsPluginData = plugins.find(element => element.name === "docusaurus-plugin-content-docs");
|
|
10
|
+
const docsPluginData = plugins.find((element) => element.name === "docusaurus-plugin-content-docs");
|
|
11
11
|
if (docsPluginData) {
|
|
12
12
|
versionData = [];
|
|
13
13
|
const loadedVersions = docsPluginData.content.loadedVersions;
|
|
14
14
|
for (const loadedVersion of loadedVersions) {
|
|
15
|
-
|
|
15
|
+
const docs = new Set();
|
|
16
16
|
for (const doc of loadedVersion.docs) {
|
|
17
17
|
docs.add(doc.permalink);
|
|
18
18
|
}
|
|
@@ -27,7 +27,7 @@ function processDocInfos({ routesPaths, outDir, baseUrl, siteConfig, plugins },
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
// Create a list of files to index per document version. This will always include all pages and blogs.
|
|
30
|
-
|
|
30
|
+
const result = [];
|
|
31
31
|
for (const { versionOutDir, docs } of versionData) {
|
|
32
32
|
const versionPaths = routesPaths
|
|
33
33
|
.map((url) => {
|
|
@@ -37,7 +37,8 @@ function processDocInfos({ routesPaths, outDir, baseUrl, siteConfig, plugins },
|
|
|
37
37
|
}
|
|
38
38
|
const route = url.substr(baseUrl.length).replace(/\/$/, "");
|
|
39
39
|
// Do not index homepage, error page and search page.
|
|
40
|
-
if (((!docsRouteBasePath || docsRouteBasePath[0] !== "") &&
|
|
40
|
+
if (((!docsRouteBasePath || docsRouteBasePath[0] !== "") &&
|
|
41
|
+
route === "") ||
|
|
41
42
|
route === "404.html" ||
|
|
42
43
|
route === "search") {
|
|
43
44
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easyops-cn/docusaurus-search-local",
|
|
3
|
-
"version": "0.27.
|
|
3
|
+
"version": "0.27.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",
|
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@docusaurus/plugin-content-docs": "^2.0.0-beta.20",
|
|
27
|
-
"@docusaurus/theme-common": "^2.0.0-beta.20",
|
|
28
27
|
"@docusaurus/theme-translations": "^2.0.0-beta.20",
|
|
29
28
|
"@docusaurus/utils": "^2.0.0-beta.20",
|
|
30
29
|
"@docusaurus/utils-common": "^2.0.0-beta.20",
|
|
@@ -43,6 +42,7 @@
|
|
|
43
42
|
},
|
|
44
43
|
"devDependencies": {
|
|
45
44
|
"@docusaurus/module-type-aliases": "^2.0.0-beta.20",
|
|
45
|
+
"@docusaurus/theme-common": "^2.0.0-beta.20",
|
|
46
46
|
"@docusaurus/types": "^2.0.0-beta.20",
|
|
47
47
|
"@tsconfig/docusaurus": "^1.0.2",
|
|
48
48
|
"@types/cheerio": "^0.22.31",
|
|
@@ -61,6 +61,8 @@
|
|
|
61
61
|
"typescript": "^4.6.4"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
|
-
"
|
|
64
|
+
"@docusaurus/theme-common": "^2.0.0-beta.20",
|
|
65
|
+
"react": "^16.14.0 || ^17.0.0 || ^18.0.0",
|
|
66
|
+
"react-dom": "^16.14.0 || ^17.0.0 || ^18.0.0"
|
|
65
67
|
}
|
|
66
68
|
}
|