mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-06 14:22:47 +02:00
feat: introduce SurfSense plugin for Obsidian with syncing capabilities and enhanced settings management
This commit is contained in:
parent
ee2fb79e75
commit
60d9e7ed8c
19 changed files with 2044 additions and 175 deletions
66
surfsense_obsidian/src/excludes.ts
Normal file
66
surfsense_obsidian/src/excludes.ts
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
/**
|
||||
* Tiny glob matcher for exclude patterns.
|
||||
*
|
||||
* Supports `*` (any chars except `/`), `**` (any chars including `/`), and
|
||||
* literal segments. Patterns without a slash are matched against any path
|
||||
* segment (so `templates` excludes `templates/foo.md` and `notes/templates/x.md`).
|
||||
*
|
||||
* Intentionally not a full minimatch — Obsidian users overwhelmingly type
|
||||
* folder names ("templates", ".trash") and the obvious wildcards. Avoiding
|
||||
* the dependency keeps the bundle small and the mobile attack surface tiny.
|
||||
*/
|
||||
|
||||
const cache = new Map<string, RegExp>();
|
||||
|
||||
function compile(pattern: string): RegExp {
|
||||
const cached = cache.get(pattern);
|
||||
if (cached) return cached;
|
||||
|
||||
let body = "";
|
||||
let i = 0;
|
||||
while (i < pattern.length) {
|
||||
const ch = pattern[i] ?? "";
|
||||
if (ch === "*") {
|
||||
if (pattern[i + 1] === "*") {
|
||||
body += ".*";
|
||||
i += 2;
|
||||
if (pattern[i] === "/") i += 1;
|
||||
continue;
|
||||
}
|
||||
body += "[^/]*";
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
if (".+^${}()|[]\\".includes(ch)) {
|
||||
body += "\\" + ch;
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
body += ch;
|
||||
i += 1;
|
||||
}
|
||||
|
||||
const anchored = pattern.includes("/")
|
||||
? `^${body}(/.*)?$`
|
||||
: `(^|/)${body}(/.*)?$`;
|
||||
const re = new RegExp(anchored);
|
||||
cache.set(pattern, re);
|
||||
return re;
|
||||
}
|
||||
|
||||
export function isExcluded(path: string, patterns: string[]): boolean {
|
||||
if (!patterns.length) return false;
|
||||
for (const raw of patterns) {
|
||||
const trimmed = raw.trim();
|
||||
if (!trimmed || trimmed.startsWith("#")) continue;
|
||||
if (compile(trimmed).test(path)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function parseExcludePatterns(raw: string): string[] {
|
||||
return raw
|
||||
.split(/\r?\n/)
|
||||
.map((line) => line.trim())
|
||||
.filter((line) => line.length > 0 && !line.startsWith("#"));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue