From 7d820e28804c36db7e24ee1390eaea4bbda73185 Mon Sep 17 00:00:00 2001 From: Jason Christopher Date: Mon, 8 Apr 2024 22:14:38 -0700 Subject: [PATCH 1/7] add exlude by folder regex functionality --- src/main.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main.ts b/src/main.ts index 2b4459f..33d414c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -44,6 +44,7 @@ interface PluginSettings { autoRename: boolean handleAllAttachments: boolean excludeExtensionPattern: string + excludeFolderPattern: string disableRenameNotice: boolean } @@ -55,6 +56,7 @@ const DEFAULT_SETTINGS: PluginSettings = { autoRename: false, handleAllAttachments: false, excludeExtensionPattern: '', + excludeFolderPattern: '', disableRenameNotice: false, } @@ -94,6 +96,10 @@ export default class PasteImageRenamePlugin extends Plugin { debugLog('excluded file by ext', file) return } + if (this.testExcludeFolder(file)) { + debugLog('excluded file by folder', file) + return + } this.startRenameProcess(file, this.settings.autoRename) } } @@ -372,6 +378,11 @@ export default class PasteImageRenamePlugin extends Plugin { if (!pattern) return false return new RegExp(pattern).test(file.extension) } + testExcludeFolder(file: TFile): boolean { + const pattern = this.settings.excludeFolderPattern + if (!pattern) return false + return new RegExp(pattern).test(file.path) + } async loadSettings() { this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()); From 98575caba1d25530b19a010f9d88cee55708cbf0 Mon Sep 17 00:00:00 2001 From: Jason Christopher Date: Mon, 8 Apr 2024 23:46:19 -0700 Subject: [PATCH 2/7] update packages --- package-lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 69d5854..78bf060 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "obsidian-paste-image-rename", - "version": "1.5.0", + "version": "1.6.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "obsidian-paste-image-rename", - "version": "1.5.0", + "version": "1.6.1", "license": "MIT", "dependencies": { "cash-dom": "^8.1.2" From 688ef181468f463c28e04910959005c182a6054e Mon Sep 17 00:00:00 2001 From: Jason Christopher Date: Mon, 8 Apr 2024 23:47:46 -0700 Subject: [PATCH 3/7] change file pattern to path pattern --- src/main.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main.ts b/src/main.ts index 33d414c..f192f0e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -44,7 +44,7 @@ interface PluginSettings { autoRename: boolean handleAllAttachments: boolean excludeExtensionPattern: string - excludeFolderPattern: string + excludePathPattern: string disableRenameNotice: boolean } @@ -56,7 +56,7 @@ const DEFAULT_SETTINGS: PluginSettings = { autoRename: false, handleAllAttachments: false, excludeExtensionPattern: '', - excludeFolderPattern: '', + excludePathPattern: '', disableRenameNotice: false, } @@ -675,6 +675,19 @@ class SettingTab extends PluginSettingTab { } )); + new Setting(containerEl) + .setName('Exclude path pattern') + .setDesc(`Write a Regex pattern to exclude certain paths from being handled. Only the first line will be used.`) + .setClass('single-line-textarea') + .addTextArea(text => text + .setPlaceholder('^Journal\/|^Zotero\/') + .setValue(this.plugin.settings.excludePathPattern) + .onChange(async (value) => { + this.plugin.settings.excludePathPattern = value; + await this.plugin.saveSettings(); + } + )); + new Setting(containerEl) .setName('Disable rename notice') .setDesc(`Turn off this option if you don't want to see the notice when renaming images. From a5db2c5f3fafca80b3744f740a92da6039fab9e3 Mon Sep 17 00:00:00 2001 From: Jason Christopher Date: Mon, 8 Apr 2024 23:48:21 -0700 Subject: [PATCH 4/7] path exclusion based on active file --- src/main.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main.ts b/src/main.ts index f192f0e..9c64862 100644 --- a/src/main.ts +++ b/src/main.ts @@ -88,6 +88,11 @@ export default class PasteImageRenamePlugin extends Plugin { return if (isPastedImage(file)) { debugLog('pasted image created', file) + const activeFile = this.getActiveFile() + if (this.testExcludePath(activeFile)) { + debugLog('excluded file by path', activeFile) + return + } this.startRenameProcess(file, this.settings.autoRename) } else { if (this.settings.handleAllAttachments) { @@ -96,8 +101,9 @@ export default class PasteImageRenamePlugin extends Plugin { debugLog('excluded file by ext', file) return } - if (this.testExcludeFolder(file)) { - debugLog('excluded file by folder', file) + const activeFile = this.getActiveFile() + if (this.testExcludePath(activeFile)) { + debugLog('excluded file by path', activeFile) return } this.startRenameProcess(file, this.settings.autoRename) @@ -378,9 +384,10 @@ export default class PasteImageRenamePlugin extends Plugin { if (!pattern) return false return new RegExp(pattern).test(file.extension) } - testExcludeFolder(file: TFile): boolean { - const pattern = this.settings.excludeFolderPattern + testExcludePath(file: TFile): boolean { + const pattern = this.settings.excludePathPattern if (!pattern) return false + debugLog('file path', file.path) return new RegExp(pattern).test(file.path) } From f742622f59374788bd988bfdc467f72e227f69e0 Mon Sep 17 00:00:00 2001 From: Jason Christopher Date: Tue, 9 Apr 2024 10:15:41 -0700 Subject: [PATCH 5/7] updated readme --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 8b0901e..430037b 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,14 @@ If we paste the third image without editing the "New name" input, its name will This feature is especially powerful if you enable "Auto rename" in settings, you can just add new images without thinking, and they will be renamed sequentially by the pattern and `imageNameKey` set. +### Exclude Paths + +> New in 1.6.0 + +Add a new setting `Exclude path pattern` which allows you to exclude renaming if the file being being pasted into's path matches a regular expression pattern. + +For example, suppose that you don't want to rename attachments to files in `My Special Folder`. If you set the `Exclude path pattern` setting to `^My Special Folder\/` renaming will not be invoked on any files in that folder. Note the leading `^` and ending `\/` in the regular expression. These ensure the pattern matches at the beginning of the path and includes the `/` character at the end. Without the latter the regular expression would match a file named `My Special Folder` in addition to any files in that folder. + ### Batch renaming process > New in 1.3.0 @@ -160,6 +168,9 @@ that match the given extension pattern. This option is only useful when "Handle all attachments" is enabled. Write a Regex pattern to exclude certain extensions from being handled. Only the first line will be used. +- **Exclude path pattern** + + Write a Regex pattern to exclude certain paths from being handled. Only the first line will be used. - **Disable rename notice** Turn off this option if you don't want to see the notice when renaming images. From d86e3490cd783ca5c5e42cb300d7a56f7aac60c2 Mon Sep 17 00:00:00 2001 From: Jason Christopher Date: Tue, 9 Apr 2024 10:22:20 -0700 Subject: [PATCH 6/7] 1.7.0 --- manifest.json | 2 +- package-lock.json | 4 ++-- package.json | 2 +- versions.json | 3 ++- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/manifest.json b/manifest.json index 152d913..b928cbd 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-paste-image-rename", "name": "Paste image rename", - "version": "1.6.1", + "version": "1.7.0", "minAppVersion": "0.12.0", "description": "Rename pasted images and all the other attchments added to the vault", "author": "Reorx", diff --git a/package-lock.json b/package-lock.json index 78bf060..90115a6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "obsidian-paste-image-rename", - "version": "1.6.1", + "version": "1.7.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "obsidian-paste-image-rename", - "version": "1.6.1", + "version": "1.7.0", "license": "MIT", "dependencies": { "cash-dom": "^8.1.2" diff --git a/package.json b/package.json index c904e4a..5783716 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-paste-image-rename", - "version": "1.6.1", + "version": "1.7.0", "main": "main.js", "scripts": { "start": "node esbuild.config.mjs", diff --git a/versions.json b/versions.json index f843727..1206e98 100644 --- a/versions.json +++ b/versions.json @@ -12,5 +12,6 @@ "1.5.1": "0.12.0", "1.5.2": "0.12.0", "1.6.0": "0.12.0", - "1.6.1": "0.12.0" + "1.6.1": "0.12.0", + "1.7.0": "0.12.0" } \ No newline at end of file From 3f3ba7a8237568cd40f3ddfe2dd388cf557829ed Mon Sep 17 00:00:00 2001 From: Jason Christopher Date: Tue, 9 Apr 2024 10:23:30 -0700 Subject: [PATCH 7/7] correct version for added functionality in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 430037b..15d296d 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ This feature is especially powerful if you enable "Auto rename" in settings, you ### Exclude Paths -> New in 1.6.0 +> New in 1.7.0 Add a new setting `Exclude path pattern` which allows you to exclude renaming if the file being being pasted into's path matches a regular expression pattern.