forked from silverbulletmd/silverbullet-graphview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphignore.ts
38 lines (32 loc) · 1.43 KB
/
graphignore.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { editor, space, system } from "@silverbulletmd/silverbullet/syscalls";
import { readGraphviewSettings } from "utils";
export class GraphIgnore {
ignoredPages: string[];
ignoredPrefixes: string[];
constructor(ignoredPages: string[] = [], ignoredPrefixes: string[] = []) {
this.ignoredPages = ignoredPages;
this.ignoredPrefixes = ignoredPrefixes;
}
// Get all pages tagged with graphignore
async init(): Promise<void> {
const ignoredPrefixesFromSettings = await readGraphviewSettings("ignoredPrefixes");
this.ignoredPrefixes = ignoredPrefixesFromSettings ? ignoredPrefixesFromSettings : [];
this.ignoredPages = (await system.invokeFunction("index.queryObjects", "tag", {
filter: ["=", ["attr", "name"], ["string", "graphignore"]],
})).map((tag) => tag.page);
}
// Check if a page is tagged with graphignore
isIgnoredPage(page: string): boolean {
return this.ignoredPages.includes(page) || this.ignoredPrefixes.some(prefix => page.startsWith(prefix));
}
// Filter function to remove pages tagged with graphignore
pagefilter(page: any) {
return !this.isIgnoredPage(page.name);
}
// Filter function to remove links to and from pages tagged with graphignore
linkfilter(link: any) {
return !this.isIgnoredPage(link.page) &&
((link.hasOwnProperty("toPage") && !this.isIgnoredPage(link.toPage)) ||
(link.hasOwnProperty("toFile") && !this.isIgnoredPage(link.toFile)));
}
}