Skip to content

Commit

Permalink
Exclude folder from overview
Browse files Browse the repository at this point in the history
  • Loading branch information
LostPaul committed Aug 6, 2023
1 parent 4b3a5a0 commit 5e3424a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "folder-notes",
"name": "Folder notes",
"version": "1.4.6",
"version": "1.4.7",
"minAppVersion": "0.15.0",
"description": "Create notes within folders that can be accessed without collapsing the folder, similar to the functionality offered in Notion.",
"author": "Lost Paul",
Expand Down
14 changes: 11 additions & 3 deletions src/excludedFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class ExcludedFolder {
disableFolderNote: boolean;
enableCollapsing: boolean;
position: number;
excludeFromFolderOverview: boolean;
constructor(path: string, position: number) {
this.type = 'folder';
this.path = path;
Expand All @@ -24,6 +25,7 @@ export class ExcludedFolder {
this.disableFolderNote = false;
this.enableCollapsing = false;
this.position = position;
this.excludeFromFolderOverview = false;
this.string = '';
}
}
Expand All @@ -38,6 +40,7 @@ export class ExcludePattern {
disableAutoCreate: boolean;
disableFolderNote: boolean;
enableCollapsing: boolean;
excludeFromFolderOverview: boolean;
constructor(pattern: string, position: number) {
this.type = 'pattern';
this.string = pattern;
Expand All @@ -47,6 +50,7 @@ export class ExcludePattern {
this.disableAutoCreate = true;
this.disableFolderNote = false;
this.enableCollapsing = false;
this.excludeFromFolderOverview = false;
this.path = '';
}
}
Expand All @@ -61,10 +65,14 @@ export function getExcludedFolder(plugin: FolderNotesPlugin, path: string) {
}

export function getExcludedFolderByPattern(plugin: FolderNotesPlugin, folderName: string) {
return plugin.settings.excludeFolders.filter((s) => s.path === '').find((pattern) => {
return plugin.settings.excludeFolders.filter((s) => s.type == 'pattern').find((pattern) => {
if (!pattern.string) { return false; }
if (pattern.string.toLocaleLowerCase().startsWith('{regex}') && pattern.string.slice(7).trim() !== '') {
const match = new RegExp(pattern.string.slice(7).trim()).exec(folderName);
const string = pattern.string.toLocaleLowerCase().trim();
if (!string.startsWith('{regex}') || string.startsWith('*') || string.endsWith('*')) { return false; }
const regex = string.replace('{regex}', '').trim();
if (string.startsWith('{regex}') && regex === '') { return false; }
if (regex !== undefined) {
const match = new RegExp(regex).exec(folderName);
if (match) {
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions src/folderOverview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { MarkdownPostProcessorContext, parseYaml, TAbstractFile, TFolder, TFile
import { extractFolderName, getFolderNote } from './functions/folderNoteFunctions';
import FolderNotesPlugin from './main';
import { FolderOverviewSettings } from './modals/folderOverview';
import { getExcludedFolder } from './excludedFolder';
export type yamlSettings = {
title?: string;
disableTitle?: boolean;
Expand Down Expand Up @@ -71,6 +72,8 @@ export function createOverview(plugin: FolderNotesPlugin, source: string, el: HT
files = files.filter((file) => {
const folderPath = plugin.getFolderPathFromString(file.path);
if (!folderPath.startsWith(sourceFolderPath)) { return false; }
const excludedFolder = getExcludedFolder(plugin, file.path);
if (excludedFolder?.excludeFromFolderOverview) { return false; }
if (file.path === ctx.sourcePath) { return false; }
if ((file.path.split('/').length - sourceFolderPath.split('/').length) - 1 < depth) {
return true;
Expand Down
12 changes: 12 additions & 0 deletions src/modals/excludeFolderSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ export default class ExcludedFolderSettings extends Modal {
})
);

new Setting(contentEl)
.setName('Don\'t show folder in folder overview')
.setDesc('Choose if the folder should be shown in the folder overview')
.addToggle((toggle) =>
toggle
.setValue(this.excludedFolder.excludeFromFolderOverview)
.onChange(async (value) => {
this.excludedFolder.excludeFromFolderOverview = value;
await this.plugin.saveSettings();
})
);

new Setting(contentEl)
.setName('Disable auto creation of folder notes in this folder')
.setDesc('Choose if a folder note should be created when a new folder is created')
Expand Down
12 changes: 12 additions & 0 deletions src/modals/patternSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ export default class PatternSettings extends Modal {
})
);

new Setting(contentEl)
.setName('Don\'t show folder in folder overview')
.setDesc('Choose if the folder should be shown in the folder overview')
.addToggle((toggle) =>
toggle
.setValue(this.pattern.excludeFromFolderOverview)
.onChange(async (value) => {
this.pattern.excludeFromFolderOverview = value;
await this.plugin.saveSettings();
})
);


new Setting(contentEl)
.setName('Disable open folder note')
Expand Down

0 comments on commit 5e3424a

Please sign in to comment.