@vuepress-plume/plugin-search 1.0.0-rc.193 → 1.0.0-rc.195
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/lib/node/index.js +4 -53
- package/package.json +2 -2
package/lib/node/index.js
CHANGED
|
@@ -100,45 +100,7 @@ async function prepareSearchIndex({ app, isSearchable, searchOptions }) {
|
|
|
100
100
|
}
|
|
101
101
|
if (app.env.isDebug) logger.info(`\n[${colors.green("@vuepress-plume/plugin-search")}] prepare search time spent: ${(performance.now() - start).toFixed(2)}ms`);
|
|
102
102
|
}
|
|
103
|
-
|
|
104
|
-
* Handle search index update when a page is modified.
|
|
105
|
-
*
|
|
106
|
-
* 当页面被修改时处理搜索索引更新。
|
|
107
|
-
*
|
|
108
|
-
* @param app - VuePress application instance / VuePress 应用实例
|
|
109
|
-
* @param options - Search index preparation options / 搜索索引准备选项
|
|
110
|
-
* @param options.page - VuePress page instance / VuePress 页面实例
|
|
111
|
-
* @param options.isSearchable - Function to filter searchable pages / 过滤可搜索页面的函数
|
|
112
|
-
* @param options.searchOptions - MiniSearch configuration / MiniSearch 配置
|
|
113
|
-
*/
|
|
114
|
-
async function onSearchIndexUpdated(app, { page, isSearchable, searchOptions }) {
|
|
115
|
-
if (isSearchable && !isSearchable(page)) return;
|
|
116
|
-
await indexFile(page, searchOptions, isSearchable);
|
|
117
|
-
await writeTemp(app);
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Handle search index update when a page is removed.
|
|
121
|
-
*
|
|
122
|
-
* 当页面被删除时处理搜索索引更新。
|
|
123
|
-
*
|
|
124
|
-
* @param app - VuePress application instance / VuePress 应用实例
|
|
125
|
-
* @param options - Search index preparation options / 搜索索引准备选项
|
|
126
|
-
* @param options.page - VuePress page instance / VuePress 页面实例
|
|
127
|
-
* @param options.isSearchable - Function to filter searchable pages / 过滤可搜索页面的函数
|
|
128
|
-
* @param options.searchOptions - MiniSearch configuration / MiniSearch 配置
|
|
129
|
-
*/
|
|
130
|
-
async function onSearchIndexRemoved(app, { page, isSearchable, searchOptions }) {
|
|
131
|
-
if (isSearchable && !isSearchable(page)) return;
|
|
132
|
-
if (page.filePathRelative) {
|
|
133
|
-
const fileId = page.path;
|
|
134
|
-
const locale = page.pathLocale;
|
|
135
|
-
const lang = page.lang;
|
|
136
|
-
const index = getIndexByLocale(locale, lang, searchOptions);
|
|
137
|
-
const cache = getIndexCache(fileId);
|
|
138
|
-
if (cache && cache.length) index.removeAll(cache);
|
|
139
|
-
await writeTemp(app);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
103
|
+
Promise.resolve();
|
|
142
104
|
/**
|
|
143
105
|
* Write all search indexes to temporary files.
|
|
144
106
|
*
|
|
@@ -189,7 +151,9 @@ async function indexFile(page, options, isSearchable) {
|
|
|
189
151
|
const cache = getIndexCache(fileId);
|
|
190
152
|
const sections = splitPageIntoSections(`<h1><a href="#"><span>${page.frontmatter.title || page.title}</span></a></h1>
|
|
191
153
|
${page.contentRendered}`);
|
|
192
|
-
|
|
154
|
+
try {
|
|
155
|
+
if (cache && cache.length) index.removeAll(cache);
|
|
156
|
+
} catch {}
|
|
193
157
|
for await (const section of sections) {
|
|
194
158
|
if (!section || !(section.text || section.titles)) break;
|
|
195
159
|
const { anchor, text, titles } = section;
|
|
@@ -490,19 +454,6 @@ function searchPlugin({ locales = {}, isSearchable, ...searchOptions } = {}) {
|
|
|
490
454
|
searchOptions
|
|
491
455
|
});
|
|
492
456
|
}
|
|
493
|
-
},
|
|
494
|
-
onPageUpdated: async (app, type, page) => {
|
|
495
|
-
if (!page?.filePathRelative) return;
|
|
496
|
-
if (type === "create" || type === "update") await onSearchIndexUpdated(app, {
|
|
497
|
-
page,
|
|
498
|
-
isSearchable,
|
|
499
|
-
searchOptions
|
|
500
|
-
});
|
|
501
|
-
else if (type === "delete") await onSearchIndexRemoved(app, {
|
|
502
|
-
page,
|
|
503
|
-
isSearchable,
|
|
504
|
-
searchOptions
|
|
505
|
-
});
|
|
506
457
|
}
|
|
507
458
|
});
|
|
508
459
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vuepress-plume/plugin-search",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.0-rc.
|
|
4
|
+
"version": "1.0.0-rc.195",
|
|
5
5
|
"description": "The Plugin for VuePress 2 - local search",
|
|
6
6
|
"author": "pengzhanbo <volodymyr@foxmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"mark.js": "^8.11.1",
|
|
43
43
|
"minisearch": "^7.2.0",
|
|
44
44
|
"p-map": "^7.0.4",
|
|
45
|
-
"vue": "^3.5.
|
|
45
|
+
"vue": "^3.5.32"
|
|
46
46
|
},
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public",
|