From 3efcf70d19bb2485b485a4f086b9f48afc906bed Mon Sep 17 00:00:00 2001 From: Pierre Lalet Date: Fri, 3 Feb 2023 19:56:18 +0100 Subject: [PATCH] Add a function to refresh notes from IVRE --- main.ts | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/main.ts b/main.ts index 7a93797..ef21fab 100644 --- a/main.ts +++ b/main.ts @@ -7,6 +7,7 @@ import { PluginSettingTab, Setting, TFile, + TFolder, Vault, } from "obsidian"; import { @@ -173,7 +174,6 @@ function create_note(vault: Vault, fname: string, content: string) { if (!(file instanceof TFile)) { console.log(`Cannot recreate ${fname}`); } else { - console.log(`Re-creating ${fname}`); vault.modify(file, content); } } else { @@ -519,6 +519,27 @@ function ivre_handle_mac( } return undefined; } +function ivre_refresh_data(vault: Vault, settings: IvrePluginSettings) { + const base = vault.getAbstractFileByPath(settings.base_directory); + if (!(base instanceof TFolder)) { + console.log(`IVRE's base is not a folder: ${base}`); + return; + } + const sub_dirs = Object.fromEntries(base.children.map((x) => [x.name, x])); + if (sub_dirs.IP instanceof TFolder) { + for (const subf of sub_dirs.IP.children) { + if (subf instanceof TFile) { + ivre_handle_address( + subf.basename + .replace(/_([0-9]+)$/, "/$1") + .replace(/_/g, ":"), + vault, + settings + ); + } + } + } +} class IvreSearch {} @@ -964,6 +985,14 @@ export default class IvrePlugin extends Plugin { }, }); + this.addCommand({ + id: "refresh-data", + name: "Refresh IVRE data", + callback: () => { + ivre_refresh_data(this.app.vault, this.settings); + }, + }); + // This adds a settings tab so the user can configure various aspects of the plugin this.addSettingTab(new IvreSettingTab(this.app, this)); }