Skip to content

Commit

Permalink
fix: creating file from template not auto-incrementing file name if f…
Browse files Browse the repository at this point in the history
…ile already exists
  • Loading branch information
Zachatoo committed Feb 13, 2024
1 parent 356dce9 commit 368e511
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/core/Templater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ declare module "obsidian" {
interface Vault {
getConfig: (key: string) => string;
exists: (path: string) => Promise<boolean>;
getAvailablePath: (path: string, extension: string) => string;
}

interface DataAdapter {
Expand Down

0 comments on commit 368e511

Please sign in to comment.