Skip to content

Commit

Permalink
feat: star implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
akosbalasko committed Mar 24, 2022
1 parent a6025d4 commit bb47b4d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
45 changes: 36 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,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/ <enter> 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/* <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
.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/ <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
.split('\n')
.map(
folder=> {
const f = folder.trim();
return f.startsWith('/')
? f.substring(1)
: f
})
.join('\n');;
await this.plugin.saveSettings();
})
);
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].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('/');
})
}

0 comments on commit bb47b4d

Please sign in to comment.