diff --git a/src/main/frontend/components/settings.cljs b/src/main/frontend/components/settings.cljs index 9984a9f0dd..de1e25c07d 100644 --- a/src/main/frontend/components/settings.cljs +++ b/src/main/frontend/components/settings.cljs @@ -304,7 +304,12 @@ [:div.it.sm:grid.sm:grid-cols-3.sm:gap-4.sm:items-:div.it.sm:grid.sm:grid-cols-3.sm:gap-4.sm:items-start [:label.block.text-sm.font-medium.leading-5.opacity-70 {:for "custom_date_format"} - (t :settings-page/custom-date-format)] + (t :settings-page/custom-date-format) + (ui/tippy {:html (t :settings-page/custom-date-format-warning) + :class "tippy-hover ml-2" + :interactive true + :disabled false} + (svg/info))] [:div.mt-1.sm:mt-0.sm:col-span-2 [:div.max-w-lg.rounded-md [:select.form-select.is-small diff --git a/src/main/frontend/date.cljs b/src/main/frontend/date.cljs index 148bc4f9a2..07d6dfc5b9 100644 --- a/src/main/frontend/date.cljs +++ b/src/main/frontend/date.cljs @@ -43,7 +43,8 @@ "EEEE, MM/dd/yyyy" "EEEE, yyyy/MM/dd" "dd-MM-yyyy" - "dd.MM.yyyy" + ;; This tyle will mess up other date formats like "2022-08" "2022Q4" "2022/10" + ;; "dd.MM.yyyy" "MM/dd/yyyy" "MM-dd-yyyy" "MM_dd_yyyy" @@ -170,7 +171,8 @@ :minute "2-digit" :hourCycle "h23"})))) -(defn valid? +(defn normalize-date + "Given raw date string, return a normalized date string at best effort." [s] (some (fn [formatter] @@ -180,10 +182,15 @@ false))) (journal-title-formatters))) -(defn valid-journal-title? +(defn normalize-journal-title + "Normalize journal title at best effort. Return nil if title is not a valid date" [title] (and title - (valid? (gp-util/capitalize-all title)))) + (normalize-date (gp-util/capitalize-all title)))) + +(defn valid-journal-title? + [title] + (boolean (normalize-journal-title title))) (defn journal-title-> ([journal-title then-fn] diff --git a/src/main/frontend/dicts.cljc b/src/main/frontend/dicts.cljc index 0155c6cec2..2484f8c3a9 100644 --- a/src/main/frontend/dicts.cljc +++ b/src/main/frontend/dicts.cljc @@ -211,6 +211,7 @@ :settings-page/disable-sentry "Send usage data and diagnostics to Logseq" :settings-page/preferred-outdenting "Logical outdenting" :settings-page/custom-date-format "Preferred date format" + :settings-page/custom-date-format-warning "Re-index required! Existing journal references would be broken!" :settings-page/preferred-file-format "Preferred file format" :settings-page/preferred-workflow "Preferred workflow" :settings-page/preferred-pasting-file "Preferred pasting file" diff --git a/src/main/frontend/format/block.cljs b/src/main/frontend/format/block.cljs index f3bfb07674..6b42d74bd7 100644 --- a/src/main/frontend/format/block.cljs +++ b/src/main/frontend/format/block.cljs @@ -52,7 +52,7 @@ and handles unexpected failure." ([block] (some->> block str - date/valid? + date/normalize-date (tf/unparse date/custom-formatter)))) (defn normalize-block diff --git a/src/main/frontend/handler/external.cljs b/src/main/frontend/handler/external.cljs index d4bd91c502..c4dbcd51d9 100644 --- a/src/main/frontend/handler/external.cljs +++ b/src/main/frontend/handler/external.cljs @@ -55,7 +55,7 @@ :update-db? false :update-status? false :finish-handler finish-handler})) - (let [journal-pages-tx (let [titles (filter date/valid-journal-title? titles)] + (let [journal-pages-tx (let [titles (filter date/normalize-journal-title titles)] (map (fn [title] (let [day (date/journal-title->int title) diff --git a/src/test/frontend/db/name_sanity_test.cljs b/src/test/frontend/db/name_sanity_test.cljs index 3c97bce923..86465a111d 100644 --- a/src/test/frontend/db/name_sanity_test.cljs +++ b/src/test/frontend/db/name_sanity_test.cljs @@ -99,7 +99,7 @@ :old-title "aa?#.bbb.ccc", :changed-title "aa?#/bbb/ccc"})) -(deftest rename-tests +(deftest rename-tests-l2t ;; z: new title structure; x: old ver title; y: title property (if available) (are [x y z] (= z (#'conversion-handler/calc-rename-target-impl :legacy :triple-lowbar x y)) "aaBBcc" "aabbcc" nil @@ -137,6 +137,10 @@ :target "adbcde___aks___sdf", :old-title "adbcde/aks/sdf", :changed-title "adbcde/aks/sdf"} + "aaa%2Fbbb%2Fccc" "aaa/bbb/ccc" {:status :informal, + :target "aaa___bbb___ccc", + :old-title "aaa/bbb/ccc", + :changed-title "aaa/bbb/ccc"} "CON" "CON" {:status :informal, :target "CON___", :old-title "CON", diff --git a/src/test/frontend/format/block_test.cljs b/src/test/frontend/format/block_test.cljs index 2958a7775b..8ce414eecd 100644 --- a/src/test/frontend/format/block_test.cljs +++ b/src/test/frontend/format/block_test.cljs @@ -1,6 +1,7 @@ (ns frontend.format.block-test (:require [cljs.test :refer [deftest testing are]] - [frontend.format.block :as block])) + [frontend.format.block :as block] + [frontend.date :as date])) (deftest test-normalize-date (testing "normalize date values" @@ -49,3 +50,23 @@ "-%" "-%"))) + +(deftest test-normalize-journal-title + (testing "normalize journal titles" + (are [x y] (let [f #(-> % date/normalize-journal-title str)] + (= (f x) y)) + "Aug 12th, 2022" + "20220812T000000" + + "2022-08-12" + "20220812T000000" + + "2022-10" + "" + + "2022Q4" + "" + + "2022-08" + ""))) +