@easyops-cn/docusaurus-search-local 0.30.2 → 0.31.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.31.0](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.30.2...v0.31.0) (2022-08-08)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* support `zhUserDict` and `zhUserDictPath` ([33f1ea4](https://github.com/easyops-cn/docusaurus-search-local/commit/33f1ea4765b0e134689fd65aa655c2bc1b4e6f0b)), closes [#246](https://github.com/easyops-cn/docusaurus-search-local/issues/246)
|
|
11
|
+
|
|
5
12
|
## [0.30.2](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.30.1...v0.30.2) (2022-07-23)
|
|
6
13
|
|
|
7
14
|
|
|
@@ -2,28 +2,24 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildIndex = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
/* eslint @typescript-eslint/no-var-requires: 0 */
|
|
5
6
|
const lunr_1 = tslib_1.__importDefault(require("lunr"));
|
|
6
|
-
function buildIndex(allDocuments, { language, removeDefaultStopWordFilter, removeDefaultStemmer, }) {
|
|
7
|
+
function buildIndex(allDocuments, { language, removeDefaultStopWordFilter, removeDefaultStemmer, zhUserDict, zhUserDictPath, }) {
|
|
7
8
|
if (language.length > 1 || language.some((item) => item !== "en")) {
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
9
9
|
require("lunr-languages/lunr.stemmer.support")(lunr_1.default);
|
|
10
10
|
}
|
|
11
11
|
if (language.includes("ja") || language.includes("jp")) {
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
13
12
|
require("lunr-languages/tinyseg")(lunr_1.default);
|
|
14
13
|
}
|
|
15
14
|
for (const lang of language.filter((item) => item !== "en" && item !== "zh")) {
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
17
15
|
require(`lunr-languages/lunr.${lang}`)(lunr_1.default);
|
|
18
16
|
}
|
|
19
17
|
if (language.includes("zh")) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
require("./tokenizer").tokenizer);
|
|
18
|
+
const { tokenizer, loadUserDict } = require("./tokenizer");
|
|
19
|
+
loadUserDict(zhUserDict, zhUserDictPath);
|
|
20
|
+
require("../../shared/lunrLanguageZh").lunrLanguageZh(lunr_1.default, tokenizer);
|
|
24
21
|
}
|
|
25
22
|
if (language.length > 1) {
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
27
23
|
require("lunr-languages/lunr.multi")(lunr_1.default);
|
|
28
24
|
}
|
|
29
25
|
return allDocuments.map((documents) => ({
|
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.tokenizer = void 0;
|
|
3
|
+
exports.tokenizer = exports.loadUserDict = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
5
6
|
const lunr_1 = tslib_1.__importDefault(require("lunr"));
|
|
6
7
|
const jieba_1 = tslib_1.__importDefault(require("@node-rs/jieba"));
|
|
7
8
|
const cutWordByUnderscore_1 = require("./cutWordByUnderscore");
|
|
8
9
|
// https://zhuanlan.zhihu.com/p/33335629
|
|
9
10
|
const RegExpConsecutiveWord = /\w+|\p{Unified_Ideograph}+/u;
|
|
11
|
+
let userDictLoaded = false;
|
|
12
|
+
function loadUserDict(zhUserDict, zhUserDictPath) {
|
|
13
|
+
if (userDictLoaded) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (zhUserDict) {
|
|
17
|
+
jieba_1.default.loadDict(Buffer.from(zhUserDict));
|
|
18
|
+
}
|
|
19
|
+
else if (zhUserDictPath) {
|
|
20
|
+
jieba_1.default.loadDict(fs_1.default.readFileSync(zhUserDictPath));
|
|
21
|
+
}
|
|
22
|
+
userDictLoaded = true;
|
|
23
|
+
}
|
|
24
|
+
exports.loadUserDict = loadUserDict;
|
|
10
25
|
function tokenizer(input, metadata) {
|
|
11
26
|
if (input == null) {
|
|
12
27
|
return [];
|
|
@@ -25,6 +25,8 @@ const schema = utils_validation_1.Joi.object({
|
|
|
25
25
|
searchBarShortcut: utils_validation_1.Joi.boolean().default(true),
|
|
26
26
|
searchBarShortcutHint: utils_validation_1.Joi.boolean().default(true),
|
|
27
27
|
docsPluginIdForPreferredVersion: utils_validation_1.Joi.string(),
|
|
28
|
+
zhUserDict: utils_validation_1.Joi.string(),
|
|
29
|
+
zhUserDictPath: utils_validation_1.Joi.string(),
|
|
28
30
|
});
|
|
29
31
|
function validateOptions({ options, validate, }) {
|
|
30
32
|
return validate(schema, options || {});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easyops-cn/docusaurus-search-local",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.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",
|