Browse Source

fix: Data Loss: serious bug in naming the journal md files

close #2578
Tienson Qin 4 years ago
parent
commit
e769c8f562

+ 3 - 1
src/main/frontend/components/page.cljs

@@ -431,7 +431,9 @@
 
            (when-not block?
              [:div
-              (when (text/namespace-page? route-page-name)
+              (when (and
+                     (not journal?)
+                     (text/namespace-page? route-page-name))
                 (hierarchy/structures route-page-name))
 
               ;; TODO: or we can lazy load them

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

@@ -56,8 +56,11 @@
    (state/get-date-formatter)))
 
 ;; (tf/parse (tf/formatter "dd.MM.yyyy") "2021Q4") => 20040120T000000
-(def safe-journal-title-formatters
-  (set ["yyyy-MM-dd" "yyyy_MM_dd" (state/get-date-formatter)]))
+(defn safe-journal-title-formatters
+  []
+  (->> [(state/get-date-formatter) "yyyy-MM-dd" "yyyy_MM_dd"]
+       (remove string/blank?)
+       distinct))
 
 (defn get-date-time-string
   ([]
@@ -191,7 +194,7 @@
 
 (defn journal-title->
   ([journal-title then-fn]
-   (journal-title-> journal-title then-fn (journal-title-formatters)))
+   (journal-title-> journal-title then-fn (safe-journal-title-formatters)))
   ([journal-title then-fn formatters]
    (when-not (string/blank? journal-title)
      (when-let [time (->> (map

+ 10 - 6
src/main/frontend/handler/page.cljs

@@ -57,10 +57,11 @@
       (util/format "\"%s\"" original-name)
       original-name)))
 
-(defn- build-page-tx [format properties page]
+(defn- build-page-tx [format properties page journal?]
   (when (:block/uuid page)
     (let [page-entity [:block/uuid (:block/uuid page)]
-          create-title-property? (util/create-title-property? (:block/name page))
+          create-title-property? (and (not journal?)
+                                      (util/create-title-property? (:block/name page)))
           page (if (seq properties) (assoc page :block/properties properties) page)]
       (cond
         (and (seq properties) create-title-property?)
@@ -78,7 +79,7 @@
 (defn create!
   ([title]
    (create! title {}))
-  ([title {:keys [redirect? create-first-block? format properties split-namespace?]
+  ([title {:keys [redirect? create-first-block? format properties split-namespace? journal?]
            :or   {redirect?           true
                   create-first-block? true
                   format              nil
@@ -98,11 +99,12 @@
              txs      (->> pages
                            ;; for namespace pages, only last page need properties
                            drop-last
-                           (mapcat #(build-page-tx format false %))
+                           (mapcat #(build-page-tx format nil % journal?))
                            (remove nil?))
-             last-txs (build-page-tx format properties (last pages))
+             last-txs (build-page-tx format properties (last pages) journal?)
              txs      (concat txs last-txs)]
 
+         ;; (util/pprint txs)
          (db/transact! txs)
 
          (when create-first-block?
@@ -593,7 +595,9 @@
             template (state/get-default-journal-template)]
         (when (db/page-empty? repo today-page)
           (create! title {:redirect? false
-                          :create-first-block? (not template)})
+                          :split-namespace? false
+                          :create-first-block? (not template)
+                          :journal? true})
           (when template
             (let [page (db/pull [:block/name today-page])]
              (editor-handler/insert-template!