@easyops-cn/docusaurus-search-local 0.29.4 → 0.30.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 +22 -0
- package/dist/client/client/theme/SearchBar/SearchBar.jsx +8 -7
- package/dist/client/client/theme/SearchBar/fetchIndexes.js +2 -2
- package/dist/client/client/theme/SearchPage/SearchPage.jsx +8 -7
- package/dist/client/client/utils/__mocks__/proxiedGenerated.js +2 -1
- package/dist/server/server/index.js +2 -2
- package/dist/server/server/utils/generate.js +15 -2
- package/dist/server/server/utils/postBuildFactory.js +2 -2
- package/dist/server/server/utils/validateOptions.js +2 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,28 @@
|
|
|
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.30.2](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.30.1...v0.30.2) (2022-07-23)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* remove useDocsPreferredVersion error log entirely ([56f5ab5](https://github.com/easyops-cn/docusaurus-search-local/commit/56f5ab51a77f682c565d357bcbf7a37567c2b21e))
|
|
11
|
+
* use debug instead of console.error for useDocsPreferredVersion message ([3a09e39](https://github.com/easyops-cn/docusaurus-search-local/commit/3a09e39ef569a9dd1d99b1e251fdc79f909cff0f))
|
|
12
|
+
|
|
13
|
+
## [0.30.1](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.30.0...v0.30.1) (2022-07-22)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* fix building error when docs disabled ([07b1724](https://github.com/easyops-cn/docusaurus-search-local/commit/07b17245ff526783dfc1469de91928d5a64bb909))
|
|
19
|
+
|
|
20
|
+
## [0.30.0](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.29.4...v0.30.0) (2022-07-22)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Features
|
|
24
|
+
|
|
25
|
+
* support saving hash in filename instead of query ([4930a88](https://github.com/easyops-cn/docusaurus-search-local/commit/4930a88779813ffcaa932a56f786066f969aff6e)), closes [#171](https://github.com/easyops-cn/docusaurus-search-local/issues/171)
|
|
26
|
+
|
|
5
27
|
## [0.29.4](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.29.3...v0.29.4) (2022-07-22)
|
|
6
28
|
|
|
7
29
|
|
|
@@ -10,7 +10,7 @@ import { fetchIndexes } from "./fetchIndexes";
|
|
|
10
10
|
import { SearchSourceFactory } from "../../utils/SearchSourceFactory";
|
|
11
11
|
import { SuggestionTemplate } from "./SuggestionTemplate";
|
|
12
12
|
import { EmptyTemplate } from "./EmptyTemplate";
|
|
13
|
-
import { searchResultLimits, Mark, searchBarShortcut, searchBarShortcutHint, docsPluginIdForPreferredVersion, } from "../../utils/proxiedGenerated";
|
|
13
|
+
import { searchResultLimits, Mark, searchBarShortcut, searchBarShortcutHint, docsPluginIdForPreferredVersion, indexDocs, } from "../../utils/proxiedGenerated";
|
|
14
14
|
import LoadingRing from "../LoadingRing/LoadingRing";
|
|
15
15
|
import styles from "./SearchBar.module.css";
|
|
16
16
|
async function fetchAutoCompleteJS() {
|
|
@@ -47,12 +47,13 @@ export default function SearchBar({ handleSearchBarToggle, }) {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
catch (e) {
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
if (indexDocs) {
|
|
51
|
+
if (e instanceof ReactContextError) {
|
|
52
|
+
/* ignore, happens when website doesn't use versions */
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
throw e;
|
|
56
|
+
}
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
const history = useHistory();
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import lunr from "lunr";
|
|
2
|
-
import {
|
|
2
|
+
import { searchIndexUrl } from "../../utils/proxiedGenerated";
|
|
3
3
|
export async function fetchIndexes(baseUrl) {
|
|
4
4
|
if (process.env.NODE_ENV === "production") {
|
|
5
|
-
const json = (await (await fetch(`${baseUrl}
|
|
5
|
+
const json = (await (await fetch(`${baseUrl}${searchIndexUrl}`)).json());
|
|
6
6
|
const wrappedIndexes = json.map(({ documents, index }, type) => ({
|
|
7
7
|
type: type,
|
|
8
8
|
documents,
|
|
@@ -14,7 +14,7 @@ import { highlightStemmed } from "../../utils/highlightStemmed";
|
|
|
14
14
|
import { getStemmedPositions } from "../../utils/getStemmedPositions";
|
|
15
15
|
import LoadingRing from "../LoadingRing/LoadingRing";
|
|
16
16
|
import { concatDocumentPath } from "../../utils/concatDocumentPath";
|
|
17
|
-
import { docsPluginIdForPreferredVersion } from "../../utils/proxiedGenerated";
|
|
17
|
+
import { docsPluginIdForPreferredVersion, indexDocs, } from "../../utils/proxiedGenerated";
|
|
18
18
|
import styles from "./SearchPage.module.css";
|
|
19
19
|
export default function SearchPage() {
|
|
20
20
|
return (<Layout>
|
|
@@ -38,12 +38,13 @@ function SearchPageContent() {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
catch (e) {
|
|
41
|
-
if (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
if (indexDocs) {
|
|
42
|
+
if (e instanceof ReactContextError) {
|
|
43
|
+
/* ignore, happens when website doesn't use versions */
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
throw e;
|
|
47
|
+
}
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
50
|
const { selectMessage } = usePluralForm();
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
export let language = ["en", "zh"];
|
|
2
2
|
export let removeDefaultStopWordFilter = false;
|
|
3
3
|
export let removeDefaultStemmer = false;
|
|
4
|
-
export const
|
|
4
|
+
export const searchIndexUrl = "search-index.json?_=abc";
|
|
5
5
|
export const searchResultLimits = 8;
|
|
6
6
|
export const searchResultContextMaxLength = 50;
|
|
7
7
|
export const explicitSearchResultPath = false;
|
|
8
8
|
export const docsPluginIdForPreferredVersion = undefined;
|
|
9
|
+
export const indexDocs = true;
|
|
9
10
|
export function __setLanguage(value) {
|
|
10
11
|
language = value;
|
|
11
12
|
}
|
|
@@ -14,7 +14,7 @@ function DocusaurusSearchLocalPlugin(context, options) {
|
|
|
14
14
|
const config = (0, processPluginOptions_1.processPluginOptions)(options, context.siteDir);
|
|
15
15
|
const dir = path_1.default.join(context.generatedFilesDir, PLUGIN_NAME, "default");
|
|
16
16
|
fs_extra_1.default.ensureDirSync(dir);
|
|
17
|
-
(0, generate_1.generate)(config, dir);
|
|
17
|
+
const searchIndexFilename = (0, generate_1.generate)(config, dir);
|
|
18
18
|
const themePath = path_1.default.resolve(__dirname, "../../client/client/theme");
|
|
19
19
|
const pagePath = path_1.default.join(themePath, "SearchPage/index.js");
|
|
20
20
|
return {
|
|
@@ -22,7 +22,7 @@ function DocusaurusSearchLocalPlugin(context, options) {
|
|
|
22
22
|
getThemePath() {
|
|
23
23
|
return themePath;
|
|
24
24
|
},
|
|
25
|
-
postBuild: (0, postBuildFactory_1.postBuildFactory)(config),
|
|
25
|
+
postBuild: (0, postBuildFactory_1.postBuildFactory)(config, searchIndexFilename),
|
|
26
26
|
getPathsToWatch() {
|
|
27
27
|
return [pagePath];
|
|
28
28
|
},
|
|
@@ -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, docsPluginIdForPreferredVersion, } = config;
|
|
9
|
+
const { language, removeDefaultStopWordFilter, removeDefaultStemmer, highlightSearchTermsOnTargetPage, searchResultLimits, searchResultContextMaxLength, explicitSearchResultPath, searchBarShortcut, searchBarShortcutHint, docsPluginIdForPreferredVersion, indexDocs, } = config;
|
|
10
10
|
const indexHash = (0, getIndexHash_1.getIndexHash)(config);
|
|
11
11
|
const contents = [
|
|
12
12
|
`import lunr from ${JSON.stringify(require.resolve("lunr"))};`,
|
|
@@ -35,7 +35,18 @@ function generate(config, dir) {
|
|
|
35
35
|
else {
|
|
36
36
|
contents.push("export const Mark = null;");
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
let searchIndexFilename = "search-index.json";
|
|
39
|
+
let searchIndexQuery = "";
|
|
40
|
+
if (indexHash) {
|
|
41
|
+
if (config.hashed === "filename") {
|
|
42
|
+
searchIndexFilename = `search-index-${indexHash}.json`;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
searchIndexQuery = `?_=${indexHash}`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const searchIndexUrl = searchIndexFilename + searchIndexQuery;
|
|
49
|
+
contents.push(`export const searchIndexUrl = ${JSON.stringify(searchIndexUrl)};`);
|
|
39
50
|
contents.push(`export const searchResultLimits = ${JSON.stringify(searchResultLimits)};`, `export const searchResultContextMaxLength = ${JSON.stringify(searchResultContextMaxLength)};`);
|
|
40
51
|
contents.push(`export const explicitSearchResultPath = ${JSON.stringify(explicitSearchResultPath)};`);
|
|
41
52
|
contents.push(`export const searchBarShortcut = ${JSON.stringify(searchBarShortcut)};`);
|
|
@@ -43,6 +54,8 @@ function generate(config, dir) {
|
|
|
43
54
|
contents.push(`export const docsPluginIdForPreferredVersion = ${docsPluginIdForPreferredVersion === undefined
|
|
44
55
|
? "undefined"
|
|
45
56
|
: JSON.stringify(docsPluginIdForPreferredVersion)};`);
|
|
57
|
+
contents.push(`export const indexDocs = ${JSON.stringify(indexDocs)};`);
|
|
46
58
|
fs_1.default.writeFileSync(path_1.default.join(dir, "generated.js"), contents.join("\n"));
|
|
59
|
+
return searchIndexFilename;
|
|
47
60
|
}
|
|
48
61
|
exports.generate = generate;
|
|
@@ -10,7 +10,7 @@ const debug_1 = require("./debug");
|
|
|
10
10
|
const processDocInfos_1 = require("./processDocInfos");
|
|
11
11
|
const scanDocuments_1 = require("./scanDocuments");
|
|
12
12
|
const writeFileAsync = util_1.default.promisify(fs_1.default.writeFile);
|
|
13
|
-
function postBuildFactory(config) {
|
|
13
|
+
function postBuildFactory(config, searchIndexFilename) {
|
|
14
14
|
return function postBuild(buildData) {
|
|
15
15
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
16
16
|
(0, debug_1.debugInfo)("gathering documents");
|
|
@@ -22,7 +22,7 @@ function postBuildFactory(config) {
|
|
|
22
22
|
(0, debug_1.debugInfo)("building index");
|
|
23
23
|
const searchIndex = (0, buildIndex_1.buildIndex)(allDocuments, config);
|
|
24
24
|
(0, debug_1.debugInfo)("writing index to disk");
|
|
25
|
-
yield writeFileAsync(path_1.default.join(versionData.outDir,
|
|
25
|
+
yield writeFileAsync(path_1.default.join(versionData.outDir, searchIndexFilename), JSON.stringify(searchIndex), { encoding: "utf8" });
|
|
26
26
|
(0, debug_1.debugInfo)("index written to disk successfully!");
|
|
27
27
|
}
|
|
28
28
|
});
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.validateOptions = void 0;
|
|
4
4
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
5
5
|
const isStringOrArrayOfStrings = utils_validation_1.Joi.alternatives().try(utils_validation_1.Joi.string(), utils_validation_1.Joi.array().items(utils_validation_1.Joi.string()));
|
|
6
|
+
const isBooleanOrString = utils_validation_1.Joi.alternatives().try(utils_validation_1.Joi.boolean(), utils_validation_1.Joi.string());
|
|
6
7
|
const isArrayOfStringsOrRegExpsOrStringOrRegExp = utils_validation_1.Joi.alternatives().try(utils_validation_1.Joi.array().items(utils_validation_1.Joi.alternatives().try(utils_validation_1.Joi.string(), utils_validation_1.Joi.object().regex())), utils_validation_1.Joi.string(), utils_validation_1.Joi.object().regex());
|
|
7
8
|
const schema = utils_validation_1.Joi.object({
|
|
8
9
|
indexDocs: utils_validation_1.Joi.boolean().default(true),
|
|
@@ -11,7 +12,7 @@ const schema = utils_validation_1.Joi.object({
|
|
|
11
12
|
docsRouteBasePath: isStringOrArrayOfStrings.default(["docs"]),
|
|
12
13
|
blogRouteBasePath: isStringOrArrayOfStrings.default(["blog"]),
|
|
13
14
|
language: isStringOrArrayOfStrings.default(["en"]),
|
|
14
|
-
hashed:
|
|
15
|
+
hashed: isBooleanOrString.default(false),
|
|
15
16
|
docsDir: isStringOrArrayOfStrings.default(["docs"]),
|
|
16
17
|
blogDir: isStringOrArrayOfStrings.default(["blog"]),
|
|
17
18
|
removeDefaultStopWordFilter: utils_validation_1.Joi.boolean().default(false),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easyops-cn/docusaurus-search-local",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.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",
|