Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/Setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
46 changes: 46 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface BinaryFileManagerSettings {
filenameFormat: string;
templatePath: string;
useTemplater: boolean;
ignoredPaths: string[];
}

const DEFAULT_SETTINGS: BinaryFileManagerSettings = {
Expand Down Expand Up @@ -39,6 +40,7 @@ const DEFAULT_SETTINGS: BinaryFileManagerSettings = {
filenameFormat: 'INFO_{{NAME}}_{{EXTENSION:UP}}',
templatePath: '',
useTemplater: false,
ignoredPaths: [],
};

export default class BinaryFileManagerPlugin extends Plugin {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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(
{},
Expand Down