From 49fa7ab5e38c98814b5d011a6501f4329059d070 Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Sat, 29 Jan 2022 12:08:46 +0200 Subject: [PATCH] feat(Hierarchy Note): :sparkles: Point to a folder full of hierarchy notes by ending the folder name with `/` (fix #138) --- main.js | 36 +++++++++++++++------------ src/Settings/HierarchyNoteSettings.ts | 20 +++++++-------- src/refreshIndex.ts | 34 +++++++++++++++++++------ 3 files changed, 55 insertions(+), 35 deletions(-) diff --git a/main.js b/main.js index 3da5825f..adf118f6 100644 --- a/main.js +++ b/main.js @@ -33369,10 +33369,23 @@ async function buildMainG(plugin) { // SECTION Hierarchy Notes db.start2G("Hierarchy Notes"); if (hierarchyNotes.length) { - for (const note of hierarchyNotes) { - const file = app.metadataCache.getFirstLinkpathDest(note, ""); - if (file) - addHNsToGraph(settings, await getHierarchyNoteItems(plugin, file), mainG); + for (const noteOrFolder of hierarchyNotes) { + if (noteOrFolder.endsWith("/")) { + const folder = app.vault.getAbstractFileByPath(obsidian.normalizePath(noteOrFolder)); + if (!(folder instanceof obsidian.TFolder)) + continue; + for (const child of folder.children) { + console.log({ child }); + if (child instanceof obsidian.TFile) { + addHNsToGraph(settings, await getHierarchyNoteItems(plugin, child), mainG); + } + } + } + else { + const file = app.metadataCache.getFirstLinkpathDest(noteOrFolder, ""); + if (file) + addHNsToGraph(settings, await getHierarchyNoteItems(plugin, file), mainG); + } } } db.end2G(); @@ -34128,24 +34141,15 @@ function addHierarchyNoteSettings(plugin, alternativeHierarchyDetails) { const hierarchyNoteDetails = subDetails("Hierarchy Notes", alternativeHierarchyDetails); new obsidian.Setting(hierarchyNoteDetails) .setName("Hierarchy Note(s)") - .setDesc("A list of notes used to create external Breadcrumb structures.") + .setDesc(fragWithHTML("A comma-separated list of notes used to create external Breadcrumb structures.
You can also point to a folder of hierarchy notes by entering folderName/ (ending with a /).
Hierarchy note names and folders of hierarchy notes can both be entered in the same comma-separated list.")) .addText((text) => { text .setPlaceholder("Hierarchy Note(s)") .setValue(settings.hierarchyNotes.join(", ")); text.inputEl.onblur = async () => { const splits = splitAndTrim(text.getValue()); - if (splits[0] === undefined) { - settings.hierarchyNotes = splits; - await plugin.saveSettings(); - } - else if (splits.every((note) => isInVault(this.app, note))) { - settings.hierarchyNotes = splits; - await plugin.saveSettings(); - } - else { - new obsidian.Notice("Atleast one of the notes is not in your vault"); - } + settings.hierarchyNotes = splits; + await plugin.saveSettings(); }; }); new obsidian.Setting(hierarchyNoteDetails) diff --git a/src/Settings/HierarchyNoteSettings.ts b/src/Settings/HierarchyNoteSettings.ts index 647d572d..32409025 100644 --- a/src/Settings/HierarchyNoteSettings.ts +++ b/src/Settings/HierarchyNoteSettings.ts @@ -3,7 +3,7 @@ import { isInVault } from "obsidian-community-lib/dist/utils"; import type BCPlugin from "../main"; import { splitAndTrim } from "../Utils/generalUtils"; import { getFields } from "../Utils/HierUtils"; -import { subDetails } from "./BreadcrumbsSettingTab"; +import { fragWithHTML, subDetails } from "./BreadcrumbsSettingTab"; export function addHierarchyNoteSettings( plugin: BCPlugin, @@ -17,7 +17,11 @@ export function addHierarchyNoteSettings( new Setting(hierarchyNoteDetails) .setName("Hierarchy Note(s)") - .setDesc("A list of notes used to create external Breadcrumb structures.") + .setDesc( + fragWithHTML( + "A comma-separated list of notes used to create external Breadcrumb structures.
You can also point to a folder of hierarchy notes by entering folderName/ (ending with a /).
Hierarchy note names and folders of hierarchy notes can both be entered in the same comma-separated list." + ) + ) .addText((text) => { text .setPlaceholder("Hierarchy Note(s)") @@ -25,15 +29,9 @@ export function addHierarchyNoteSettings( text.inputEl.onblur = async () => { const splits = splitAndTrim(text.getValue()); - if (splits[0] === undefined) { - settings.hierarchyNotes = splits; - await plugin.saveSettings(); - } else if (splits.every((note) => isInVault(this.app, note))) { - settings.hierarchyNotes = splits; - await plugin.saveSettings(); - } else { - new Notice("Atleast one of the notes is not in your vault"); - } + + settings.hierarchyNotes = splits; + await plugin.saveSettings(); }; }); diff --git a/src/refreshIndex.ts b/src/refreshIndex.ts index d179e388..0324ccc3 100644 --- a/src/refreshIndex.ts +++ b/src/refreshIndex.ts @@ -1,6 +1,6 @@ import { MultiGraph } from "graphology"; import { debug, error } from "loglevel"; -import { Notice, Pos, TFile } from "obsidian"; +import { normalizePath, Notice, Pos, TFile, TFolder } from "obsidian"; import { wait } from "obsidian-community-lib"; import { addCSVCrumbs, getCSVRows } from "./AlternativeHierarchies/CSVCrumbs"; import { addDendronNotesToGraph } from "./AlternativeHierarchies/DendronNotes"; @@ -238,14 +238,32 @@ export async function buildMainG(plugin: BCPlugin): Promise { db.start2G("Hierarchy Notes"); if (hierarchyNotes.length) { - for (const note of hierarchyNotes) { - const file = app.metadataCache.getFirstLinkpathDest(note, ""); - if (file) - addHNsToGraph( - settings, - await getHierarchyNoteItems(plugin, file), - mainG + for (const noteOrFolder of hierarchyNotes) { + if (noteOrFolder.endsWith("/")) { + const folder = app.vault.getAbstractFileByPath( + normalizePath(noteOrFolder) ); + + if (!(folder instanceof TFolder)) continue; + for (const child of folder.children) { + console.log({ child }); + if (child instanceof TFile) { + addHNsToGraph( + settings, + await getHierarchyNoteItems(plugin, child), + mainG + ); + } + } + } else { + const file = app.metadataCache.getFirstLinkpathDest(noteOrFolder, ""); + if (file) + addHNsToGraph( + settings, + await getHierarchyNoteItems(plugin, file), + mainG + ); + } } }