refacotr(editor): reorder create-today-journal condition, avoid file reading

This commit is contained in:
Andelf
2023-08-24 16:13:39 +08:00
parent 97a20276f4
commit ebc8e8171f

View File

@@ -836,19 +836,19 @@
(config/get-file-extension format))
repo-dir (config/get-repo-dir repo)
template (state/get-default-journal-template)]
(p/let [file-exists? (fs/file-exists? repo-dir file-rpath)
file-content (when file-exists?
(fs/read-file repo-dir file-rpath))]
(when (and (db/page-empty? repo today-page)
(or (not file-exists?)
(and file-exists? (string/blank? file-content))))
(create! title {:redirect? false
:split-namespace? false
:create-first-block? (not template)
:journal? true})
(state/pub-event! [:journal/insert-template today-page])
(ui-handler/re-render-root!)
(plugin-handler/hook-plugin-app :today-journal-created {:title today-page}))))))))
(when (db/page-empty? repo today-page)
(p/let [file-exists? (fs/file-exists? repo-dir file-rpath)
file-content (when file-exists?
(fs/read-file repo-dir file-rpath))]
(when (or (not file-exists?)
(and file-exists? (string/blank? file-content)))
(create! title {:redirect? false
:split-namespace? false
:create-first-block? (not template)
:journal? true})
(state/pub-event! [:journal/insert-template today-page])
(ui-handler/re-render-root!)
(plugin-handler/hook-plugin-app :today-journal-created {:title today-page})))))))))
(defn open-today-in-sidebar
[]