Skip to content

Commit

Permalink
Merge pull request #49 from p-l-/add-refresh-data
Browse files Browse the repository at this point in the history
Add a function to refresh notes from IVRE
  • Loading branch information
p-l- authored Feb 3, 2023
2 parents f6b52c2 + 3efcf70 commit bdc88f7
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
PluginSettingTab,
Setting,
TFile,
TFolder,
Vault,
} from "obsidian";
import {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {}

Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit bdc88f7

Please sign in to comment.