Skip to content

Commit

Permalink
fix the folder exclusion logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Diomede committed May 23, 2021
1 parent e4fddd7 commit b1ed3da
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
"@rollup/plugin-commonjs": "^18.0.0",
"@rollup/plugin-node-resolve": "^11.2.1",
"@rollup/plugin-typescript": "^8.2.1",
"@types/lodash": "^4.14.170",
"@types/node": "^14.14.37",
"obsidian": "^0.12.0",
"rollup": "^2.32.1",
"tslib": "^2.2.0",
"typescript": "^4.2.4"
},
"dependencies": {
"liquidjs": "^9.25.0"
"liquidjs": "^9.25.0",
"lodash": "^4.17.21"
}
}
6 changes: 5 additions & 1 deletion suggest/template-suggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ export default class TemplateSuggest extends CodeMirrorSuggest<ITemplateCompleti
getTemplateSuggestions(inputStr: string): ITemplateCompletion[] {
// find the list of files
// TODO: filter before returning all the files
const templates = getTFilesFromFolder(this.app, this.plugin.settings.templatesFolder, this.plugin.settings.excludeFolders.split(','));
const {
templatesFolder,
excludeFolders
} = this.plugin.settings;
const templates = getTFilesFromFolder(this.app, templatesFolder, excludeFolders.split(','));
return templates
.map(file => ({ label: file.basename, file: file }))
.filter((items) => items.label.toLowerCase().startsWith(inputStr));
Expand Down
3 changes: 2 additions & 1 deletion utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { App, normalizePath, TAbstractFile, TFile, TFolder, Vault } from "obsidian";
import { compact } from 'lodash';

export function getTFilesFromFolder(app: App, folderName: string, subfoldersToExclude?: string[]): Array<TFile> {
folderName = normalizePath(folderName);
let folder = app.vault.getAbstractFileByPath(folderName);
if (!folder) throw new Error(`${folderName} folder doesn't exist`);
if (!(folder instanceof TFolder)) throw new Error(`${folderName} is a file, not a folder`);

const foldersToExclude = subfoldersToExclude
const foldersToExclude = subfoldersToExclude && compact(subfoldersToExclude).length > 0
? subfoldersToExclude.map(subfolder => [folderName,subfolder].join('/'))
: [];

Expand Down

0 comments on commit b1ed3da

Please sign in to comment.