diff --git a/src/main.ts b/src/main.ts index d6cdd10..a654a7d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -65,13 +65,11 @@ export default class DendronTreePlugin extends Plugin { onunload() {} async createNote(baseName: string) { - const path = `${this.settings.vaultPath}/${baseName}.md`; - const title = generateNoteTitle( - NoteTree.getPathFromFileName(baseName).at(-1)!, - isUseTitleCase(baseName) - ); + const filePath = `${this.settings.vaultPath}/${baseName}.md`; + const notePath = NoteTree.getPathFromFileName(baseName); + const title = generateNoteTitle(notePath[notePath.length - 1], isUseTitleCase(baseName)); const template = getNoteTemplate(title); - return await this.app.vault.create(path, template); + return await this.app.vault.create(filePath, template); } async createRootFolder() { diff --git a/src/note.ts b/src/note.ts index 1218cc7..c4cf00b 100644 --- a/src/note.ts +++ b/src/note.ts @@ -118,8 +118,7 @@ export class NoteTree { let currentNote: Note = this.root; if (!NoteTree.isRootPath(path)) - while (path.length > 0) { - const name = path.shift()!; + for (const name of path) { let note: Note | undefined = currentNote.findChildren(name); if (!note) { @@ -142,8 +141,7 @@ export class NoteTree { let currentNote: Note = this.root; - while (path.length > 0) { - const name = path.shift()!; + for (const name of path) { const found = currentNote.findChildren(name); if (!found) return undefined; currentNote = found;