From 1727499bbd35e5770eef0d4935a458bb72bc7060 Mon Sep 17 00:00:00 2001 From: Idrees Hassan Date: Wed, 29 Jun 2022 21:46:16 -0400 Subject: [PATCH] Make WikiLinks optional --- main.ts | 28 ++++++++++++++++++++++++---- package-lock.json | 4 ++-- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/main.ts b/main.ts index 0861ff2..27d6c85 100644 --- a/main.ts +++ b/main.ts @@ -4,14 +4,16 @@ interface WaypointSettings { waypointFlag: string stopScanAtFolderNotes: boolean, showFolderNotes: boolean, - debugLogging: boolean + debugLogging: boolean, + useWikiLinks: boolean } const DEFAULT_SETTINGS: WaypointSettings = { waypointFlag: "%% Waypoint %%", stopScanAtFolderNotes: false, showFolderNotes: false, - debugLogging: false + debugLogging: false, + useWikiLinks: true } export default class Waypoint extends Plugin { @@ -147,14 +149,22 @@ export default class Waypoint extends Plugin { const bullet = " ".repeat(indentLevel) + "-"; if (node instanceof TFile) { if (node.path.endsWith(".md")) { - return `${bullet} [${node.basename}](${node.path.replace(/ /g, '%20')})`; + if (this.settings.useWikiLinks) { + return `${bullet} [[${node.basename}]]`; + } else { + return `${bullet} [${node.basename}](../${encodeURI(node.path)})`; + } } return null; } else if (node instanceof TFolder) { let text = `${bullet} **${node.name}**`; const folderNote = this.app.vault.getAbstractFileByPath(node.path + "/" + node.name + ".md"); if (folderNote instanceof TFile) { - text = `${bullet} **[${folderNote.basename}](${folderNote.path.replace(/ /g, '%20')})**`; + if (this.settings.useWikiLinks) { + text = `${bullet} **[[${folderNote.basename}]]**`; + } else { + text = `${bullet} **[${folderNote.basename}](../${encodeURI(folderNote.path)})**`; + } if (!topLevel) { if (this.settings.stopScanAtFolderNotes) { return text; @@ -304,6 +314,16 @@ class WaypointSettingsTab extends PluginSettingTab { await this.plugin.saveSettings(); }) ); + new Setting(containerEl) + .setName("Use WikiLinks") + .setDesc("If enabled, links will be generated like [[My Page]] instead of [My Page](../Folder/My%Page.md).") + .addToggle(toggle => toggle + .setValue(this.plugin.settings.useWikiLinks) + .onChange(async (value) => { + this.plugin.settings.useWikiLinks = value; + await this.plugin.saveSettings(); + }) + ); new Setting(containerEl) .setName("Waypoint Flag") .setDesc("Text flag that triggers waypoint generation in a folder note. Must be surrounded by double-percent signs.") diff --git a/package-lock.json b/package-lock.json index 5801987..88445a8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "waypoint", - "version": "1.0.1", + "version": "1.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "waypoint", - "version": "1.0.1", + "version": "1.1.0", "license": "MIT", "devDependencies": { "@types/codemirror": "^5.60.5",