From 67edb89f41a4c498e75c0b7b257d79a4d9f387cb Mon Sep 17 00:00:00 2001 From: "idan.liberman" Date: Fri, 4 Oct 2024 23:04:29 +0300 Subject: [PATCH] add feature to remove redirects folder and contents upon plugin unload --- main.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/main.ts b/main.ts index 564f7ee..e249460 100644 --- a/main.ts +++ b/main.ts @@ -98,19 +98,32 @@ export default class RedirectPlugin extends Plugin { } catch (error) { console.log(error); console.log(redirectingNote); + new Notice( + `${redirectingNote.name} is already in the _redirects folder.`, + 3000 + ); } // MAKE SURE TO NOT REMOVE THE REDIRECTING NOTE WHEN CLICKED INSIDE THE _REDIRECTS FOLDER! // console.log(redirectingNote.path); // console.log(`_redirects/${redirectingNote.name}`); if (redirectingNote.path === `_redirects/${redirectingNote.name}`) { - // console.log("yes we're in the reidrects folder"); + console.log("yes we're in the reidrects folder"); return; } await this.app.vault.delete(redirectingNote); } - onunload() {} + onunload() { + const redirectsFolder = this.app.vault.getFolderByPath("_redirects"); + + if (!redirectsFolder) { + return; + } + console.log("redirectsFolder: ", redirectsFolder); + + this.app.vault.delete(redirectsFolder, true); + } async loadSettings() { this.settings = Object.assign(