Skip to content

Commit

Permalink
Merge pull request #67 from akosbalasko/feat-star-exclude-include-sub…
Browse files Browse the repository at this point in the history
…dirs
  • Loading branch information
akosbalasko authored Mar 24, 2022
2 parents a6025d4 + 07eb295 commit c09853c
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 13 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
47 changes: 38 additions & 9 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -255,13 +256,21 @@ export default class ZoottelkeeperPlugin extends Plugin {
return `${parentPath}${this.settings.indexPrefix}${parentName}.md`;
};

removeDisallowedFoldersIndexes = async (indexFiles: Set<string>): Promise<void> => {
for (const folder of this.settings.foldersExcluded.split('\n').map(f=> f.trim())){
const innerIndex = this.getInnerIndexFilePath(folder);
indexFiles.delete(innerIndex);
}
}

cleanDisallowedFolders = async (): Promise<void> => {
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();
Expand Down Expand Up @@ -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/ <enter> 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/* <enter> 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/ <enter> 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();
})
);
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
7 changes: 6 additions & 1 deletion utils/isInSpecificFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('/');
})
}

3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit c09853c

Please sign in to comment.