From fedd294bcfdb72a06046d56180c237172e441306 Mon Sep 17 00:00:00 2001 From: Lex Toumbourou Date: Tue, 11 Apr 2023 19:45:03 +1000 Subject: [PATCH] Add Update All Links command. --- README.md | 4 ++++ main.ts | 18 ++++++++++++++++++ manifest.json | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0e14c72..1158863 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,10 @@ The plugin infers the title as follows: ``` * Link result: `[no-title](no-title.md)` +## Comands + +* `Update All Links` can be used to add the title as link text to all existing Markdown links in your vault. + ## License MIT diff --git a/main.ts b/main.ts index c294b76..2327709 100644 --- a/main.ts +++ b/main.ts @@ -26,6 +26,24 @@ export default class BetterMarkdownLinksPlugin extends Plugin { this.updateBackLinks(file, file.path); }) ); + + this.addCommand({ + id: "update-all-links", + name: "Update All Links", + callback: async () => { + await this.updateAllLinks(); + new Notice("All links have been updated."); + }, + }); + } + + async updateAllLinks() { + const markdownFiles = this.app.vault.getMarkdownFiles(); + + for (const file of markdownFiles) { + const oldPath = file.path; + await this.updateBackLinks(file, oldPath); + } } async updateBackLinks(file: TFile, oldPath: string) { diff --git a/manifest.json b/manifest.json index 8cdfeac..2b142a2 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-title-as-link-text", "name": "Title As Link Text", - "version": "1.0.2", + "version": "1.0.3", "minAppVersion": "0.15.0", "description": "This plugin improves the behaviour of Markdown-style links in Obsidian.", "author": "Lex Toumbourou",