Skip to content

Commit

Permalink
fix(journal): wrong save location for page name with two slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
andelf committed Oct 26, 2023
1 parent 8e7f067 commit 71f5601
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
19 changes: 13 additions & 6 deletions src/main/frontend/date.cljs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns frontend.date
"Date related utility fns"
"Journal date related utility fns"
(:require ["chrono-node" :as chrono]
[cljs-bean.core :as bean]
[cljs-time.coerce :as tc]
Expand Down Expand Up @@ -154,12 +154,17 @@
(journal-title-formatters)))

(defn normalize-journal-title
"Normalize journal title at best effort. Return nil if title is not a valid date"
"Normalize journal title at best effort. Return nil if title is not a valid date.
Return format: 20220812T000000"
[title]
(and title
(normalize-date (gp-util/capitalize-all title))))

(defn valid-journal-title?
"This is a loose rule, requires double check by journal-title->custom-format.
BUG: This also accepts strings like 3/4/5 as journal titles"
[title]
(boolean (normalize-journal-title title)))

Expand All @@ -176,6 +181,7 @@
(date-time-util/safe-journal-title-formatters (state/get-date-formatter))))

(defn journal-day->ts
"journal-day format yyyyMMdd"
[day]
(when day
(-> (tf/parse (tf/formatter "yyyyMMdd") (str day))
Expand All @@ -185,20 +191,21 @@
[journal-title]
(journal-title-> journal-title #(tc/to-long %)))

(def default-journal-title-formatter (tf/formatter "yyyy_MM_dd"))
(def default-journal-filename-formatter (tf/formatter "yyyy_MM_dd"))

(defn journal-title->default
"Journal title to filename format"
[journal-title]
(let [formatter (if-let [format (state/get-journal-file-name-format)]
(tf/formatter format)
default-journal-title-formatter)]
default-journal-filename-formatter)]
(journal-title-> journal-title #(tf/unparse formatter %))))

(defn date->file-name
[date]
(let [formatter (if-let [format (state/get-journal-file-name-format)]
(tf/formatter format)
default-journal-title-formatter)]
default-journal-filename-formatter)]
(tf/unparse formatter date)))

(defn journal-title->custom-format
Expand Down Expand Up @@ -229,4 +236,4 @@
:LemonRenewsAt "2024-04-11T07:28:00.000000Z",
:LemonEndsAt nil,
:LemonStatus "active"}]
(->> info :LemonRenewsAt (tf/parse iso-parser) (< (js/Date.)))))
(->> info :LemonRenewsAt (tf/parse iso-parser) (< (js/Date.)))))
5 changes: 3 additions & 2 deletions src/main/frontend/modules/file/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@
whiteboard-page? (model/whiteboard-page? page-block)
format (if whiteboard-page? "edn" format)
journal-page? (date/valid-journal-title? title)
journal-title (date/normalize-journal-title title)
filename (if (and journal-page? (not (string/blank? journal-title)))
journal-title (date/journal-title->custom-format title)
journal-page? (and journal-page? (not (string/blank? journal-title)))
filename (if journal-page?
(date/date->file-name journal-title)
(-> (or (:block/original-name page-block) (:block/name page-block))
(fs-util/file-name-sanity)))
Expand Down

0 comments on commit 71f5601

Please sign in to comment.