Skip to content

Commit 5c5d270

Browse files
committed
refactor: extract search filter into named function
1 parent c4350a9 commit 5c5d270

1 file changed

Lines changed: 10 additions & 16 deletions

File tree

docs/.vitepress/config.js

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,15 @@ function buildEditLink({ filePath }) {
169169
return `${repoUrl}/bluelua.github.io/edit/main/docs/src/${filePath}`;
170170
}
171171

172+
function filterSearchResult(result) {
173+
const project = location.pathname.match(/^\/([^/]+)(?:\/|$)/)?.[1];
174+
if (!project) {
175+
return true;
176+
}
177+
178+
return result.id === `/${project}/` || result.id.startsWith(`/${project}/`);
179+
}
180+
172181
export default defineConfig({
173182
srcDir: "./src",
174183
title: "BlueLua",
@@ -215,22 +224,7 @@ export default defineConfig({
215224
search: {
216225
provider: "local",
217226
options: {
218-
miniSearch: {
219-
searchOptions: {
220-
filter(result) {
221-
const project =
222-
location.pathname.match(/^\/([^/]+)(?:\/|$)/)?.[1];
223-
if (!project) {
224-
return true;
225-
}
226-
227-
return (
228-
result.id === `/${project}/` ||
229-
result.id.startsWith(`/${project}/`)
230-
);
231-
},
232-
},
233-
},
227+
miniSearch: { searchOptions: { filter: filterSearchResult } },
234228
},
235229
},
236230
editLink: { pattern: buildEditLink },

0 commit comments

Comments
 (0)