Просмотр исходного кода

Merge branch 'master' into zotero/poc

Junyu Zhan 4 лет назад
Родитель
Сommit
06b80fe4c7

+ 1 - 1
package.json

@@ -82,7 +82,7 @@
         "ignore": "^5.1.8",
         "is-svg": "4.2.2",
         "jszip": "^3.5.0",
-        "mldoc": "0.9.1",
+        "mldoc": "0.9.2",
         "path": "^0.12.7",
         "pixi-graph-fork": "^0.1.3",
         "posthog-js": "^1.10.2",

+ 1 - 4
src/main/frontend/components/export.cljs

@@ -32,10 +32,7 @@
           (t :export-json)]]
         [:li.mb-4
          [:a.font-medium {:on-click #(export/export-repo-as-roam-json! current-repo)}
-          (t :export-roam-json)]]
-        [:li.mb-4
-         [:a.font-medium {:on-click #(export/convert-repo-markdown-v2! current-repo)}
-          (t :convert-markdown)]]]
+          (t :export-roam-json)]]]
        [:a#download-as-edn-v2.hidden]
        [:a#download-as-json-v2.hidden]
        [:a#download-as-roam-json.hidden]

+ 1 - 8
src/main/frontend/components/header.cljs

@@ -22,8 +22,7 @@
             [frontend.handler.web.nfs :as nfs]
             [frontend.mixins :as mixins]
             [goog.dom :as gdom]
-            [goog.object :as gobj]
-            [frontend.handler.migrate :as migrate]))
+            [goog.object :as gobj]))
 
 (rum/defc logo < rum/reactive
   [{:keys [white? electron-mac?]}]
@@ -138,12 +137,6 @@
           :options {:href (rfe/href :import)}
           :icon svg/import-sm})
 
-       (when (and current-repo
-                  (not (:markdown/version (state/get-config))))
-         {:title "Convert to more standard Markdown"
-          :options {:on-click (fn [] (migrate/show-convert-notification! current-repo))}
-          :icon svg/import-sm})
-
        {:title [:div.flex-row.flex.justify-between.items-center
                 [:span (t :join-community)]]
         :options {:href "https://discord.gg/KpN4eHY"

+ 2 - 2
src/main/frontend/config.cljs

@@ -83,7 +83,7 @@
                                 (set))]
     (set/union
      config-formats
-     #{:gif :svg :jpeg :ico :png :jpg :bmp})))
+     #{:gif :svg :jpeg :ico :png :jpg :bmp :webp})))
 
 (def html-render-formats
   #{:adoc :asciidoc})
@@ -167,7 +167,7 @@
 
 (defn get-highlight
   [format]
-  "^^")
+  "==")
 
 (defn get-code
   [format]

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

@@ -55,6 +55,10 @@
      "yyyy年MM月dd日"}
    (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 get-date-time-string
   ([]
    (get-date-time-string (t/now)))
@@ -188,10 +192,15 @@
 (defn journal-title->
   [journal-title then-fn]
   (when-not (string/blank? journal-title)
-    (when-let [time (try
-                      (tf/parse (tf/formatter (state/get-date-formatter)) (util/capitalize-all journal-title))
-                      (catch js/Error _e
-                        nil))]
+    (when-let [time (->> (map
+                           (fn [formatter]
+                             (try
+                               (tf/parse (tf/formatter formatter) (util/capitalize-all journal-title))
+                               (catch js/Error _e
+                                 nil)))
+                           safe-journal-title-formatters)
+                         (filter some?)
+                         first)]
       (then-fn time))))
 
 (defn journal-title->int

+ 1 - 5
src/main/frontend/db.cljs

@@ -4,7 +4,6 @@
             [frontend.db-schema :as db-schema]
             [frontend.db.conn :as conn]
             [frontend.db.default :as default-db]
-            [frontend.db.migrate :as migrate]
             [frontend.db.model]
             [frontend.db.query-custom]
             [frontend.db.query-react]
@@ -135,9 +134,7 @@
 
 (defn restore!
   [{:keys [repos] :as me} old-db-schema restore-config-handler]
-  (let [logged? (:name me)
-        ;; TODO: switch to use the db version
-        old-db? (and old-db-schema (not (:block/name old-db-schema)))]
+  (let [logged? (:name me)]
     (doall
      (for [{:keys [url]} repos]
        (let [repo url]
@@ -148,7 +145,6 @@
                  stored (idb/get-item db-name)
                  _ (if stored
                      (let [stored-db (string->db stored)
-                           stored-db (if old-db? (migrate/migrate url stored-db) stored-db)
                            attached-db (d/db-with stored-db (concat
                                                              [(me-tx stored-db me)]
                                                              default-db/built-in-pages))]

+ 7 - 5
src/main/frontend/extensions/srs.cljs

@@ -629,8 +629,10 @@
 ;; handlers
 (defn make-block-a-card!
   [block-id]
-  (when-let [content (:block/content (db/entity [:block/uuid block-id]))]
-    (editor-handler/save-block!
-     (state/get-current-repo)
-     block-id
-     (str (string/trim content) " #" card-hash-tag))))
+  (when-let [block (db/entity [:block/uuid block-id])]
+    (when-let [content (:block/content block)]
+      (let [content (property/remove-built-in-properties (:block/format block) content)]
+        (editor-handler/save-block!
+         (state/get-current-repo)
+         block-id
+         (str (string/trim content) " #" card-hash-tag))))))

+ 3 - 3
src/main/frontend/handler/editor.cljs

@@ -849,7 +849,7 @@
                      (when-let [sibling-block-id (dom/attr sibling-block "blockid")]
                        (when-let [block (db/pull repo '[*] [:block/uuid (uuid sibling-block-id)])]
                          (let [original-content (util/trim-safe (:block/content block))
-                               new-value (str original-content " " (string/triml value))
+                               new-value (str (property/remove-built-in-properties format original-content) " " (string/triml value))
                                tail-len (count (string/triml value))
                                pos (max
                                     (if original-content
@@ -1518,8 +1518,8 @@
    "*" "*"
    "_" "_"
    "^" "^"
+   "=" "="
    ;; ":" ":"                              ; TODO: only properties editing and org mode tag
-
    })
 
 (def reversed-autopair-map
@@ -1527,7 +1527,7 @@
           (keys autopair-map)))
 
 (defonce autopair-when-selected
-  #{"^" "_"})
+  #{"^" "_" "="})
 
 (def delete-map
   (assoc autopair-map

+ 2 - 14
src/main/frontend/handler/events.cljs

@@ -12,7 +12,6 @@
             [frontend.components.encryption :as encryption]
             [frontend.fs.nfs :as nfs]
             [frontend.db.conn :as conn]
-            [frontend.handler.migrate :as migrate]
             [frontend.extensions.srs :as srs]
             [frontend.db-schema :as db-schema]
             [frontend.db :as db]
@@ -60,21 +59,10 @@
   ;; add ast/version to db
   (let [conn (conn/get-conn repo false)
         ast-version (d/datoms @conn :aevt :ast/version)]
-    (db/set-key-value repo :ast/version db-schema/ast-version))
-
-  ;; markdown convert notification
-  (js/setTimeout
-   (fn []
-     (when (not (:markdown/version (state/get-config)))
-       (migrate/show-convert-notification! repo)))
-   5000))
+    (db/set-key-value repo :ast/version db-schema/ast-version)))
 
 (defmethod handle :graph/migrated [[_ repo]]
-  (js/setTimeout
-   (fn []
-     (when (not (:markdown/version (state/get-config)))
-       (migrate/show-migrated-notification! repo)))
-   5000))
+  (js/alert "Graph migrated."))
 
 (defn get-local-repo
   []

+ 0 - 15
src/main/frontend/handler/export.cljs

@@ -581,21 +581,6 @@
                   (.setAttribute anchor "download" path)
                   (.click anchor))))))))))
 
-(defn convert-repo-markdown-v2!
-  [repo]
-  (when repo
-    (when-let [files (get-md-file-contents repo)]
-      (let [zip-file-name (-> (string/replace repo config/local-db-prefix "")
-                              (string/replace #"^/+" ""))
-            zip-file-name (str zip-file-name
-                               "_markdown_"
-                               (quot (util/time-ms) 1000))]
-        (p/let [zipfile (zip/make-zip zip-file-name files repo)]
-          (when-let [anchor (gdom/getElement "convert-markdown-to-unordered-list-or-heading")]
-            (.setAttribute anchor "href" (js/window.URL.createObjectURL zipfile))
-            (.setAttribute anchor "download" (.-name zipfile))
-            (.click anchor)))))))
-
 (defn- dissoc-properties [m ks]
   (if (:block/properties m)
     (update m :block/properties

+ 0 - 88
src/main/frontend/handler/migrate.cljs

@@ -1,88 +0,0 @@
-(ns frontend.handler.migrate
-  (:require [frontend.handler.export :as export]
-            [frontend.handler.file :as file]
-            [frontend.handler.repo :as repo]
-            [frontend.handler.config :as config-handler]
-            [frontend.handler.notification :as notification]
-            [frontend.handler.web.nfs :as nfs-handler]
-            [frontend.handler.user :as user-handler]
-            [frontend.ui :as ui]
-            [frontend.state :as state]
-            [promesa.core :as p]
-            [clojure.string :as string]))
-
-(defn convert-md-files!
-  [repo]
-  (when repo
-    (let [files (export/get-md-file-contents repo)]
-      (when (seq files)
-        (-> (p/all (for [[path content] files]
-                     (file/alter-file repo path content {:add-history? false
-                                                         :reset? false})))
-            (p/then (fn []
-                      (p/let [_ (repo/push repo {:commit-message "Converted to new Markdown syntax!"})
-                              _ (repo/re-index! nfs-handler/rebuild-index!)]
-                        (js/setTimeout #(config-handler/set-config! :markdown/version 2) 2000)
-
-                        (notification/show!
-                         [:div
-                          [:p "All markdown files have been converted to the new Markdown syntax successfully!"]]
-                         :success
-                         false))))
-            (p/catch (fn [e]
-                       (throw e))))))))
-
-(defn show-convert-notification!
-  [repo]
-  (notification/show!
-   [:div
-    [:h1 (str "Graph: " repo)]
-
-    [:p "Previously Logseq uses `#` Markdown heading as outliner bullets, since beta, we've changed to use more standard `-` unordered list as outliner bullets."]
-
-    [:div
-     [:p.mt-2 "If you've converted this graph before, click on this button so that you won't see this notification again."]
-     (ui/button "Yes, it's already converted!"
-       :on-click (fn []
-                   (notification/clear-all!)
-                   (config-handler/set-config! :markdown/version 2)))]
-
-    [:hr]
-
-    [:p "Let's make a backup first."]
-    [:p
-     (ui/button "Download this graph"
-       :on-click (fn []
-                   (export/export-repo-as-zip! repo)))]
-
-    [:div
-     [:b "Make sure you've downloaded this graph! Now let's convert the Markdown files."]
-     [:p
-      (ui/button "Start to convert!"
-        :on-click (fn []
-                    (notification/clear-all!)
-                    (convert-md-files! repo)))]]]
-   :warning
-   false))
-
-(defn show-migrated-notification!
-  [repo]
-  (notification/show!
-   [:div
-    [:h1 (str "Graph: " repo)]
-
-    [:p "Previously Logseq uses `#` Markdown heading as outliner bullets, since beta, we've changed to use more standard `-` unordered list as outliner bullets."]
-
-    [:hr]
-
-    [:p "1. Let's make a backup first."]
-    [:p
-     (ui/button "Download this graph"
-       :on-click (fn [] (export/export-git-repo-as-zip! repo)))]
-
-    [:div
-     [:p [:b "2. Make sure you've downloaded this graph! Now click this button to logout and login again."]]
-     (ui/button "Logout"
-       :on-click user-handler/sign-out!)]]
-   :warning
-   false))

+ 4 - 4
yarn.lock

@@ -6165,10 +6165,10 @@ mkdirp@^0.5.0, mkdirp@^0.5.4, mkdirp@~0.5.1:
   dependencies:
     minimist "^1.2.5"
 
[email protected].1:
-  version "0.9.1"
-  resolved "https://registry.yarnpkg.com/mldoc/-/mldoc-0.9.1.tgz#dfcdcf52614a27ce83b9318c551246398e13f0e7"
-  integrity sha512-4BL8Fu6+izd9iJ3JhqEU57K9W8MHUD29V51eOXa/pTpmkXi1GFSy0c9nYLkd8KjAPkI6nFVmjl7A9rcfbGe+/g==
[email protected].2:
+  version "0.9.2"
+  resolved "https://registry.yarnpkg.com/mldoc/-/mldoc-0.9.2.tgz#0d88a049bb9564a1567134178b2dea9196f30148"
+  integrity sha512-e1JFKKkX6IYHFP8XwN0pqcEn2L8biVHWXGUyaUU8RHsCq2poN1fPIAZ5waosS4EffC+CQk68PycEhCobYwbndA==
   dependencies:
     yargs "^12.0.2"