@easyops-cn/docusaurus-search-local 0.38.0 → 0.38.1

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.38.1](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.38.0...v0.38.1) (2023-11-28)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * compile to commonjs ([b8dc37d](https://github.com/easyops-cn/docusaurus-search-local/commit/b8dc37d1ea89014ad226883b5cf65cfec92d937a)), closes [#370](https://github.com/easyops-cn/docusaurus-search-local/issues/370)
11
+
5
12
  ## [0.38.0](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.37.5...v0.38.0) (2023-11-24)
6
13
 
7
14
 
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,47 +1,50 @@
1
- import { __awaiter } from "tslib";
2
- import path from "path";
3
- import fs from "fs-extra";
4
- import { normalizeUrl } from "@docusaurus/utils";
5
- import { codeTranslationLocalesToTry } from "@docusaurus/theme-translations";
6
- import { processPluginOptions } from "./utils/processPluginOptions";
7
- import { postBuildFactory } from "./utils/postBuildFactory";
8
- import { generate } from "./utils/generate";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateOptions = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const path_1 = tslib_1.__importDefault(require("path"));
6
+ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
7
+ const utils_1 = require("@docusaurus/utils");
8
+ const theme_translations_1 = require("@docusaurus/theme-translations");
9
+ const processPluginOptions_1 = require("./utils/processPluginOptions");
10
+ const postBuildFactory_1 = require("./utils/postBuildFactory");
11
+ const generate_1 = require("./utils/generate");
9
12
  const PLUGIN_NAME = "@easyops-cn/docusaurus-search-local";
10
- export default function DocusaurusSearchLocalPlugin(context, options) {
11
- const config = processPluginOptions(options, context);
12
- const dir = path.join(context.generatedFilesDir, PLUGIN_NAME, "default");
13
- fs.ensureDirSync(dir);
14
- const searchIndexFilename = generate(config, dir);
15
- const themePath = path.resolve(__dirname, "../../client/client/theme");
16
- const pagePath = path.join(themePath, "SearchPage/index.js");
13
+ function DocusaurusSearchLocalPlugin(context, options) {
14
+ const config = (0, processPluginOptions_1.processPluginOptions)(options, context);
15
+ const dir = path_1.default.join(context.generatedFilesDir, PLUGIN_NAME, "default");
16
+ fs_extra_1.default.ensureDirSync(dir);
17
+ const searchIndexFilename = (0, generate_1.generate)(config, dir);
18
+ const themePath = path_1.default.resolve(__dirname, "../../client/client/theme");
19
+ const pagePath = path_1.default.join(themePath, "SearchPage/index.js");
17
20
  return {
18
21
  name: PLUGIN_NAME,
19
22
  getThemePath() {
20
23
  return themePath;
21
24
  },
22
- postBuild: postBuildFactory(config, searchIndexFilename),
25
+ postBuild: (0, postBuildFactory_1.postBuildFactory)(config, searchIndexFilename),
23
26
  getPathsToWatch() {
24
27
  return [pagePath];
25
28
  },
26
29
  getDefaultCodeTranslationMessages() {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- const dirPath = path.join(__dirname, "../../locales");
29
- const localesToTry = codeTranslationLocalesToTry(context.i18n.currentLocale);
30
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
31
+ const dirPath = path_1.default.join(__dirname, "../../locales");
32
+ const localesToTry = (0, theme_translations_1.codeTranslationLocalesToTry)(context.i18n.currentLocale);
30
33
  // Return the content of the first file that match
31
34
  // fr_FR.json => fr.json => nothing
32
35
  for (const locale of localesToTry) {
33
- const filePath = path.resolve(dirPath, `${locale}.json`);
34
- if (yield fs.pathExists(filePath)) {
35
- return fs.readJSON(filePath);
36
+ const filePath = path_1.default.resolve(dirPath, `${locale}.json`);
37
+ if (yield fs_extra_1.default.pathExists(filePath)) {
38
+ return fs_extra_1.default.readJSON(filePath);
36
39
  }
37
40
  }
38
41
  return {};
39
42
  });
40
43
  },
41
44
  contentLoaded({ actions: { addRoute } }) {
42
- return __awaiter(this, void 0, void 0, function* () {
45
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
43
46
  addRoute({
44
- path: normalizeUrl([context.baseUrl, "search"]),
47
+ path: (0, utils_1.normalizeUrl)([context.baseUrl, "search"]),
45
48
  component: "@theme/SearchPage",
46
49
  exact: true,
47
50
  });
@@ -49,4 +52,6 @@ export default function DocusaurusSearchLocalPlugin(context, options) {
49
52
  },
50
53
  };
51
54
  }
52
- export { validateOptions } from "./utils/validateOptions";
55
+ exports.default = DocusaurusSearchLocalPlugin;
56
+ var validateOptions_1 = require("./utils/validateOptions");
57
+ Object.defineProperty(exports, "validateOptions", { enumerable: true, get: function () { return validateOptions_1.validateOptions; } });
@@ -1,43 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildIndex = void 0;
4
+ const tslib_1 = require("tslib");
1
5
  /* eslint @typescript-eslint/no-var-requires: 0 */
2
- import lunr from "lunr";
3
- export function buildIndex(allDocuments, { language, removeDefaultStopWordFilter, removeDefaultStemmer, zhUserDict, zhUserDictPath, }) {
6
+ const lunr_1 = tslib_1.__importDefault(require("lunr"));
7
+ function buildIndex(allDocuments, { language, removeDefaultStopWordFilter, removeDefaultStemmer, zhUserDict, zhUserDictPath, }) {
4
8
  if (language.length > 1 || language.some((item) => item !== "en")) {
5
- require("lunr-languages/lunr.stemmer.support")(lunr);
9
+ require("lunr-languages/lunr.stemmer.support")(lunr_1.default);
6
10
  }
7
11
  if (language.includes("ja") || language.includes("jp")) {
8
- require("lunr-languages/tinyseg")(lunr);
12
+ require("lunr-languages/tinyseg")(lunr_1.default);
9
13
  }
10
14
  for (const lang of language.filter((item) => item !== "en" && item !== "zh")) {
11
- require(`lunr-languages/lunr.${lang}`)(lunr);
15
+ require(`lunr-languages/lunr.${lang}`)(lunr_1.default);
12
16
  }
13
17
  if (language.includes("zh")) {
14
18
  const { tokenizer, loadUserDict } = require("./tokenizer");
15
19
  loadUserDict(zhUserDict, zhUserDictPath);
16
- require("../../shared/lunrLanguageZh").lunrLanguageZh(lunr, tokenizer);
20
+ require("../../shared/lunrLanguageZh").lunrLanguageZh(lunr_1.default, tokenizer);
17
21
  }
18
22
  if (language.length > 1) {
19
- require("lunr-languages/lunr.multi")(lunr);
23
+ require("lunr-languages/lunr.multi")(lunr_1.default);
20
24
  }
21
25
  return allDocuments.map((documents) => ({
22
26
  documents,
23
- index: lunr(function () {
27
+ index: (0, lunr_1.default)(function () {
24
28
  if (language.length > 1) {
25
- this.use(lunr.multiLanguage(...language));
29
+ this.use(lunr_1.default.multiLanguage(...language));
26
30
  }
27
31
  else if (language[0] !== "en") {
28
- this.use(lunr[language[0]]);
32
+ this.use(lunr_1.default[language[0]]);
29
33
  }
30
34
  if (removeDefaultStopWordFilter) {
31
35
  // Sometimes we need no English stop words,
32
36
  // since they are almost all programming code.
33
- this.pipeline.remove(lunr.stopWordFilter);
37
+ this.pipeline.remove(lunr_1.default.stopWordFilter);
34
38
  }
35
39
  if (removeDefaultStemmer) {
36
- this.pipeline.remove(lunr.stemmer);
40
+ this.pipeline.remove(lunr_1.default.stemmer);
37
41
  }
38
42
  // Override tokenizer when language `zh` is enabled.
39
43
  if (language.includes("zh")) {
40
- this.tokenizer = lunr.zh.tokenizer;
44
+ this.tokenizer = lunr_1.default.zh.tokenizer;
41
45
  }
42
46
  this.ref("i");
43
47
  this.field("t");
@@ -50,3 +54,4 @@ export function buildIndex(allDocuments, { language, removeDefaultStopWordFilter
50
54
  }),
51
55
  }));
52
56
  }
57
+ exports.buildIndex = buildIndex;
@@ -1,6 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cutWordByUnderscore = void 0;
1
4
  const splitRegExp = [/(_)([^_])/g, /([^_])(_)/g];
2
- export function cutWordByUnderscore(input) {
5
+ function cutWordByUnderscore(input) {
3
6
  return splitRegExp
4
7
  .reduce((carry, re) => carry.replace(re, "$1\0$2"), input)
5
8
  .split("\0");
6
9
  }
10
+ exports.cutWordByUnderscore = cutWordByUnderscore;
@@ -1,5 +1,9 @@
1
- import createDebug from "debug";
2
- const debug = createDebug("search-local");
3
- export const debugVerbose = debug.extend("verbose");
4
- export const debugInfo = debug.extend("info");
5
- export const debugWarn = debug.extend("warn");
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.debugWarn = exports.debugInfo = exports.debugVerbose = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const debug_1 = tslib_1.__importDefault(require("debug"));
6
+ const debug = (0, debug_1.default)("search-local");
7
+ exports.debugVerbose = debug.extend("verbose");
8
+ exports.debugInfo = debug.extend("info");
9
+ exports.debugWarn = debug.extend("warn");
@@ -1,9 +1,13 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import { getIndexHash } from "./getIndexHash";
4
- export function generate(config, dir) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generate = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ const path_1 = tslib_1.__importDefault(require("path"));
7
+ const getIndexHash_1 = require("./getIndexHash");
8
+ function generate(config, dir) {
5
9
  const { language, removeDefaultStopWordFilter, removeDefaultStemmer, highlightSearchTermsOnTargetPage, searchResultLimits, searchResultContextMaxLength, explicitSearchResultPath, searchBarShortcut, searchBarShortcutHint, searchBarPosition, docsPluginIdForPreferredVersion, indexDocs, searchContextByPaths, hideSearchBarWithNoSearchContext, useAllContextsWithNoSearchContext, } = config;
6
- const indexHash = getIndexHash(config);
10
+ const indexHash = (0, getIndexHash_1.getIndexHash)(config);
7
11
  const contents = [
8
12
  `import lunr from ${JSON.stringify(require.resolve("lunr"))};`,
9
13
  ];
@@ -57,6 +61,7 @@ export function generate(config, dir) {
57
61
  : null)};`);
58
62
  contents.push(`export const hideSearchBarWithNoSearchContext = ${JSON.stringify(!!hideSearchBarWithNoSearchContext)};`);
59
63
  contents.push(`export const useAllContextsWithNoSearchContext = ${JSON.stringify(!!useAllContextsWithNoSearchContext)};`);
60
- fs.writeFileSync(path.join(dir, "generated.js"), contents.join("\n"));
64
+ fs_1.default.writeFileSync(path_1.default.join(dir, "generated.js"), contents.join("\n"));
61
65
  return searchIndexFilename;
62
66
  }
67
+ exports.generate = generate;
@@ -1,3 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCondensedText = void 0;
1
4
  // We prepend and append whitespace for these tags.
2
5
  // https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
3
6
  const BLOCK_TAGS = new Set([
@@ -38,7 +41,7 @@ const BLOCK_TAGS = new Set([
38
41
  "td",
39
42
  "th",
40
43
  ]);
41
- export function getCondensedText(element, $) {
44
+ function getCondensedText(element, $) {
42
45
  const getText = (element) => {
43
46
  if (Array.isArray(element)) {
44
47
  return element.map((item) => getText(item)).join("");
@@ -60,3 +63,4 @@ export function getCondensedText(element, $) {
60
63
  };
61
64
  return getText(element).trim().replace(/\s+/g, " ");
62
65
  }
66
+ exports.getCondensedText = getCondensedText;
@@ -1,9 +1,13 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import crypto from "crypto";
4
- import klawSync from "klaw-sync";
5
- import { debugInfo } from "./debug";
6
- export function getIndexHash(config) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getIndexHash = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ const path_1 = tslib_1.__importDefault(require("path"));
7
+ const crypto_1 = tslib_1.__importDefault(require("crypto"));
8
+ const klaw_sync_1 = tslib_1.__importDefault(require("klaw-sync"));
9
+ const debug_1 = require("./debug");
10
+ function getIndexHash(config) {
7
11
  if (!config.hashed) {
8
12
  return null;
9
13
  }
@@ -11,14 +15,14 @@ export function getIndexHash(config) {
11
15
  const scanFiles = (flagField, dirField) => {
12
16
  if (config[flagField]) {
13
17
  for (const dir of config[dirField]) {
14
- if (!fs.existsSync(dir)) {
18
+ if (!fs_1.default.existsSync(dir)) {
15
19
  console.warn(`Warn: \`${dirField}\` doesn't exist: "${dir}".`);
16
20
  }
17
- else if (!fs.lstatSync(dir).isDirectory()) {
21
+ else if (!fs_1.default.lstatSync(dir).isDirectory()) {
18
22
  console.warn(`Warn: \`${dirField}\` is not a directory: "${dir}".`);
19
23
  }
20
24
  else {
21
- files.push(...klawSync(dir, {
25
+ files.push(...(0, klaw_sync_1.default)(dir, {
22
26
  nodir: true,
23
27
  filter: markdownFilter,
24
28
  traverseAll: true,
@@ -30,22 +34,23 @@ export function getIndexHash(config) {
30
34
  scanFiles("indexDocs", "docsDir");
31
35
  scanFiles("indexBlog", "blogDir");
32
36
  if (files.length > 0) {
33
- const md5sum = crypto.createHash("md5");
37
+ const md5sum = crypto_1.default.createHash("md5");
34
38
  // The version of this plugin should be counted in hash,
35
39
  // since the index maybe changed between versions.
36
40
  // eslint-disable-next-line @typescript-eslint/no-var-requires
37
- const pluginVersion = require(path.resolve(__dirname, "../../../../package.json")).version;
38
- debugInfo("using @easyops-cn/docusaurus-search-local v%s", pluginVersion);
41
+ const pluginVersion = require(path_1.default.resolve(__dirname, "../../../../package.json")).version;
42
+ (0, debug_1.debugInfo)("using @easyops-cn/docusaurus-search-local v%s", pluginVersion);
39
43
  md5sum.update(pluginVersion, "utf8");
40
44
  for (const item of files) {
41
- md5sum.update(fs.readFileSync(item.path));
45
+ md5sum.update(fs_1.default.readFileSync(item.path));
42
46
  }
43
47
  const indexHash = md5sum.digest("hex").substring(0, 8);
44
- debugInfo("the index hash is %j", indexHash);
48
+ (0, debug_1.debugInfo)("the index hash is %j", indexHash);
45
49
  return indexHash;
46
50
  }
47
51
  return null;
48
52
  }
53
+ exports.getIndexHash = getIndexHash;
49
54
  function markdownFilter(item) {
50
55
  return item.path.endsWith(".md") || item.path.endsWith(".mdx");
51
56
  }
@@ -1,9 +1,13 @@
1
- import cheerio from "cheerio";
2
- import { parseDocument } from "./parseDocument";
3
- import { parsePage } from "./parsePage";
4
- export function parse(html, type, url, { ignoreCssSelectors }) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parse = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const cheerio_1 = tslib_1.__importDefault(require("cheerio"));
6
+ const parseDocument_1 = require("./parseDocument");
7
+ const parsePage_1 = require("./parsePage");
8
+ function parse(html, type, url, { ignoreCssSelectors }) {
5
9
  var _a;
6
- const $ = cheerio.load(html);
10
+ const $ = cheerio_1.default.load(html);
7
11
  const robotsMeta = $('meta[name="robots"]');
8
12
  if ((_a = robotsMeta.attr("content")) === null || _a === void 0 ? void 0 : _a.includes("noindex")) {
9
13
  // Unlisted content
@@ -23,7 +27,8 @@ export function parse(html, type, url, { ignoreCssSelectors }) {
23
27
  .remove();
24
28
  }
25
29
  if (type === "page") {
26
- return parsePage($, url);
30
+ return (0, parsePage_1.parsePage)($, url);
27
31
  }
28
- return parseDocument($);
32
+ return (0, parseDocument_1.parseDocument)($);
29
33
  }
34
+ exports.parse = parse;
@@ -1,8 +1,11 @@
1
- import { blogPostContainerID } from "@docusaurus/utils-common";
2
- import { getCondensedText } from "./getCondensedText";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseDocument = void 0;
4
+ const utils_common_1 = require("@docusaurus/utils-common");
5
+ const getCondensedText_1 = require("./getCondensedText");
3
6
  const HEADINGS = "h1, h2, h3";
4
7
  // const SUB_HEADINGS = "h2, h3";
5
- export function parseDocument($) {
8
+ function parseDocument($) {
6
9
  const $pageTitle = $("article h1").first();
7
10
  const pageTitle = $pageTitle.text();
8
11
  const sections = [];
@@ -43,7 +46,7 @@ export function parseDocument($) {
43
46
  else {
44
47
  $firstElement = $h;
45
48
  }
46
- const blogPost = $(`#${blogPostContainerID}`);
49
+ const blogPost = $(`#${utils_common_1.blogPostContainerID}`);
47
50
  if (blogPost.length) {
48
51
  // Simplify blog post.
49
52
  $firstElement = blogPost.children().first();
@@ -72,7 +75,7 @@ export function parseDocument($) {
72
75
  else {
73
76
  $sectionElements = $h.nextUntil(HEADINGS);
74
77
  }
75
- const content = getCondensedText($sectionElements.get(), $);
78
+ const content = (0, getCondensedText_1.getCondensedText)($sectionElements.get(), $);
76
79
  sections.push({
77
80
  title,
78
81
  hash,
@@ -81,3 +84,4 @@ export function parseDocument($) {
81
84
  });
82
85
  return { pageTitle, sections, breadcrumb };
83
86
  }
87
+ exports.parseDocument = parseDocument;
@@ -1,6 +1,9 @@
1
- import { debugWarn } from "./debug";
2
- import { getCondensedText } from "./getCondensedText";
3
- export function parsePage($, url) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parsePage = void 0;
4
+ const debug_1 = require("./debug");
5
+ const getCondensedText_1 = require("./getCondensedText");
6
+ function parsePage($, url) {
4
7
  $("a[aria-hidden=true]").remove();
5
8
  let $pageTitle = $("h1").first();
6
9
  if ($pageTitle.length === 0) {
@@ -9,7 +12,7 @@ export function parsePage($, url) {
9
12
  const pageTitle = $pageTitle.text();
10
13
  const $main = $("main");
11
14
  if ($main.length === 0) {
12
- debugWarn("page has no <main>, therefore no content was indexed for this page %o", url);
15
+ (0, debug_1.debugWarn)("page has no <main>, therefore no content was indexed for this page %o", url);
13
16
  }
14
17
  return {
15
18
  pageTitle,
@@ -17,9 +20,10 @@ export function parsePage($, url) {
17
20
  {
18
21
  title: pageTitle,
19
22
  hash: "",
20
- content: $main.length > 0 ? getCondensedText($main.get(0), $).trim() : "",
23
+ content: $main.length > 0 ? (0, getCondensedText_1.getCondensedText)($main.get(0), $).trim() : "",
21
24
  },
22
25
  ],
23
26
  breadcrumb: [],
24
27
  };
25
28
  }
29
+ exports.parsePage = parsePage;
@@ -1,22 +1,25 @@
1
- import { __awaiter } from "tslib";
2
- import fs from "fs";
3
- import path from "path";
4
- import util from "util";
5
- import { buildIndex } from "./buildIndex";
6
- import { debugInfo } from "./debug";
7
- import { processDocInfos } from "./processDocInfos";
8
- import { scanDocuments } from "./scanDocuments";
9
- const writeFileAsync = util.promisify(fs.writeFile);
10
- export function postBuildFactory(config, searchIndexFilename) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.postBuildFactory = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ const path_1 = tslib_1.__importDefault(require("path"));
7
+ const util_1 = tslib_1.__importDefault(require("util"));
8
+ const buildIndex_1 = require("./buildIndex");
9
+ const debug_1 = require("./debug");
10
+ const processDocInfos_1 = require("./processDocInfos");
11
+ const scanDocuments_1 = require("./scanDocuments");
12
+ const writeFileAsync = util_1.default.promisify(fs_1.default.writeFile);
13
+ function postBuildFactory(config, searchIndexFilename) {
11
14
  return function postBuild(buildData) {
12
- return __awaiter(this, void 0, void 0, function* () {
13
- debugInfo("gathering documents");
14
- const data = processDocInfos(buildData, config);
15
- debugInfo("parsing documents");
15
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
16
+ (0, debug_1.debugInfo)("gathering documents");
17
+ const data = (0, processDocInfos_1.processDocInfos)(buildData, config);
18
+ (0, debug_1.debugInfo)("parsing documents");
16
19
  for (const versionData of data) {
17
20
  // Give every index entry a unique id so that the index does not need to store long URLs.
18
- const allDocuments = yield scanDocuments(versionData.paths, config);
19
- debugInfo("building index");
21
+ const allDocuments = yield (0, scanDocuments_1.scanDocuments)(versionData.paths, config);
22
+ (0, debug_1.debugInfo)("building index");
20
23
  const docsByDirMap = new Map();
21
24
  const { searchContextByPaths, hideSearchBarWithNoSearchContext, useAllContextsWithNoSearchContext, } = config;
22
25
  if (searchContextByPaths) {
@@ -63,12 +66,13 @@ export function postBuildFactory(config, searchIndexFilename) {
63
66
  docsByDirMap.set("", allDocuments);
64
67
  }
65
68
  for (const [k, allDocs] of docsByDirMap) {
66
- const searchIndex = buildIndex(allDocs, config);
67
- debugInfo(`writing index (/${k}) to disk`);
68
- yield writeFileAsync(path.join(versionData.outDir, searchIndexFilename.replace("{dir}", k === "" ? "" : `-${k.replace(/\//g, "-")}`)), JSON.stringify(searchIndex), { encoding: "utf8" });
69
- debugInfo(`index (/${k}) written to disk successfully!`);
69
+ const searchIndex = (0, buildIndex_1.buildIndex)(allDocs, config);
70
+ (0, debug_1.debugInfo)(`writing index (/${k}) to disk`);
71
+ yield writeFileAsync(path_1.default.join(versionData.outDir, searchIndexFilename.replace("{dir}", k === "" ? "" : `-${k.replace(/\//g, "-")}`)), JSON.stringify(searchIndex), { encoding: "utf8" });
72
+ (0, debug_1.debugInfo)(`index (/${k}) written to disk successfully!`);
70
73
  }
71
74
  }
72
75
  });
73
76
  };
74
77
  }
78
+ exports.postBuildFactory = postBuildFactory;
@@ -1,13 +1,17 @@
1
- import path from "path";
2
- import { debugVerbose } from "./debug";
3
- export function processDocInfos({ routesPaths, outDir, baseUrl, siteConfig, plugins }, { indexDocs, indexBlog, indexPages, docsRouteBasePath, blogRouteBasePath, ignoreFiles, }) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processDocInfos = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const path_1 = tslib_1.__importDefault(require("path"));
6
+ const debug_1 = require("./debug");
7
+ function processDocInfos({ routesPaths, outDir, baseUrl, siteConfig, plugins }, { indexDocs, indexBlog, indexPages, docsRouteBasePath, blogRouteBasePath, ignoreFiles, }) {
4
8
  const emptySet = new Set();
5
9
  let versionData = new Map([[outDir, emptySet]]);
6
10
  if (plugins) {
7
11
  // Handle docs multi-instance.
8
12
  const docsPlugins = plugins.filter((item) => item.name === "docusaurus-plugin-content-docs");
9
13
  const loadedVersions = docsPlugins.flatMap((plugin) => plugin.content.loadedVersions);
10
- debugVerbose("loadedVersions:", loadedVersions);
14
+ (0, debug_1.debugVerbose)("loadedVersions:", loadedVersions);
11
15
  if (loadedVersions.length > 0) {
12
16
  versionData = new Map();
13
17
  for (const loadedVersion of loadedVersions) {
@@ -15,7 +19,7 @@ export function processDocInfos({ routesPaths, outDir, baseUrl, siteConfig, plug
15
19
  let versionOutDir = outDir;
16
20
  // The last versions search-index should always be placed in the root since it is the one used from non-docs pages
17
21
  if (!loadedVersion.isLast) {
18
- versionOutDir = path.join(outDir, ...route.split("/").filter((i) => i));
22
+ versionOutDir = path_1.default.join(outDir, ...route.split("/").filter((i) => i));
19
23
  }
20
24
  // Merge docs which share the same `versionOutDir`.
21
25
  let docs = versionData.get(versionOutDir);
@@ -27,7 +31,7 @@ export function processDocInfos({ routesPaths, outDir, baseUrl, siteConfig, plug
27
31
  docs.add(doc.permalink);
28
32
  }
29
33
  }
30
- debugVerbose("versionData:", versionData);
34
+ (0, debug_1.debugVerbose)("versionData:", versionData);
31
35
  }
32
36
  }
33
37
  // Create a list of files to index per document version. This will always include all pages and blogs.
@@ -59,7 +63,7 @@ export function processDocInfos({ routesPaths, outDir, baseUrl, siteConfig, plug
59
63
  if (indexBlog &&
60
64
  blogRouteBasePath.some((basePath) => isSameOrSubRoute(route, basePath))) {
61
65
  if (blogRouteBasePath.some((basePath) => isSameRoute(route, basePath) ||
62
- isSameOrSubRoute(route, path.posix.join(basePath, "tags")))) {
66
+ isSameOrSubRoute(route, path_1.default.posix.join(basePath, "tags")))) {
63
67
  // Do not index list of blog posts and tags filter pages
64
68
  return;
65
69
  }
@@ -96,7 +100,7 @@ export function processDocInfos({ routesPaths, outDir, baseUrl, siteConfig, plug
96
100
  })
97
101
  .filter(Boolean)
98
102
  .map(({ route, url, type }) => ({
99
- filePath: path.join(outDir, siteConfig.trailingSlash === false && route != ""
103
+ filePath: path_1.default.join(outDir, siteConfig.trailingSlash === false && route != ""
100
104
  ? `${route}.html`
101
105
  : `${route}/index.html`),
102
106
  url,
@@ -108,6 +112,7 @@ export function processDocInfos({ routesPaths, outDir, baseUrl, siteConfig, plug
108
112
  }
109
113
  return result;
110
114
  }
115
+ exports.processDocInfos = processDocInfos;
111
116
  function isSameRoute(routeA, routeB) {
112
117
  return addTrailingSlash(routeA) === addTrailingSlash(routeB);
113
118
  }
@@ -1,5 +1,9 @@
1
- import path from "path";
2
- export function processPluginOptions(options, { siteDir, siteConfig: { themeConfig }, }) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processPluginOptions = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const path_1 = tslib_1.__importDefault(require("path"));
6
+ function processPluginOptions(options, { siteDir, siteConfig: { themeConfig }, }) {
3
7
  var _a, _b;
4
8
  const config = Object.assign({}, options);
5
9
  ensureArray(config, "docsRouteBasePath");
@@ -11,8 +15,8 @@ export function processPluginOptions(options, { siteDir, siteConfig: { themeConf
11
15
  ensureArray(config, "ignoreCssSelectors");
12
16
  config.docsRouteBasePath = config.docsRouteBasePath.map((basePath) => basePath.replace(/^\//, ""));
13
17
  config.blogRouteBasePath = config.blogRouteBasePath.map((basePath) => basePath.replace(/^\//, ""));
14
- config.docsDir = config.docsDir.map((dir) => path.resolve(siteDir, dir));
15
- config.blogDir = config.blogDir.map((dir) => path.resolve(siteDir, dir));
18
+ config.docsDir = config.docsDir.map((dir) => path_1.default.resolve(siteDir, dir));
19
+ config.blogDir = config.blogDir.map((dir) => path_1.default.resolve(siteDir, dir));
16
20
  if (config.searchBarPosition === "auto") {
17
21
  const search = (_b = (_a = themeConfig.navbar) === null || _a === void 0 ? void 0 : _a.items) === null || _b === void 0 ? void 0 : _b.find((item) => item.type === "search");
18
22
  config.searchBarPosition =
@@ -20,6 +24,7 @@ export function processPluginOptions(options, { siteDir, siteConfig: { themeConf
20
24
  }
21
25
  return config;
22
26
  }
27
+ exports.processPluginOptions = processPluginOptions;
23
28
  function ensureArray(object, key) {
24
29
  if (!Array.isArray(object[key])) {
25
30
  object[key] = [object[key]];
@@ -1,24 +1,27 @@
1
- import { __awaiter } from "tslib";
2
- import fs from "fs";
3
- import path from "path";
4
- import util from "util";
5
- import { parse } from "./parse";
6
- import { debugVerbose } from "./debug";
7
- const readFileAsync = util.promisify(fs.readFile);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.scanDocuments = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ const path_1 = tslib_1.__importDefault(require("path"));
7
+ const util_1 = tslib_1.__importDefault(require("util"));
8
+ const parse_1 = require("./parse");
9
+ const debug_1 = require("./debug");
10
+ const readFileAsync = util_1.default.promisify(fs_1.default.readFile);
8
11
  let nextDocId = 0;
9
12
  const getNextDocId = () => {
10
13
  return (nextDocId += 1);
11
14
  };
12
- export function scanDocuments(DocInfoWithFilePathList, config) {
13
- return __awaiter(this, void 0, void 0, function* () {
15
+ function scanDocuments(DocInfoWithFilePathList, config) {
16
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
14
17
  const titleDocuments = [];
15
18
  const headingDocuments = [];
16
19
  const contentDocuments = [];
17
20
  const allDocuments = [titleDocuments, headingDocuments, contentDocuments];
18
- yield Promise.all(DocInfoWithFilePathList.map(({ filePath, url, type }) => __awaiter(this, void 0, void 0, function* () {
19
- debugVerbose(`parsing %s file %o of %o`, type, path.relative(process.cwd(), filePath), url);
21
+ yield Promise.all(DocInfoWithFilePathList.map(({ filePath, url, type }) => tslib_1.__awaiter(this, void 0, void 0, function* () {
22
+ (0, debug_1.debugVerbose)(`parsing %s file %o of %o`, type, path_1.default.relative(process.cwd(), filePath), url);
20
23
  const html = yield readFileAsync(filePath, { encoding: "utf8" });
21
- const parsed = parse(html, type, url, config);
24
+ const parsed = (0, parse_1.parse)(html, type, url, config);
22
25
  if (!parsed) {
23
26
  // Unlisted content
24
27
  return;
@@ -56,3 +59,4 @@ export function scanDocuments(DocInfoWithFilePathList, config) {
56
59
  return allDocuments;
57
60
  });
58
61
  }
62
+ exports.scanDocuments = scanDocuments;
@@ -1,29 +1,34 @@
1
- import fs from "fs";
2
- import lunr from "lunr";
3
- import jieba from "@node-rs/jieba";
4
- import { cutWordByUnderscore } from "./cutWordByUnderscore";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tokenizer = exports.loadUserDict = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ const lunr_1 = tslib_1.__importDefault(require("lunr"));
7
+ const jieba_1 = tslib_1.__importDefault(require("@node-rs/jieba"));
8
+ const cutWordByUnderscore_1 = require("./cutWordByUnderscore");
5
9
  // https://zhuanlan.zhihu.com/p/33335629
6
10
  const RegExpConsecutiveWord = /\w+|\p{Unified_Ideograph}+/u;
7
11
  let userDictLoaded = false;
8
- export function loadUserDict(zhUserDict, zhUserDictPath) {
12
+ function loadUserDict(zhUserDict, zhUserDictPath) {
9
13
  if (userDictLoaded) {
10
14
  return;
11
15
  }
12
16
  if (zhUserDict) {
13
- jieba.loadDict(Buffer.from(zhUserDict));
17
+ jieba_1.default.loadDict(Buffer.from(zhUserDict));
14
18
  }
15
19
  else if (zhUserDictPath) {
16
- jieba.loadDict(fs.readFileSync(zhUserDictPath));
20
+ jieba_1.default.loadDict(fs_1.default.readFileSync(zhUserDictPath));
17
21
  }
18
22
  userDictLoaded = true;
19
23
  }
20
- export function tokenizer(input, metadata) {
24
+ exports.loadUserDict = loadUserDict;
25
+ function tokenizer(input, metadata) {
21
26
  if (input == null) {
22
27
  return [];
23
28
  }
24
29
  if (Array.isArray(input)) {
25
30
  return input.map(function (t) {
26
- return new lunr.Token(lunr.utils.asString(t).toLowerCase(), lunr.utils.clone(metadata));
31
+ return new lunr_1.default.Token(lunr_1.default.utils.asString(t).toLowerCase(), lunr_1.default.utils.clone(metadata));
27
32
  });
28
33
  }
29
34
  const content = input.toString().toLowerCase();
@@ -38,14 +43,14 @@ export function tokenizer(input, metadata) {
38
43
  const word = match[0];
39
44
  start += match.index;
40
45
  if (/\w/.test(word[0])) {
41
- tokens.push(new lunr.Token(word, Object.assign(Object.assign({}, lunr.utils.clone(metadata)), { position: [start, word.length], index: tokens.length })));
46
+ tokens.push(new lunr_1.default.Token(word, Object.assign(Object.assign({}, lunr_1.default.utils.clone(metadata)), { position: [start, word.length], index: tokens.length })));
42
47
  // Try to cut `api_gateway` to `api` and `gateway`.
43
- const subWords = cutWordByUnderscore(word);
48
+ const subWords = (0, cutWordByUnderscore_1.cutWordByUnderscore)(word);
44
49
  if (subWords.length > 1) {
45
50
  let i = 0;
46
51
  for (const subWord of subWords) {
47
52
  if (subWord[0] !== "_") {
48
- tokens.push(new lunr.Token(subWord, Object.assign(Object.assign({}, lunr.utils.clone(metadata)), { position: [start + i, subWord.length], index: tokens.length })));
53
+ tokens.push(new lunr_1.default.Token(subWord, Object.assign(Object.assign({}, lunr_1.default.utils.clone(metadata)), { position: [start + i, subWord.length], index: tokens.length })));
49
54
  }
50
55
  i += subWord.length;
51
56
  }
@@ -53,8 +58,8 @@ export function tokenizer(input, metadata) {
53
58
  start += word.length;
54
59
  }
55
60
  else {
56
- for (const zhWord of jieba.cut(word)) {
57
- tokens.push(new lunr.Token(zhWord, Object.assign(Object.assign({}, lunr.utils.clone(metadata)), { position: [start, zhWord.length], index: tokens.length })));
61
+ for (const zhWord of jieba_1.default.cut(word)) {
62
+ tokens.push(new lunr_1.default.Token(zhWord, Object.assign(Object.assign({}, lunr_1.default.utils.clone(metadata)), { position: [start, zhWord.length], index: tokens.length })));
58
63
  start += zhWord.length;
59
64
  }
60
65
  }
@@ -62,3 +67,4 @@ export function tokenizer(input, metadata) {
62
67
  }
63
68
  return tokens;
64
69
  }
70
+ exports.tokenizer = tokenizer;
@@ -1,35 +1,39 @@
1
- import { Joi } from "@docusaurus/utils-validation";
2
- const isStringOrArrayOfStrings = Joi.alternatives().try(Joi.string(), Joi.array().items(Joi.string()));
3
- const isBooleanOrString = Joi.alternatives().try(Joi.boolean(), Joi.string());
4
- const isArrayOfStringsOrRegExpsOrStringOrRegExp = Joi.alternatives().try(Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.object().regex())), Joi.string(), Joi.object().regex());
5
- const schema = Joi.object({
6
- indexDocs: Joi.boolean().default(true),
7
- indexBlog: Joi.boolean().default(true),
8
- indexPages: Joi.boolean().default(false),
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateOptions = void 0;
4
+ const utils_validation_1 = require("@docusaurus/utils-validation");
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());
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());
8
+ const schema = utils_validation_1.Joi.object({
9
+ indexDocs: utils_validation_1.Joi.boolean().default(true),
10
+ indexBlog: utils_validation_1.Joi.boolean().default(true),
11
+ indexPages: utils_validation_1.Joi.boolean().default(false),
9
12
  docsRouteBasePath: isStringOrArrayOfStrings.default(["docs"]),
10
13
  blogRouteBasePath: isStringOrArrayOfStrings.default(["blog"]),
11
14
  language: isStringOrArrayOfStrings.default(["en"]),
12
15
  hashed: isBooleanOrString.default(false),
13
16
  docsDir: isStringOrArrayOfStrings.default(["docs"]),
14
17
  blogDir: isStringOrArrayOfStrings.default(["blog"]),
15
- removeDefaultStopWordFilter: Joi.boolean().default(false),
16
- removeDefaultStemmer: Joi.boolean().default(false),
17
- highlightSearchTermsOnTargetPage: Joi.boolean().default(false),
18
- searchResultLimits: Joi.number().default(8),
19
- searchResultContextMaxLength: Joi.number().default(50),
20
- explicitSearchResultPath: Joi.boolean().default(false),
18
+ removeDefaultStopWordFilter: utils_validation_1.Joi.boolean().default(false),
19
+ removeDefaultStemmer: utils_validation_1.Joi.boolean().default(false),
20
+ highlightSearchTermsOnTargetPage: utils_validation_1.Joi.boolean().default(false),
21
+ searchResultLimits: utils_validation_1.Joi.number().default(8),
22
+ searchResultContextMaxLength: utils_validation_1.Joi.number().default(50),
23
+ explicitSearchResultPath: utils_validation_1.Joi.boolean().default(false),
21
24
  ignoreFiles: isArrayOfStringsOrRegExpsOrStringOrRegExp.default([]),
22
25
  ignoreCssSelectors: isStringOrArrayOfStrings.default([]),
23
- searchBarShortcut: Joi.boolean().default(true),
24
- searchBarShortcutHint: Joi.boolean().default(true),
25
- searchBarPosition: Joi.string().default("auto"),
26
- docsPluginIdForPreferredVersion: Joi.string(),
27
- zhUserDict: Joi.string(),
28
- zhUserDictPath: Joi.string(),
29
- searchContextByPaths: Joi.array().items(Joi.string()),
30
- hideSearchBarWithNoSearchContext: Joi.boolean().default(false),
31
- useAllContextsWithNoSearchContext: Joi.boolean().default(false),
26
+ searchBarShortcut: utils_validation_1.Joi.boolean().default(true),
27
+ searchBarShortcutHint: utils_validation_1.Joi.boolean().default(true),
28
+ searchBarPosition: utils_validation_1.Joi.string().default("auto"),
29
+ docsPluginIdForPreferredVersion: utils_validation_1.Joi.string(),
30
+ zhUserDict: utils_validation_1.Joi.string(),
31
+ zhUserDictPath: utils_validation_1.Joi.string(),
32
+ searchContextByPaths: utils_validation_1.Joi.array().items(utils_validation_1.Joi.string()),
33
+ hideSearchBarWithNoSearchContext: utils_validation_1.Joi.boolean().default(false),
34
+ useAllContextsWithNoSearchContext: utils_validation_1.Joi.boolean().default(false),
32
35
  });
33
- export function validateOptions({ options, validate, }) {
36
+ function validateOptions({ options, validate, }) {
34
37
  return validate(schema, options || {});
35
38
  }
39
+ exports.validateOptions = validateOptions;
@@ -1,4 +1,7 @@
1
- export function generateTrimmer(wordCharacters) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateTrimmer = void 0;
4
+ function generateTrimmer(wordCharacters) {
2
5
  const startRegex = new RegExp("^[^" + wordCharacters + "]+", "u");
3
6
  const endRegex = new RegExp("[^" + wordCharacters + "]+$", "u");
4
7
  return function (token) {
@@ -7,3 +10,4 @@ export function generateTrimmer(wordCharacters) {
7
10
  });
8
11
  };
9
12
  }
13
+ exports.generateTrimmer = generateTrimmer;
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,7 +1,10 @@
1
- import { generateTrimmer } from "./generateTrimmer";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.lunrLanguageZh = void 0;
4
+ const generateTrimmer_1 = require("./generateTrimmer");
2
5
  // `lunr-languages/lunr.stemmer.support` is required.
3
- export function lunrLanguageZh(lunr, tokenizer) {
4
- lunr.trimmerSupport.generateTrimmer = generateTrimmer;
6
+ function lunrLanguageZh(lunr, tokenizer) {
7
+ lunr.trimmerSupport.generateTrimmer = generateTrimmer_1.generateTrimmer;
5
8
  lunr.zh = function () {
6
9
  this.pipeline.reset();
7
10
  this.pipeline.add(lunr.zh.trimmer, lunr.zh.stopWordFilter);
@@ -22,3 +25,4 @@ export function lunrLanguageZh(lunr, tokenizer) {
22
25
  lunr.zh.stopWordFilter = lunr.generateStopWordFilter("的 一 不 在 人 有 是 为 以 于 上 他 而 后 之 来 及 了 因 下 可 到 由 这 与 也 此 但 并 个 其 已 无 小 我 们 起 最 再 今 去 好 只 又 或 很 亦 某 把 那 你 乃 它 吧 被 比 别 趁 当 从 到 得 打 凡 儿 尔 该 各 给 跟 和 何 还 即 几 既 看 据 距 靠 啦 了 另 么 每 们 嘛 拿 哪 那 您 凭 且 却 让 仍 啥 如 若 使 谁 虽 随 同 所 她 哇 嗡 往 哪 些 向 沿 哟 用 于 咱 则 怎 曾 至 致 着 诸 自".split(" "));
23
26
  lunr.Pipeline.registerFunction(lunr.zh.stopWordFilter, "stopWordFilter-zh");
24
27
  }
28
+ exports.lunrLanguageZh = lunrLanguageZh;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyops-cn/docusaurus-search-local",
3
- "version": "0.38.0",
3
+ "version": "0.38.1",
4
4
  "description": "An offline/local search plugin for Docusaurus v3",
5
5
  "repository": "https://github.com/easyops-cn/docusaurus-search-local",
6
6
  "homepage": "https://github.com/easyops-cn/docusaurus-search-local",