@easyops-cn/docusaurus-search-local 0.46.0 → 0.47.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/dist/client/client/theme/searchByWorker.js +1 -1
- package/dist/client/client/theme/worker.js +1 -2
- package/dist/client/client/utils/__mocks__/proxiedGenerated.js +1 -14
- package/dist/client/client/utils/__mocks__/proxiedGeneratedConstants.js +10 -0
- package/dist/client/client/utils/proxiedGeneratedConstants.js +2 -0
- package/dist/client/client/utils/smartQueries.js +1 -1
- package/dist/server/server/utils/generate.js +25 -23
- package/package.json +6 -6
- package/dist/client/client/utils/SearchSourceFactory.js +0 -52
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.47.0](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.46.1...v0.47.0) (2025-01-07)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* support React 19 ([725074e](https://github.com/easyops-cn/docusaurus-search-local/commit/725074eb84f153f84974cd6f4bac21d8aee79187)), closes [#474](https://github.com/easyops-cn/docusaurus-search-local/issues/474)
|
|
11
|
+
|
|
12
|
+
## [0.46.1](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.46.0...v0.46.1) (2024-11-27)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* fix Uncaught ReferenceError: importScripts is not defined ([139b82b](https://github.com/easyops-cn/docusaurus-search-local/commit/139b82befc22a574d71eb307b3a79afb2984ea69))
|
|
18
|
+
|
|
5
19
|
## [0.46.0](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.45.0...v0.46.0) (2024-11-27)
|
|
6
20
|
|
|
7
21
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as Comlink from "comlink";
|
|
2
2
|
let remoteWorkerPromise;
|
|
3
3
|
function getRemoteWorker() {
|
|
4
|
-
if (!remoteWorkerPromise) {
|
|
4
|
+
if (process.env.NODE_ENV === "production" && !remoteWorkerPromise) {
|
|
5
5
|
remoteWorkerPromise = (async () => {
|
|
6
6
|
const Remote = Comlink.wrap(new Worker(new URL("./worker.js", import.meta.url)));
|
|
7
7
|
return await new Remote();
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import * as Comlink from "comlink";
|
|
2
2
|
import lunr from "lunr";
|
|
3
|
-
import { searchIndexUrl, searchResultLimits } from "../utils/
|
|
3
|
+
import { searchIndexUrl, searchResultLimits, language } from "../utils/proxiedGeneratedConstants";
|
|
4
4
|
import { tokenize } from "../utils/tokenize";
|
|
5
5
|
import { smartQueries } from "../utils/smartQueries";
|
|
6
6
|
import { SearchDocumentType, } from "../../shared/interfaces";
|
|
7
7
|
import { sortSearchResults } from "../utils/sortSearchResults";
|
|
8
8
|
import { processTreeStatusOfSearchResults } from "../utils/processTreeStatusOfSearchResults";
|
|
9
|
-
import { language } from "../utils/proxiedGenerated";
|
|
10
9
|
const cache = new Map();
|
|
11
10
|
export class SearchWorker {
|
|
12
11
|
async fetchIndexes(baseUrl, searchContext) {
|
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export let removeDefaultStopWordFilter = false;
|
|
3
|
-
export let removeDefaultStemmer = false;
|
|
4
|
-
export const searchIndexUrl = "search-index{dir}.json?_=abc";
|
|
5
|
-
export const searchResultLimits = 8;
|
|
1
|
+
export const removeDefaultStemmer = false;
|
|
6
2
|
export const searchResultContextMaxLength = 50;
|
|
7
3
|
export const explicitSearchResultPath = false;
|
|
8
4
|
export const docsPluginIdForPreferredVersion = undefined;
|
|
9
5
|
export const indexDocs = true;
|
|
10
|
-
export function __setLanguage(value) {
|
|
11
|
-
language = value;
|
|
12
|
-
}
|
|
13
|
-
export function __setRemoveDefaultStopWordFilter(value) {
|
|
14
|
-
removeDefaultStopWordFilter = value;
|
|
15
|
-
}
|
|
16
|
-
export function __setRemoveDefaultStemmer(value) {
|
|
17
|
-
removeDefaultStemmer = value;
|
|
18
|
-
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export let language = ["en", "zh"];
|
|
2
|
+
export let removeDefaultStopWordFilter = false;
|
|
3
|
+
export const searchIndexUrl = "search-index{dir}.json?_=abc";
|
|
4
|
+
export const searchResultLimits = 8;
|
|
5
|
+
export function __setLanguage(value) {
|
|
6
|
+
language = value;
|
|
7
|
+
}
|
|
8
|
+
export function __setRemoveDefaultStopWordFilter(value) {
|
|
9
|
+
removeDefaultStopWordFilter = value;
|
|
10
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import lunr from "lunr";
|
|
2
2
|
import { smartTerms } from "./smartTerms";
|
|
3
|
-
import { language, removeDefaultStopWordFilter } from "./
|
|
3
|
+
import { language, removeDefaultStopWordFilter } from "./proxiedGeneratedConstants";
|
|
4
4
|
/**
|
|
5
5
|
* Get all possible queries for a list of tokens consists of words mixed English and Chinese,
|
|
6
6
|
* by a Chinese words dictionary.
|
|
@@ -8,26 +8,7 @@ const getIndexHash_1 = require("./getIndexHash");
|
|
|
8
8
|
function generate(config, dir) {
|
|
9
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
|
-
const contents = [
|
|
12
|
-
`import lunr from ${JSON.stringify(require.resolve("lunr"))};`,
|
|
13
|
-
];
|
|
14
|
-
if (language.length > 1 || language.some((item) => item !== "en")) {
|
|
15
|
-
contents.push(`require(${JSON.stringify(require.resolve("lunr-languages/lunr.stemmer.support"))})(lunr);`);
|
|
16
|
-
}
|
|
17
|
-
if (language.includes("ja") || language.includes("jp")) {
|
|
18
|
-
contents.push(`require(${JSON.stringify(require.resolve("lunr-languages/tinyseg"))})(lunr);`);
|
|
19
|
-
}
|
|
20
|
-
for (const lang of language.filter((item) => item !== "en" && item !== "zh")) {
|
|
21
|
-
contents.push(`require(${JSON.stringify(require.resolve(`lunr-languages/lunr.${lang}`))})(lunr);`);
|
|
22
|
-
}
|
|
23
|
-
if (language.includes("zh")) {
|
|
24
|
-
contents.push(`require(${JSON.stringify(require.resolve("@easyops-cn/docusaurus-search-local/dist/client/shared/lunrLanguageZh"))}).lunrLanguageZh(lunr);`);
|
|
25
|
-
}
|
|
26
|
-
if (language.length > 1) {
|
|
27
|
-
contents.push(`require(${JSON.stringify(require.resolve("lunr-languages/lunr.multi"))})(lunr);`);
|
|
28
|
-
}
|
|
29
|
-
contents.push(`export const language = ${JSON.stringify(language)};`);
|
|
30
|
-
contents.push(`export const removeDefaultStopWordFilter = ${JSON.stringify(removeDefaultStopWordFilter)};`);
|
|
11
|
+
const contents = [];
|
|
31
12
|
contents.push(`export const removeDefaultStemmer = ${JSON.stringify(removeDefaultStemmer)};`);
|
|
32
13
|
if (highlightSearchTermsOnTargetPage) {
|
|
33
14
|
contents.push(`export { default as Mark } from ${JSON.stringify(require.resolve("mark.js"))}`);
|
|
@@ -45,9 +26,7 @@ function generate(config, dir) {
|
|
|
45
26
|
searchIndexQuery = `?_=${indexHash}`;
|
|
46
27
|
}
|
|
47
28
|
}
|
|
48
|
-
const
|
|
49
|
-
contents.push(`export const searchIndexUrl = ${JSON.stringify(searchIndexUrl)};`);
|
|
50
|
-
contents.push(`export const searchResultLimits = ${JSON.stringify(searchResultLimits)};`, `export const searchResultContextMaxLength = ${JSON.stringify(searchResultContextMaxLength)};`);
|
|
29
|
+
contents.push(`export const searchResultContextMaxLength = ${JSON.stringify(searchResultContextMaxLength)};`);
|
|
51
30
|
contents.push(`export const explicitSearchResultPath = ${JSON.stringify(explicitSearchResultPath)};`);
|
|
52
31
|
contents.push(`export const searchBarShortcut = ${JSON.stringify(searchBarShortcut)};`);
|
|
53
32
|
contents.push(`export const searchBarShortcutHint = ${JSON.stringify(searchBarShortcutHint)};`);
|
|
@@ -62,6 +41,29 @@ function generate(config, dir) {
|
|
|
62
41
|
contents.push(`export const hideSearchBarWithNoSearchContext = ${JSON.stringify(!!hideSearchBarWithNoSearchContext)};`);
|
|
63
42
|
contents.push(`export const useAllContextsWithNoSearchContext = ${JSON.stringify(!!useAllContextsWithNoSearchContext)};`);
|
|
64
43
|
fs_1.default.writeFileSync(path_1.default.join(dir, "generated.js"), contents.join("\n"));
|
|
44
|
+
const constantContents = [
|
|
45
|
+
`import lunr from ${JSON.stringify(require.resolve("lunr"))};`,
|
|
46
|
+
];
|
|
47
|
+
if (language.length > 1 || language.some((item) => item !== "en")) {
|
|
48
|
+
constantContents.push(`require(${JSON.stringify(require.resolve("lunr-languages/lunr.stemmer.support"))})(lunr);`);
|
|
49
|
+
}
|
|
50
|
+
if (language.includes("ja") || language.includes("jp")) {
|
|
51
|
+
constantContents.push(`require(${JSON.stringify(require.resolve("lunr-languages/tinyseg"))})(lunr);`);
|
|
52
|
+
}
|
|
53
|
+
for (const lang of language.filter((item) => item !== "en" && item !== "zh")) {
|
|
54
|
+
constantContents.push(`require(${JSON.stringify(require.resolve(`lunr-languages/lunr.${lang}`))})(lunr);`);
|
|
55
|
+
}
|
|
56
|
+
if (language.includes("zh")) {
|
|
57
|
+
constantContents.push(`require(${JSON.stringify(require.resolve("@easyops-cn/docusaurus-search-local/dist/client/shared/lunrLanguageZh"))}).lunrLanguageZh(lunr);`);
|
|
58
|
+
}
|
|
59
|
+
if (language.length > 1) {
|
|
60
|
+
constantContents.push(`require(${JSON.stringify(require.resolve("lunr-languages/lunr.multi"))})(lunr);`);
|
|
61
|
+
}
|
|
62
|
+
constantContents.push(`export const removeDefaultStopWordFilter = ${JSON.stringify(removeDefaultStopWordFilter)};`);
|
|
63
|
+
constantContents.push(`export const language = ${JSON.stringify(language)};`);
|
|
64
|
+
const searchIndexUrl = searchIndexFilename + searchIndexQuery;
|
|
65
|
+
constantContents.push(`export const searchIndexUrl = ${JSON.stringify(searchIndexUrl)};`, `export const searchResultLimits = ${JSON.stringify(searchResultLimits)};`);
|
|
66
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, "generated-constants.js"), constantContents.join("\n"));
|
|
65
67
|
return searchIndexFilename;
|
|
66
68
|
}
|
|
67
69
|
exports.generate = generate;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easyops-cn/docusaurus-search-local",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.47.0",
|
|
4
4
|
"description": "An offline/local search plugin for Docusaurus v3",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@easyops-cn/autocomplete.js": "^0.38.1",
|
|
39
39
|
"@node-rs/jieba": "^1.6.0",
|
|
40
40
|
"cheerio": "^1.0.0",
|
|
41
|
-
"clsx": "^
|
|
41
|
+
"clsx": "^2.1.1",
|
|
42
42
|
"comlink": "^4.4.2",
|
|
43
43
|
"debug": "^4.2.0",
|
|
44
44
|
"fs-extra": "^10.0.0",
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
"@types/klaw-sync": "^6.0.0",
|
|
61
61
|
"@types/lunr": "^2.3.3",
|
|
62
62
|
"@types/node": "^18.0.0",
|
|
63
|
-
"@types/react": "^
|
|
64
|
-
"@types/react-helmet": "^6.1.
|
|
63
|
+
"@types/react": "^19.0.3",
|
|
64
|
+
"@types/react-helmet": "^6.1.1",
|
|
65
65
|
"@types/react-router-dom": "^5.1.6",
|
|
66
66
|
"concurrently": "^7.0.0",
|
|
67
67
|
"copyfiles": "^2.4.0",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
72
|
"@docusaurus/theme-common": "^2 || ^3",
|
|
73
|
-
"react": "^16.14.0 || ^17 || ^18",
|
|
74
|
-
"react-dom": "^16.14.0 || 17 || ^18"
|
|
73
|
+
"react": "^16.14.0 || ^17 || ^18 || ^19",
|
|
74
|
+
"react-dom": "^16.14.0 || 17 || ^18 || ^19"
|
|
75
75
|
}
|
|
76
76
|
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { tokenize } from "./tokenize";
|
|
2
|
-
import { smartQueries } from "./smartQueries";
|
|
3
|
-
import { SearchDocumentType, } from "../../shared/interfaces";
|
|
4
|
-
import { sortSearchResults } from "./sortSearchResults";
|
|
5
|
-
import { processTreeStatusOfSearchResults } from "./processTreeStatusOfSearchResults";
|
|
6
|
-
import { language } from "./proxiedGenerated";
|
|
7
|
-
export function SearchSourceFactory(wrappedIndexes, zhDictionary, resultsLimit) {
|
|
8
|
-
return function searchSource(input, callback) {
|
|
9
|
-
const rawTokens = tokenize(input, language);
|
|
10
|
-
if (rawTokens.length === 0) {
|
|
11
|
-
callback([]);
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
const queries = smartQueries(rawTokens, zhDictionary);
|
|
15
|
-
const results = [];
|
|
16
|
-
search: for (const { term, tokens } of queries) {
|
|
17
|
-
for (const { documents, index, type } of wrappedIndexes) {
|
|
18
|
-
results.push(...index
|
|
19
|
-
.query((query) => {
|
|
20
|
-
for (const item of term) {
|
|
21
|
-
query.term(item.value, {
|
|
22
|
-
wildcard: item.wildcard,
|
|
23
|
-
presence: item.presence,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
})
|
|
27
|
-
.slice(0, resultsLimit)
|
|
28
|
-
// Remove duplicated results.
|
|
29
|
-
.filter((result) => !results.some((item) => item.document.i.toString() === result.ref))
|
|
30
|
-
.slice(0, resultsLimit - results.length)
|
|
31
|
-
.map((result) => {
|
|
32
|
-
const document = documents.find((doc) => doc.i.toString() === result.ref);
|
|
33
|
-
return {
|
|
34
|
-
document,
|
|
35
|
-
type,
|
|
36
|
-
page: type !== SearchDocumentType.Title &&
|
|
37
|
-
wrappedIndexes[0].documents.find((doc) => doc.i === document.p),
|
|
38
|
-
metadata: result.matchData.metadata,
|
|
39
|
-
tokens,
|
|
40
|
-
score: result.score,
|
|
41
|
-
};
|
|
42
|
-
}));
|
|
43
|
-
if (results.length >= resultsLimit) {
|
|
44
|
-
break search;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
sortSearchResults(results);
|
|
49
|
-
processTreeStatusOfSearchResults(results);
|
|
50
|
-
callback(results);
|
|
51
|
-
};
|
|
52
|
-
}
|