From 1ceb4ee6206a67bbf56f0e32b875c40a894a4791 Mon Sep 17 00:00:00 2001 From: Liam Rooney Date: Thu, 18 Apr 2024 16:54:04 -0700 Subject: [PATCH 1/2] added option to use 'Obsidian Links' in Landmark Subtrees --- main.ts | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/main.ts b/main.ts index b58960e..97c17ea 100644 --- a/main.ts +++ b/main.ts @@ -18,6 +18,7 @@ interface WaypointSettings { showNonMarkdownFiles: boolean; debugLogging: boolean; useWikiLinks: boolean; + useObsidianLinksInLandmarkSubtree: boolean; useFrontMatterTitle: boolean; showEnclosingNote: boolean; folderNoteType: string; @@ -34,6 +35,7 @@ const DEFAULT_SETTINGS: WaypointSettings = { showNonMarkdownFiles: false, debugLogging: false, useWikiLinks: true, + useObsidianLinksInLandmarkSubtree: false, useFrontMatterTitle: false, showEnclosingNote: false, folderNoteType: FolderNoteType.InsideFolder, @@ -268,9 +270,10 @@ export default class Waypoint extends Plugin { * @param node The current node in our recursive descent * @param indentLevel How many levels of indentation to draw * @param topLevel Whether this is the top level of the tree or not + * @param landmarkObsidianLink Whether to use Obsidian links for files in Landmark "subtrees" * @returns The string representation of the tree, or null if the node is not a file or folder */ - async getFileTreeRepresentation(rootNode: TFolder, node: TAbstractFile, indentLevel: number, topLevel = false): Promise | null { + async getFileTreeRepresentation(rootNode: TFolder, node: TAbstractFile, indentLevel: number, topLevel = false, landmarkObsidianLink = false): Promise | null { const indent = this.settings.useSpaces ? " ".repeat(this.settings.numSpaces) : " "; const bullet = indent.repeat(indentLevel) + "-"; if (!(node instanceof TFile) && !(node instanceof TFolder)) { @@ -297,6 +300,13 @@ export default class Waypoint extends Plugin { } // Print the file name if (node.extension == "md") { + if(landmarkObsidianLink) { // can only be set true if setting enabled + if (title) { + return `${bullet} [${title}](obsidian://open?vault=${this.app.vault.getName()}&file=${this.getEncodedUri(rootNode, node)})`; + } else { + return `${bullet} [${node.basename}](obsidian://open?vault=${this.app.vault.getName()}&file=${this.getEncodedUri(rootNode, node)})`; + } + } if (this.settings.useWikiLinks) { if (title) { return `${bullet} [[${node.basename}|${title}]]`; @@ -329,7 +339,10 @@ export default class Waypoint extends Plugin { folderNote = this.app.vault.getAbstractFileByPath(node.parent.path + "/" + node.name + ".md"); } if (folderNote instanceof TFile) { - if (this.settings.useWikiLinks) { + if (landmarkObsidianLink) { + text = `${bullet} **[${folderNote.basename}](obsidian://open?vault=${this.app.vault.getName()}&file=${this.getEncodedUri(rootNode, folderNote)})**`; + } + else if (this.settings.useWikiLinks) { text = `${bullet} **[[${folderNote.basename}]]**`; } else { text = `${bullet} **[${folderNote.basename}](${this.getEncodedUri(rootNode, folderNote)})**`; @@ -342,6 +355,9 @@ export default class Waypoint extends Plugin { if (content.includes(Waypoint.BEGIN_WAYPOINT) || content.includes(this.settings.waypointFlag)) { return text; } + if (this.settings.useObsidianLinksInLandmarkSubtree && (content.includes(Waypoint.BEGIN_LANDMARK) || content.includes(this.settings.landmarkFlag))) { + landmarkObsidianLink = true; + } } } } @@ -371,7 +387,7 @@ export default class Waypoint extends Plugin { } if (children.length > 0) { const nextIndentLevel = topLevel && !this.settings.showEnclosingNote ? indentLevel : indentLevel + 1; - text += (text === "" ? "" : "\n") + (await Promise.all(children.map((child) => this.getFileTreeRepresentation(rootNode, child, nextIndentLevel)))).filter(Boolean).join("\n"); + text += (text === "" ? "" : "\n") + (await Promise.all(children.map((child) => this.getFileTreeRepresentation(rootNode, child, nextIndentLevel, false, landmarkObsidianLink)))).filter(Boolean).join("\n"); } return text; } @@ -584,6 +600,18 @@ class WaypointSettingsTab extends PluginSettingTab { await this.plugin.saveSettings(); }) ); + new Setting(containerEl) + .setName("Generate Obsidian Links for Landmark Subdirectories") + .setDesc(`If enabled, links will be generated like [My Page](obsidian://open?vault=${this.app.vault.getName()}&file=./Folder/My%20Page.md) for files in Landmark Subdirectories. + The file with the Landmark itself will respect the 'Use WikiLinks' Setting. + Access the files the same, but the graph is less cluttered. + `) + .addToggle((toggle) => + toggle.setValue(this.plugin.settings.useObsidianLinksInLandmarkSubtree).onChange(async (value) => { + this.plugin.settings.useObsidianLinksInLandmarkSubtree = value; + await this.plugin.saveSettings(); + }) + ); new Setting(containerEl) .setName("Use Title Property") .setDesc("If enabled, links will use the \"title\" frontmatter property for the displayed text (if it exists).") From 0b299770a958e6b32e4378ae2f3419151092288b Mon Sep 17 00:00:00 2001 From: Liam Rooney Date: Thu, 18 Apr 2024 18:43:13 -0700 Subject: [PATCH 2/2] removed new line --- main.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/main.ts b/main.ts index 97c17ea..49e2f2d 100644 --- a/main.ts +++ b/main.ts @@ -341,8 +341,7 @@ export default class Waypoint extends Plugin { if (folderNote instanceof TFile) { if (landmarkObsidianLink) { text = `${bullet} **[${folderNote.basename}](obsidian://open?vault=${this.app.vault.getName()}&file=${this.getEncodedUri(rootNode, folderNote)})**`; - } - else if (this.settings.useWikiLinks) { + } else if (this.settings.useWikiLinks) { text = `${bullet} **[[${folderNote.basename}]]**`; } else { text = `${bullet} **[${folderNote.basename}](${this.getEncodedUri(rootNode, folderNote)})**`;