andy-stack_vaultkeeper-ai/Helpers/WikiLinks.ts
Andrew Beal 167a2b13a5 refactor: standardize error handling with Exception helper and improve return types
Add Exception helper class for consistent error handling and logging. Replace throw statements and console.error calls with Exception methods. Update service methods to return Error | T instead of mixed success/failure objects. Improve type safety in Claude.extractContents with explicit return type.

Add WikiLinks helper to VaultCacheService for managing wiki link references.

Update unit tests.
2025-11-17 19:02:15 +00:00

39 lines
No EOL
856 B
TypeScript

import { TFile } from "obsidian";
export class WikiLinks {
public links: string[] = [];
public addWikiLink(file: TFile) {
if (file.extension === "md") {
this.links.push(this.asWikiLink(file));
}
}
public removeWikiLink(file: TFile | string) {
if (file instanceof TFile) {
if (file.extension === "md") {
this.removeFromLinks(this.asWikiLink(file));
}
} else {
if (file.endsWith(".md")) {
this.removeFromLinks(this.asWikiLink(file));
}
}
}
private asWikiLink(file: TFile | string) {
if (file instanceof TFile) {
return file.path.replace(/\.md$/, "");
}
return file.replace(/\.md$/, "");
}
private removeFromLinks(wikiLink: string) {
const index = this.links.indexOf(wikiLink);
if (index !== -1) {
this.links.splice(index, 1);
}
}
}