diff --git a/README.md b/README.md index 7812e38..a4c810f 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,32 @@ [![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/akosbalasko/zoottelkeeper-obsidian-plugin?style=for-the-badge&sort=semver)](https://github.com/akosbalasko/zoottelkeeper-obsidian-plugin/releases/latest) ![GitHub All Releases](https://img.shields.io/github/downloads/akosbalasko/zoottelkeeper-obsidian-plugin/total?style=for-the-badge) +## Changes in v.0.18.0 + +- Include/Exclude folders improved: absolute paths are required, independently from its first character (it can be '/', or simply just start with the name of the folder within the root path to be included/excluded ). +- Specific character is introduced: if you type '*' at the end of the folder, it means that it AND its subdirectories(recursively) will be included or excluded + +### Example: +Assuming that you have the following directories in the root of your vault: +``` +Notes +Notes/Daily +Articles +Articles/Science +``` + +If you would like to include Notes, the Daily within and Articles to be included, but exclude Articles/Science you should set +include property to: +``` +Notes/* +Articles +``` +and exclude property to: +``` +Articles/Science +``` + + ## What's new in the latest version (v0.17.0) - Option to set a **template** for index files - Numbers sorted correctly in index links (bug: https://github.com/akosbalasko/zoottelkeeper-obsidian-plugin/issues/45) diff --git a/main.ts b/main.ts index 8c968da..592abee 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,48 @@ 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, example: Notes/ Articles/, which will include Notes and Articles folder in the root folder. Empty list means all of the vault will be handled except the excluded folders. \'*\' 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 + .replace(/,/g,'\n') + .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. Example: "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 + .replace(/,/g,'\n') + .split('\n') + .map( + folder=> { + const f = folder.trim(); + return f.startsWith('/') + ? f.substring(1) + : f + }) + .join('\n');; await this.plugin.saveSettings(); }) ); diff --git a/manifest.json b/manifest.json index 9270aab..f1c5714 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "zoottelkeeper-obsidian-plugin", "name": "Zoottelkeeper Plugin", - "version": "0.17.3", + "version": "0.18.0", "minAppVersion": "0.12.1", "description": "This plugin automatically creates, maintains and tags MOCs for all your folders.", "author": "Akos Balasko, Micha Brugger", diff --git a/package.json b/package.json index a09ad05..551cd22 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zoottelkeeper-obsidian-plugin", - "version": "0.17.3", + "version": "0.18.0", "description": "This plugin automatically creates, maintains and tags MOCs for all your folders.", "main": "main.js", "scripts": { diff --git a/utils/isInSpecificFolder.ts b/utils/isInSpecificFolder.ts index a6cfe98..ab7523f 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].replace(/,/g,'\n').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('/'); + }) } diff --git a/versions.json b/versions.json index f190f75..b9e55ea 100644 --- a/versions.json +++ b/versions.json @@ -14,5 +14,6 @@ "0.17.0": "0.12.1", "0.17.1": "0.12.1", "0.17.2": "0.12.1", - "0.17.3": "0.12.1" + "0.17.3": "0.12.1", + "0.18.0": "0.12.1" } \ No newline at end of file