diff --git a/main.ts b/main.ts index 8c968da..2aaa9b8 100644 --- a/main.ts +++ b/main.ts @@ -85,13 +85,14 @@ export default class ZoottelkeeperPlugin extends Plugin { Array.from(indexFiles2BUpdated) )}` ); - + + await this.removeDisallowedFoldersIndexes(indexFiles2BUpdated); // update index files for (const indexFile of Array.from(indexFiles2BUpdated)) { await this.generateIndexContents(indexFile); } - await this.cleanDisallowedFolders(); + } catch (e) {} } this.lastVault = new Set( @@ -255,13 +256,21 @@ export default class ZoottelkeeperPlugin extends Plugin { return `${parentPath}${this.settings.indexPrefix}${parentName}.md`; }; + removeDisallowedFoldersIndexes = async (indexFiles: Set): Promise => { + for (const folder of this.settings.foldersExcluded.split('\n').map(f=> f.trim())){ + const innerIndex = this.getInnerIndexFilePath(folder); + indexFiles.delete(innerIndex); + } + } + cleanDisallowedFolders = async (): Promise => { - for (const folder of this.settings.foldersExcluded.split(',').map(f=> f.trim())){ + for (const folder of this.settings.foldersExcluded.split('\n').map(f=> f.trim())){ const innerIndex = this.getInnerIndexFilePath(folder); const indexTFile = this.app.vault.getAbstractFileByPath(innerIndex); await this.app.vault.delete(indexTFile); } } + getParentFolder = (filePath: string): string => { const fileFolderArray = filePath.split('/'); fileFolderArray.pop(); @@ -320,28 +329,46 @@ class ZoottelkeeperPluginSettingTab extends PluginSettingTab { new Setting(containerEl) .setName('Folders included') .setDesc( - 'Specify the folders to be handled by Zoottelkeeper. They must be absolute paths starting from the root vault separated by comma. Empty list means all of the vault will be handled except the excluded folders.' + 'Specify the folders to be handled by Zoottelkeeper. They must be absolute paths starting from the root vault one per line. Empty list means all of the vault will be handled except the excluded folders. \n E.g. "Notes/ Articles/", \n that will include Notes and Articles folder in the root folder. * can be added to the end, to include the folder\'s subdirectories recursively, e.g. Notes/* Articles/' ) - .addText((text) => + .addTextArea((text) => text .setPlaceholder('') .setValue(this.plugin.settings.foldersIncluded) .onChange(async (value) => { - this.plugin.settings.foldersIncluded = value; + this.plugin.settings.foldersIncluded = value + .split('\n') + .map( + folder=> { + const f = folder.trim(); + return f.startsWith('/') + ? f.substring(1) + : f + }) + .join('\n'); await this.plugin.saveSettings(); }) ); new Setting(containerEl) .setName('Folders excluded') .setDesc( - 'Specify the folders NOT to be handled by Zoottelkeeper. They must be absolute paths starting from the root vault separated by comma.' + 'Specify the folders NOT to be handled by Zoottelkeeper. They must be absolute paths starting from the root vault, one per line. \n e.g. "Notes/ Articles/ ", it will exclude Notes and Articles folder in the root folder. * can be added to the end, to exclude the folder\'s subdirectories recursively.' ) - .addText((text) => + .addTextArea((text) => text .setPlaceholder('') .setValue(this.plugin.settings.foldersExcluded) .onChange(async (value) => { - this.plugin.settings.foldersExcluded = value; + this.plugin.settings.foldersExcluded = value + .split('\n') + .map( + folder=> { + const f = folder.trim(); + return f.startsWith('/') + ? f.substring(1) + : f + }) + .join('\n');; await this.plugin.saveSettings(); }) ); diff --git a/utils/isInSpecificFolder.ts b/utils/isInSpecificFolder.ts index a6cfe98..d6170b7 100644 --- a/utils/isInSpecificFolder.ts +++ b/utils/isInSpecificFolder.ts @@ -10,6 +10,11 @@ export const isInDisAllowedFolder = (settings: ZoottelkeeperPluginSettings, inde } export const isInSpecificFolder = (settings: ZoottelkeeperPluginSettings, indexFilePath: string, folderType: string): boolean => { - return !!settings[folderType].split(',').find((folder: any) => indexFilePath.startsWith(folder.trim())) + + return !!settings[folderType].split('\n').find((folder: any) => { + return folder.endsWith('*') + ? indexFilePath.startsWith(folder.slice(0, -1).trim()) + : indexFilePath.split(folder).length > 1 && !indexFilePath.split(folder)[1].includes('/'); + }) }