diff --git a/src/Setting.ts b/src/Setting.ts index 545b096..472ce17 100644 --- a/src/Setting.ts +++ b/src/Setting.ts @@ -39,6 +39,25 @@ export class BinaryFileManagerSettingTab extends PluginSettingTab { }); }); + new Setting(containerEl) + .setName('Ignored directories') + .setDesc( + 'Directory paths to ignore during auto detection. One path per line. Wildcards supported (e.g., archives/*, *inbox)' + ) + .addTextArea((textArea) => { + textArea + .setPlaceholder('archives/*\n*inbox\ntemp/') + .setValue(this.plugin.settings.ignoredPaths.join('\n')) + .onChange(async (value: string) => { + this.plugin.settings.ignoredPaths = value + .split('\n') + .map((path) => path.trim()) + .filter((path) => path.length > 0); + await this.plugin.saveSettings(); + }); + textArea.inputEl.rows = 4; + }); + new Setting(containerEl) .setName('New file location') .setDesc('New metadata file will be placed here') diff --git a/src/main.ts b/src/main.ts index 523eb7c..8256118 100644 --- a/src/main.ts +++ b/src/main.ts @@ -12,6 +12,7 @@ interface BinaryFileManagerSettings { filenameFormat: string; templatePath: string; useTemplater: boolean; + ignoredPaths: string[]; } const DEFAULT_SETTINGS: BinaryFileManagerSettings = { @@ -39,6 +40,7 @@ const DEFAULT_SETTINGS: BinaryFileManagerSettings = { filenameFormat: 'INFO_{{NAME}}_{{EXTENSION:UP}}', templatePath: '', useTemplater: false, + ignoredPaths: [], }; export default class BinaryFileManagerPlugin extends Plugin { @@ -69,6 +71,11 @@ export default class BinaryFileManagerPlugin extends Plugin { return; } + // Check if the file path should be ignored during auto detection + if (this.isPathIgnored(file.path)) { + return; + } + await this.metaDataGenerator.create(file as TFile); new Notice(`Metadata file of ${file.name} is created.`); this.fileListAdapter.add(file.path); @@ -102,6 +109,11 @@ export default class BinaryFileManagerPlugin extends Plugin { continue; } + // Check if the file path should be ignored during manual detection + if (this.isPathIgnored(file.path)) { + return; + } + promises.push( this.metaDataGenerator .create(file as TFile) @@ -126,6 +138,10 @@ export default class BinaryFileManagerPlugin extends Plugin { const unlinkedFiles = this.metaDataGenerator.findUnlinkedBinaries(); unlinkedFiles.forEach((file) => { + // Check if the file path should be ignored during unlinked detection + if (this.isPathIgnored(file.path)) { + return; + } promises.push( this.metaDataGenerator .create(file as TFile) @@ -148,6 +164,36 @@ export default class BinaryFileManagerPlugin extends Plugin { // onunload() {} + private isPathIgnored(filePath: string): boolean { + if (this.settings.ignoredPaths.length === 0) { + return false; + } + + for (const ignoredPath of this.settings.ignoredPaths) { + const trimmedPath = ignoredPath.trim(); + if (trimmedPath === '') { + continue; + } + + // Convert glob pattern to regex + const regexPattern = trimmedPath + .replace(/\*/g, '.*') + .replace(/\?/g, '.'); + + const regex = new RegExp(`^${regexPattern}(?:/|$)`); + + // Check if the file path or its parent directory matches the pattern + if ( + regex.test(filePath) || + regex.test(filePath.split('/').slice(0, -1).join('/')) + ) { + return true; + } + } + + return false; + } + async loadSettings() { this.settings = Object.assign( {},