diff --git a/package-lock.json b/package-lock.json index 8256fb5..c73e8d9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "obsidian-sample-plugin", - "version": "1.0.27", + "version": "1.0.28", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "obsidian-sample-plugin", - "version": "1.0.27", + "version": "1.0.28", "license": "MIT", "devDependencies": { "@types/node": "16.11.6", diff --git a/src/models/PluginSettingsTab.ts b/src/models/PluginSettingsTab.ts index 886360b..897e574 100644 --- a/src/models/PluginSettingsTab.ts +++ b/src/models/PluginSettingsTab.ts @@ -32,6 +32,7 @@ export interface PluginSetting { renderFolderItalic: boolean; useBulletPoints: boolean; excludeFolders: string[]; + excludePatterns: string[]; recursionLimit: number; headlineLimit: number; indexFileUserSpecified: boolean; @@ -56,6 +57,7 @@ export const DEFAULT_SETTINGS: PluginSetting = { renderFolderItalic: false, useBulletPoints: false, excludeFolders: [], + excludePatterns: [], recursionLimit: -1, headlineLimit: 6, indexFileUserSpecified: false, @@ -137,6 +139,20 @@ export class PluginSettingsTab extends PluginSettingTab { component.inputEl.cols = 50 }) + new Setting(containerEl) + .setName("Excluded Patterns") + .setDesc("Files and folders matching these patterns will be excluded from the content renderer. Use * as wildcard. One pattern per line.") + .addTextArea(component => { + component.setPlaceholder("Assets\n*img*\n*.pdf") + .setValue(this.plugin.settings.excludePatterns.join("\n")) + .onChange(async (value) => { + this.plugin.settings.excludePatterns = value.split("\n") + await this.plugin.saveSettings() + }) + component.inputEl.rows = 8 + component.inputEl.cols = 50 + }) + new Setting(containerEl) .setName("Automatically generate IndexFile") .setDesc("This will automatically create an IndexFile when you create a new folder") diff --git a/src/types/Utilities.ts b/src/types/Utilities.ts index 05ebc70..40f2349 100644 --- a/src/types/Utilities.ts +++ b/src/types/Utilities.ts @@ -22,11 +22,22 @@ export function isIndexFile(path: string) { } export function isExcludedPath(path: string) { + // Check exact folder matches first for (const excludedFolder of FolderIndexPlugin.PLUGIN.settings.excludeFolders) { if (excludedFolder == "") continue if (RegExp(`^${excludedFolder}$`).test(path)) return true; } + + // Then check pattern matches + for (const pattern of FolderIndexPlugin.PLUGIN.settings.excludePatterns) { + if (pattern == "") + continue + // Escape special characters in the pattern except * which we'll use as wildcard + const escapedPattern = pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&').replace(/\\\*/g, '.*'); + if (new RegExp(escapedPattern, 'i').test(path)) + return true; + } return false }