diff --git a/src/core/Templater.ts b/src/core/Templater.ts index 6e14bc98..0cda685a 100644 --- a/src/core/Templater.ts +++ b/src/core/Templater.ts @@ -138,18 +138,15 @@ export class Templater { const extension = template instanceof TFile ? template.extension || "md" : "md"; - const created_note = await errorWrapper( - async () => - app.vault.create( - normalizePath( - `${folder?.path ?? ""}/${ - filename ?? "Untitled" - }.${extension}` - ), - "" + const created_note = await errorWrapper(async () => { + const path = app.vault.getAvailablePath( + normalizePath( + `${folder?.path ?? ""}/${filename ?? "Untitled"}` ), - `Couldn't create ${extension} file.` - ); + extension + ); + return app.vault.create(path, ""); + }, `Couldn't create ${extension} file.`); if (created_note == null) { await this.end_templater_task(); diff --git a/src/types.ts b/src/types.ts index 30d4cc9b..0943aeab 100644 --- a/src/types.ts +++ b/src/types.ts @@ -8,6 +8,7 @@ declare module "obsidian" { interface Vault { getConfig: (key: string) => string; exists: (path: string) => Promise; + getAvailablePath: (path: string, extension: string) => string; } interface DataAdapter {