Skip to content

Commit

Permalink
Merge pull request #93 from Moyf/support-exclude-patterns
Browse files Browse the repository at this point in the history
Exclude specific files/folders from the render view
  • Loading branch information
turulix authored Dec 11, 2024
2 parents 9e75e09 + 407a6e6 commit eb160cd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions src/models/PluginSettingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface PluginSetting {
renderFolderItalic: boolean;
useBulletPoints: boolean;
excludeFolders: string[];
excludePatterns: string[];
recursionLimit: number;
headlineLimit: number;
indexFileUserSpecified: boolean;
Expand All @@ -56,6 +57,7 @@ export const DEFAULT_SETTINGS: PluginSetting = {
renderFolderItalic: false,
useBulletPoints: false,
excludeFolders: [],
excludePatterns: [],
recursionLimit: -1,
headlineLimit: 6,
indexFileUserSpecified: false,
Expand Down Expand Up @@ -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")
Expand Down
11 changes: 11 additions & 0 deletions src/types/Utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit eb160cd

Please sign in to comment.