Skip to content

Commit

Permalink
refactor: note path iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
levirs565 committed May 26, 2023
1 parent 7c9746a commit b544f6b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
10 changes: 4 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 2 additions & 4 deletions src/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down

0 comments on commit b544f6b

Please sign in to comment.