From bb47b4dcd3042d8aae2ce3ae87608db09b92b13d Mon Sep 17 00:00:00 2001 From: Akos Balasko Date: Thu, 24 Mar 2022 14:06:31 +0100 Subject: [PATCH 1/3] feat: star implemented --- main.ts | 45 +++++++++++++++++++++++++++++-------- utils/isInSpecificFolder.ts | 7 +++++- 2 files changed, 42 insertions(+), 10 deletions(-) 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('/'); + }) } From 3268626bddcc19b8f82349678a829adb4b113f6a Mon Sep 17 00:00:00 2001 From: Akos Balasko Date: Thu, 24 Mar 2022 14:23:10 +0100 Subject: [PATCH 2/3] backward compatibility --- main.ts | 6 ++++-- utils/isInSpecificFolder.ts | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/main.ts b/main.ts index 2aaa9b8..592abee 100644 --- a/main.ts +++ b/main.ts @@ -329,7 +329,7 @@ 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 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/' + '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/' ) .addTextArea((text) => text @@ -337,6 +337,7 @@ class ZoottelkeeperPluginSettingTab extends PluginSettingTab { .setValue(this.plugin.settings.foldersIncluded) .onChange(async (value) => { this.plugin.settings.foldersIncluded = value + .replace(/,/g,'\n') .split('\n') .map( folder=> { @@ -352,7 +353,7 @@ class ZoottelkeeperPluginSettingTab extends PluginSettingTab { 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, 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.' + '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.' ) .addTextArea((text) => text @@ -360,6 +361,7 @@ class ZoottelkeeperPluginSettingTab extends PluginSettingTab { .setValue(this.plugin.settings.foldersExcluded) .onChange(async (value) => { this.plugin.settings.foldersExcluded = value + .replace(/,/g,'\n') .split('\n') .map( folder=> { diff --git a/utils/isInSpecificFolder.ts b/utils/isInSpecificFolder.ts index d6170b7..ab7523f 100644 --- a/utils/isInSpecificFolder.ts +++ b/utils/isInSpecificFolder.ts @@ -11,7 +11,7 @@ export const isInDisAllowedFolder = (settings: ZoottelkeeperPluginSettings, inde export const isInSpecificFolder = (settings: ZoottelkeeperPluginSettings, indexFilePath: string, folderType: string): boolean => { - return !!settings[folderType].split('\n').find((folder: any) => { + 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('/'); From 07eb2956b1230a971dbe48772ec6a2e62fb4a718 Mon Sep 17 00:00:00 2001 From: Akos Balasko Date: Thu, 24 Mar 2022 18:43:13 +0100 Subject: [PATCH 3/3] versions and readme updated --- README.md | 26 ++++++++++++++++++++++++++ manifest.json | 2 +- package.json | 2 +- versions.json | 3 ++- 4 files changed, 30 insertions(+), 3 deletions(-) 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/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/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