From 2a811b344e5b4ca3fe0c629e4d46c211739c1a69 Mon Sep 17 00:00:00 2001 From: zoreet Date: Wed, 20 Dec 2023 15:55:09 +0100 Subject: [PATCH] fix for empty files; ugh --- src/HabitTracker.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/HabitTracker.ts b/src/HabitTracker.ts index 0329c5b..0851164 100644 --- a/src/HabitTracker.ts +++ b/src/HabitTracker.ts @@ -235,12 +235,14 @@ export default class HabitTracker { } this.app.fileManager.processFrontMatter(file, (frontmatter) => { - if(isTicked === 'true') { - frontmatter['entries'] = frontmatter['entries'].filter((e) => e !== date); + let entries = frontmatter["entries"] || []; + if (isTicked === "true") { + entries = entries.filter((e) => e !== date); } else { - frontmatter['entries'].push(date); - frontmatter['entries'].sort(); + entries.push(date); + entries.sort(); } + frontmatter["entries"] = entries; }); this.renderHabit(file.path, await this.getHabitEntries(file.path));