From d9b957f237822504ad951fe62b63346d03793c9c Mon Sep 17 00:00:00 2001 From: Glin76 Date: Sat, 14 Jun 2025 08:35:52 +0200 Subject: [PATCH 1/7] Adding new script RemoveDeadNoteLink --- RemoveDeadNoteLink/info.json | 10 +++++ RemoveDeadNoteLink/removedeadnotelink.qml | 53 +++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 RemoveDeadNoteLink/info.json create mode 100644 RemoveDeadNoteLink/removedeadnotelink.qml diff --git a/RemoveDeadNoteLink/info.json b/RemoveDeadNoteLink/info.json new file mode 100644 index 0000000..76c6957 --- /dev/null +++ b/RemoveDeadNoteLink/info.json @@ -0,0 +1,10 @@ +{ + "name": "RemoveDeadNoteLink", + "identifier": "removedeadnotelink", + "script": "removedeadnotelink.qml", + "authors": ["@Glin76"], + "platforms": ["linux", "macos", "windows"], + "version": "0.0.2", + "minAppVersion": "25.6.1", + "description": "This script creates a menu item and a button that search in all notes and remove links to note (MD file) no longer existing (aka dead note-link)." +} \ No newline at end of file diff --git a/RemoveDeadNoteLink/removedeadnotelink.qml b/RemoveDeadNoteLink/removedeadnotelink.qml new file mode 100644 index 0000000..4232b60 --- /dev/null +++ b/RemoveDeadNoteLink/removedeadnotelink.qml @@ -0,0 +1,53 @@ +import QtQml 2.0 + +/** + * This script creates a menu item and a button that search in all notes and remove links to note (MD file) no longer existing (aka dead note-link) + */ + +QtObject { + + function customActionInvoked(identifier) { + switch (identifier) { + case "RemoveDeadNoteLink": + var dialogText = ""; + var reLink = RegExp("\\[.*\\]\\(.*\\.md\\)", "g"); // RegExp to find links : "[***](***.md)" + script.fetchNoteIdsByNoteTextPart("").forEach(function (noteId){ // Loop for all notes + var linkText = ""; + var note = script.fetchNoteById(noteId); + var newNoteText = note.noteText; + var LinkFound = reLink.exec(note.noteText); + while (LinkFound != null){ // Loop for all links in the note + var LinkNoteName = LinkFound.toString().replace(RegExp(".*\\(", "").exec(LinkFound),"") // RegExp to find the name of the link : from start of the link to "(", and then removed from the string + LinkNoteName = LinkNoteName.toString().replace(RegExp(".*\\/", "").exec(LinkNoteName),"") // RegExp to find the relative path : from start to the last"/", and then removed from the string + LinkNoteName = LinkNoteName.replace(")",""); // removing last ")" of the link + while (LinkNoteName.search("%20") > -1) { + LinkNoteName = LinkNoteName.replace("%20", " "); // replacing all the %20 by space in the filename + } + if (script.fetchNoteByFileName(LinkNoteName).id == 0) { // Does a note exist with that filename + newNoteText = newNoteText.replace(LinkFound, ""); // removing the link in the future NoteText + linkText += "\n - "+LinkFound; + } + LinkFound = reLink.exec(note.noteText); + } + if (note.noteText != newNoteText) { + script.setCurrentNote(note); + script.noteTextEditSelectAll(); + script.noteTextEditWrite(newNoteText.trim()); + dialogText += "\n\nNote : "+note.name+" link(s) removed :"+linkText; + } + }); + + if (dialogText != "") { + dialogText = "Here's the result of removing dead note-link(s)"+dialogText; + script.informationMessageBox(dialogText); + } else { + script.informationMessageBox("No dead note-link found"); + } + break; + } + } + + function init() { + script.registerCustomAction("RemoveDeadNoteLink", "Remove dead links to note", "Remove dead note-link", "bookmark-new", true, false, true); + } +} From 193ffcee15cb20827e7d9d2f8b0c44a1565d0be6 Mon Sep 17 00:00:00 2001 From: Glin76 Date: Sat, 14 Jun 2025 08:43:55 +0200 Subject: [PATCH 2/7] Rename removedeadnotelink.qml to removedeadnotelink.qml --- {RemoveDeadNoteLink => Removedeadnotelink}/removedeadnotelink.qml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {RemoveDeadNoteLink => Removedeadnotelink}/removedeadnotelink.qml (100%) diff --git a/RemoveDeadNoteLink/removedeadnotelink.qml b/Removedeadnotelink/removedeadnotelink.qml similarity index 100% rename from RemoveDeadNoteLink/removedeadnotelink.qml rename to Removedeadnotelink/removedeadnotelink.qml From 301b40b51ba80dac8510ce31636016ada302c5fd Mon Sep 17 00:00:00 2001 From: Glin76 Date: Sat, 14 Jun 2025 08:46:07 +0200 Subject: [PATCH 3/7] Update and rename info.json to info.json --- {RemoveDeadNoteLink => Removedeadnotelink}/info.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename {RemoveDeadNoteLink => Removedeadnotelink}/info.json (97%) diff --git a/RemoveDeadNoteLink/info.json b/Removedeadnotelink/info.json similarity index 97% rename from RemoveDeadNoteLink/info.json rename to Removedeadnotelink/info.json index 76c6957..f194e05 100644 --- a/RemoveDeadNoteLink/info.json +++ b/Removedeadnotelink/info.json @@ -7,4 +7,4 @@ "version": "0.0.2", "minAppVersion": "25.6.1", "description": "This script creates a menu item and a button that search in all notes and remove links to note (MD file) no longer existing (aka dead note-link)." -} \ No newline at end of file +} From 04f719590ac7b779b2f80545c87239a1f74e74e2 Mon Sep 17 00:00:00 2001 From: Glin76 Date: Sat, 14 Jun 2025 08:47:12 +0200 Subject: [PATCH 4/7] Update and rename info.json to info.json --- {Removedeadnotelink => removedeadnotelink}/info.json | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {Removedeadnotelink => removedeadnotelink}/info.json (100%) diff --git a/Removedeadnotelink/info.json b/removedeadnotelink/info.json similarity index 100% rename from Removedeadnotelink/info.json rename to removedeadnotelink/info.json From 77bcf785b9461b526c81849c8e8834be4d77ee84 Mon Sep 17 00:00:00 2001 From: Glin76 Date: Sat, 14 Jun 2025 08:47:46 +0200 Subject: [PATCH 5/7] Rename removedeadnotelink.qml to removedeadnotelink.qml --- {Removedeadnotelink => removedeadnotelink}/removedeadnotelink.qml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {Removedeadnotelink => removedeadnotelink}/removedeadnotelink.qml (100%) diff --git a/Removedeadnotelink/removedeadnotelink.qml b/removedeadnotelink/removedeadnotelink.qml similarity index 100% rename from Removedeadnotelink/removedeadnotelink.qml rename to removedeadnotelink/removedeadnotelink.qml From 357babb58f233b2d4ebc1111c61b4ceff4f08a2f Mon Sep 17 00:00:00 2001 From: Glin76 Date: Sat, 14 Jun 2025 10:22:10 +0200 Subject: [PATCH 6/7] Update info.json --- removedeadnotelink/info.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/removedeadnotelink/info.json b/removedeadnotelink/info.json index f194e05..71d6677 100644 --- a/removedeadnotelink/info.json +++ b/removedeadnotelink/info.json @@ -4,7 +4,7 @@ "script": "removedeadnotelink.qml", "authors": ["@Glin76"], "platforms": ["linux", "macos", "windows"], - "version": "0.0.2", + "version": "0.0.1", "minAppVersion": "25.6.1", - "description": "This script creates a menu item and a button that search in all notes and remove links to note (MD file) no longer existing (aka dead note-link)." + "description": "This script creates a menu item and a button that searches in all notes and removes links to notes (MD file) that no longer exist (aka dead note-link)." } From 7a850cb0557d30a5c638428b4abe1272e6a87d73 Mon Sep 17 00:00:00 2001 From: Glin76 Date: Sat, 14 Jun 2025 10:40:49 +0200 Subject: [PATCH 7/7] Update info.json --- removedeadnotelink/info.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/removedeadnotelink/info.json b/removedeadnotelink/info.json index 71d6677..bf5a225 100644 --- a/removedeadnotelink/info.json +++ b/removedeadnotelink/info.json @@ -6,5 +6,5 @@ "platforms": ["linux", "macos", "windows"], "version": "0.0.1", "minAppVersion": "25.6.1", - "description": "This script creates a menu item and a button that searches in all notes and removes links to notes (MD file) that no longer exist (aka dead note-link)." + "description": "This script creates a menu item and a button that searches through all notes and removes links to all notes (Markdown files) that no longer exist, also known as dead note links." }