This commit is contained in:
爱喝水的木子
2026-03-13 16:28:51 +08:00
commit bfdf4843e1
38 changed files with 9490 additions and 0 deletions

14
lib/search.ts Normal file
View File

@@ -0,0 +1,14 @@
export function escapeRegExp(input: string): string {
return input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
export function buildSearchFilter(query?: string) {
if (!query) return null;
const trimmed = query.trim();
if (!trimmed) return null;
const safe = escapeRegExp(trimmed);
const regex = new RegExp(safe, "i");
return {
$or: [{ title: { $regex: regex } }, { markdown: { $regex: regex } }]
};
}