Skip to content

Commit

Permalink
feat(Hierarchy Note): ✨ Point to a folder full of hierarchy notes by …
Browse files Browse the repository at this point in the history
…ending the folder name with `/` (fix #138)
  • Loading branch information
SkepticMystic committed Jan 29, 2022
1 parent 1428e50 commit 49fa7ab
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 35 deletions.
36 changes: 20 additions & 16 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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.<br>You can also point to a <i>folder</i> of hierarchy notes by entering <code>folderName/</code> (ending with a <code>/</code>).<br>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)
Expand Down
20 changes: 9 additions & 11 deletions src/Settings/HierarchyNoteSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -17,23 +17,21 @@ 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.<br>You can also point to a <i>folder</i> of hierarchy notes by entering <code>folderName/</code> (ending with a <code>/</code>).<br>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 Notice("Atleast one of the notes is not in your vault");
}

settings.hierarchyNotes = splits;
await plugin.saveSettings();
};
});

Expand Down
34 changes: 26 additions & 8 deletions src/refreshIndex.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -238,14 +238,32 @@ export async function buildMainG(plugin: BCPlugin): Promise<MultiGraph> {
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
);
}
}
}

Expand Down

0 comments on commit 49fa7ab

Please sign in to comment.