oen_liquid-template/utils.ts
Diomede b490f21770 Initial POC
POC for a plugin that allows you to write templates with LiquidJS tags
2021-05-18 21:39:08 +02:00

21 lines
695 B
TypeScript

import { App, normalizePath, TAbstractFile, TFile, TFolder, Vault } from "obsidian";
export function getTFilesFromFolder(app: App, folderName: 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`);
let files: Array<TFile> = [];
Vault.recurseChildren(folder, (file: TAbstractFile) => {
if (file instanceof TFile) {
files.push(file);
}
});
files.sort((a, b) => {
return a.basename.localeCompare(b.basename);
});
return files;
}