mirror of
https://github.com/oen/liquid-template.git
synced 2026-07-22 05:40:24 +00:00
fix the folder exclusion logic
This commit is contained in:
parent
e4fddd7e99
commit
b1ed3daa3b
3 changed files with 10 additions and 3 deletions
|
|
@ -14,6 +14,7 @@
|
|||
"@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",
|
||||
|
|
@ -21,6 +22,7 @@
|
|||
"typescript": "^4.2.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"liquidjs": "^9.25.0"
|
||||
"liquidjs": "^9.25.0",
|
||||
"lodash": "^4.17.21"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
3
utils.ts
3
utils.ts
|
|
@ -1,4 +1,5 @@
|
|||
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);
|
||||
|
|
@ -6,7 +7,7 @@ export function getTFilesFromFolder(app: App, folderName: string, subfoldersToEx
|
|||
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('/'))
|
||||
: [];
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue