瀏覽代碼

fix(journal): wrong save location for page name with two slashes

Fix #10219
Andelf 2 年之前
父節點
當前提交
71f5601301
共有 2 個文件被更改,包括 16 次插入8 次删除
  1. 13 6
      src/main/frontend/date.cljs
  2. 3 2
      src/main/frontend/modules/file/core.cljs

+ 13 - 6
src/main/frontend/date.cljs

@@ -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]
@@ -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)))
 
@@ -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))
@@ -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
@@ -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.)))))

+ 3 - 2
src/main/frontend/modules/file/core.cljs

@@ -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)))