Bladeren bron

fix: mutual block reference

Also, :block/title shouldn't replace non-page block id references
because it could be recursive.
Tienson Qin 5 maanden geleden
bovenliggende
commit
3d9cb9238c

+ 4 - 1
deps/db/src/logseq/db/common/entity_plus.cljc

@@ -11,6 +11,7 @@
             [datascript.core :as d]
             [datascript.impl.entity :as entity :refer [Entity]]
             [logseq.common.util.date-time :as date-time-util]
+            [logseq.db.common.entity-util :as common-entity-util]
             [logseq.db.frontend.entity-util :as entity-util]
             [logseq.db.frontend.property :as db-property]))
 
@@ -95,7 +96,9 @@
          (when-not (and search? (keyword-identical? k :block/title))
            (get (.-kv e) k))
          (let [result (lookup-entity e k default-value)
-               refs (:block/refs e)
+               ;; Replace title for pages only, otherwise it'll recursively
+               ;; replace block id refs if there're cycle references of blocks
+               refs (filter common-entity-util/page? (:block/refs e))
                result' (if (and (string? result) refs)
                          ;; FIXME: Correct namespace dependencies instead of resolve workaround
                          ((resolve 'logseq.db.frontend.content/id-ref->title-ref) result refs search?)

+ 2 - 1
src/main/frontend/commands.cljs

@@ -13,6 +13,7 @@
             [frontend.handler.notification :as notification]
             [frontend.handler.plugin :as plugin-handler]
             [frontend.handler.property.file :as property-file]
+            [frontend.ref :as ref]
             [frontend.search :as search]
             [frontend.state :as state]
             [frontend.util :as util]
@@ -434,7 +435,7 @@
          ["Draw" (fn []
                    (let [file (draw/file-name)
                          path (str common-config/default-draw-directory "/" file)
-                         text (page-ref/->page-ref path)]
+                         text (ref/->page-ref path)]
                      (p/let [_ (draw/create-draw-with-default-content path)]
                        (println "draw file created, " path))
                      text)) "Draw a graph with Excalidraw"])

+ 23 - 21
src/main/frontend/components/block.cljs

@@ -28,8 +28,8 @@
             [frontend.db :as db]
             [frontend.db-mixins :as db-mixins]
             [frontend.db.async :as db-async]
-            [frontend.db.model :as model]
             [frontend.db.file-based.model :as file-model]
+            [frontend.db.model :as model]
             [frontend.extensions.highlight :as highlight]
             [frontend.extensions.latex :as latex]
             [frontend.extensions.lightbox :as lightbox]
@@ -46,8 +46,8 @@
             [frontend.handler.db-based.property :as db-property-handler]
             [frontend.handler.dnd :as dnd]
             [frontend.handler.editor :as editor-handler]
-            [frontend.handler.file-based.editor :as file-editor-handler]
             [frontend.handler.export.common :as export-common-handler]
+            [frontend.handler.file-based.editor :as file-editor-handler]
             [frontend.handler.file-based.property.util :as property-util]
             [frontend.handler.file-sync :as file-sync]
             [frontend.handler.notification :as notification]
@@ -62,6 +62,7 @@
             [frontend.mobile.util :as mobile-util]
             [frontend.modules.outliner.tree :as tree]
             [frontend.modules.shortcut.utils :as shortcut-utils]
+            [frontend.ref :as ref]
             [frontend.security :as security]
             [frontend.state :as state]
             [frontend.template :as template]
@@ -905,10 +906,8 @@
 
 (rum/defc invalid-node-ref
   [id]
-  (let [db-based? (config/db-based-graph? (state/get-current-repo))
-        ->ref (if db-based? page-ref/->page-ref block-ref/->block-ref)]
-    [:span.warning.mr-1 {:title "Node ref invalid"}
-     (->ref (str id))]))
+  [:span.warning.mr-1 {:title "Node ref invalid"}
+   (ref/->block-ref (str id))])
 
 (defn inline-text
   ([format v]
@@ -1260,9 +1259,9 @@
                          :render render})))
 
 (rum/defc block-reference-aux < rum/reactive db-mixins/query
-  [config block-id label]
-  (let [block (db/entity [:block/uuid block-id])
-        db-id (:db/id block)
+  [config block label]
+  (let [db-id (:db/id block)
+        block-id (:block/uuid block)
         block (when db-id (db/sub-block db-id))
         block-type (keyword (pu/lookup block :logseq.property/ls-type))
         hl-type (pu/lookup block :logseq.property.pdf/hl-type)
@@ -1332,6 +1331,7 @@
         (log/warn :invalid-node block)
         (invalid-node-ref block-id)))))
 
+;; FIXME: allow cycle refs including 3 or more blocks
 (rum/defc block-reference
   [config id label]
   (let [block-id (and id (if (uuid? id) id (parse-uuid id)))
@@ -1344,11 +1344,10 @@
                                            :skip-refresh? true})]
          (set-block! block)))
      [])
-    (if (and block-id (= (:block/uuid (:block config)) block-id))
-      [:span.warning.text-sm "Self reference"]
-      (if block
-        (block-reference-aux config block-id label)
-        (invalid-node-ref block-id)))))
+    (if block
+      [:div.inline-flex.gap-1
+       (block-reference-aux config block label)]
+      (invalid-node-ref block-id))))
 
 (defn- render-macro
   [config name arguments macro-content format]
@@ -1533,7 +1532,7 @@
           (image-link config url page nil metadata full_text)
           (let [label* (if (seq (mldoc/plain->text label)) label nil)]
             (if (and (string? page) (string/blank? page))
-              [:span (page-ref/->page-ref page)]
+              [:span (ref/->page-ref page)]
               (page-reference (:html-export? config) page config label*)))))
 
       ["Embed_data" src]
@@ -2872,9 +2871,12 @@
         format (if db-based? :markdown (or (:block/format block) :markdown))
         pre-block? (when-not db-based? (:block/pre-block? block))
         collapsed? (:collapsed? config)
-        content (if db-based?
-                  (:block/raw-title block)
-                  (property-util/remove-built-in-properties format (:block/raw-title block)))
+        content* (if db-based?
+                   (:block/raw-title block)
+                   (property-util/remove-built-in-properties format (:block/raw-title block)))
+        content (if-let [source-id (and (:block-ref? config) (:block/uuid (:block config)))]
+                  (string/replace content* (ref/->block-ref source-id) "")
+                  content*)
         block (merge block (block/parse-title-and-body uuid format pre-block? content))
         ast-body (:block.temp/ast-body block)
         ast-title (:block.temp/ast-title block)
@@ -3362,8 +3364,8 @@
   [^js e block *control-show? block-id doc-mode?]
   (let [mouse-moving? (not= (some-> @*block-last-mouse-event (.-clientY)) (.-clientY e))]
     (when (and mouse-moving?
-            (not @*dragging?)
-            (not= (:block/uuid block) (:block/uuid (state/get-edit-block))))
+               (not @*dragging?)
+               (not= (:block/uuid block) (:block/uuid (state/get-edit-block))))
       (.preventDefault e)
       (reset! *control-show? true)
       (when-let [parent (gdom/getElement block-id)]
@@ -3615,7 +3617,7 @@
          :on-mouse-enter (fn [e]
                            (block-mouse-over e block *control-show? block-id doc-mode?))
          :on-mouse-move (fn [e]
-                           (reset! *block-last-mouse-event e))
+                          (reset! *block-last-mouse-event e))
          :on-mouse-leave (fn [_e]
                            (block-mouse-leave *control-show? block-id doc-mode?))}
 

+ 3 - 8
src/main/frontend/components/content.cljs

@@ -19,6 +19,7 @@
             [frontend.handler.property :as property-handler]
             [frontend.handler.property.util :as pu]
             [frontend.modules.shortcut.core :as shortcut]
+            [frontend.ref :as ref]
             [frontend.state :as state]
             [frontend.ui :as ui]
             [frontend.util :as util]
@@ -26,8 +27,6 @@
             [goog.dom :as gdom]
             [goog.object :as gobj]
             [logseq.common.util :as common-util]
-            [logseq.common.util.block-ref :as block-ref]
-            [logseq.common.util.page-ref :as page-ref]
             [logseq.db :as ldb]
             [logseq.shui.ui :as shui]
             [promesa.core :as p]
@@ -232,18 +231,14 @@
          (shui/dropdown-menu-item
           {:key      "Copy block ref"
            :on-click (fn [_e]
-                       (editor-handler/copy-block-ref! block-id
-                                                       (if db? page-ref/->page-ref block-ref/->block-ref)))}
+                       (editor-handler/copy-block-ref! block-id ref/->block-ref))}
           (t :content/copy-block-ref))
 
          (when-not db?
            (shui/dropdown-menu-item
             {:key      "Copy block embed"
              :on-click (fn [_e]
-                         (editor-handler/copy-block-ref! block-id
-                                                         (if db?
-                                                           block-ref/->block-ref
-                                                           #(util/format "{{embed ((%s))}}" %))))}
+                         (editor-handler/copy-block-ref! block-id #(util/format "{{embed ((%s))}}" %)))}
             (t :content/copy-block-emebed)))
 
          ;; TODO Logseq protocol mobile support

+ 3 - 2
src/main/frontend/components/query/builder.cljs

@@ -7,12 +7,13 @@
             [frontend.db :as db]
             [frontend.db-mixins :as db-mixins]
             [frontend.db.async :as db-async]
-            [frontend.db.model :as db-model]
             [frontend.db.file-based.model :as file-model]
+            [frontend.db.model :as db-model]
             [frontend.db.query-dsl :as query-dsl]
             [frontend.handler.editor :as editor-handler]
             [frontend.handler.query.builder :as query-builder]
             [frontend.mixins :as mixins]
+            [frontend.ref :as ref]
             [frontend.state :as state]
             [frontend.ui :as ui]
             [frontend.util :as util]
@@ -466,7 +467,7 @@
       (str "Search: " clause)
 
       (= (keyword f) :page-ref)
-      (page-ref/->page-ref (second clause))
+      (ref/->page-ref (second clause))
 
       (contains? #{:tags :page-tags} (keyword f))
       (cond

+ 2 - 2
src/main/frontend/extensions/pdf/assets.cljs

@@ -19,12 +19,12 @@
             [frontend.handler.property :as property-handler]
             [frontend.handler.property.util :as pu]
             [frontend.handler.route :as route-handler]
+            [frontend.ref :as ref]
             [frontend.state :as state]
             [frontend.ui :as ui]
             [frontend.util :as util]
             [logseq.common.config :as common-config]
             [logseq.common.path :as path]
-            [logseq.common.util.block-ref :as block-ref]
             [logseq.publishing.db :as publish-db]
             [medley.core :as medley]
             [promesa.core :as p]
@@ -324,7 +324,7 @@
   (p/let [ref-block (ensure-ref-block! (state/get-current-pdf) highlight nil)]
     (when ref-block
       (util/copy-to-clipboard!
-       (block-ref/->block-ref (:block/uuid ref-block))
+       (ref/->block-ref (:block/uuid ref-block))
        :owner-window (pdf-windows/resolve-own-window viewer)))))
 
 (defn file-based-open-block-ref!

+ 2 - 2
src/main/frontend/extensions/zotero/handler.cljs

@@ -9,8 +9,8 @@
             [frontend.handler.editor :as editor-handler]
             [frontend.handler.notification :as notification]
             [frontend.handler.page :as page-handler]
+            [frontend.ref :as ref]
             [frontend.state :as state]
-            [logseq.common.util.page-ref :as page-ref]
             [promesa.core :as p]))
 
 ;; TODO: test
@@ -48,7 +48,7 @@
 (defn handle-command-zotero
   [id page-name]
   (state/clear-editor-action!)
-  (editor-handler/insert-command! id (page-ref/->page-ref page-name) nil {}))
+  (editor-handler/insert-command! id (ref/->page-ref page-name) nil {}))
 
 (defn- create-abstract-note!
   [page-name abstract-note]

+ 5 - 7
src/main/frontend/handler/dnd.cljs

@@ -1,15 +1,13 @@
 (ns frontend.handler.dnd
   "Provides fns for drag and drop"
-  (:require [frontend.config :as config]
-            [frontend.db :as db]
+  (:require [frontend.db :as db]
             [frontend.handler.block :as block-handler]
             [frontend.handler.editor :as editor-handler]
             [frontend.handler.property :as property-handler]
             [frontend.modules.outliner.op :as outliner-op]
             [frontend.modules.outliner.ui :as ui-outliner-tx]
+            [frontend.ref :as ref]
             [frontend.state :as state]
-            [logseq.common.util.block-ref :as block-ref]
-            [logseq.common.util.page-ref :as page-ref]
             [logseq.db :as ldb]))
 
 (defn move-blocks
@@ -27,15 +25,15 @@
     (cond
       ;; alt pressed, make a block-ref
       (and alt-key? (= (count blocks) 1))
-      (let [->ref (if (config/db-based-graph?) page-ref/->page-ref block-ref/->block-ref)]
+      (do
         (property-handler/file-persist-block-id! (state/get-current-repo) (:block/uuid first-block))
         (editor-handler/api-insert-new-block!
-         (->ref (:block/uuid first-block))
+         (ref/->block-ref (:block/uuid first-block))
          {:block-uuid (:block/uuid target-block)
           :sibling? (not nested?)
           :before? top?}))
 
-      ;; format mismatch
+;; format mismatch
       (and current-format target-format (not= current-format target-format))
       (state/pub-event! [:notification/show
                          {:content [:div "Those two pages have different formats."]

+ 23 - 20
src/main/frontend/handler/editor.cljs

@@ -8,8 +8,8 @@
             [frontend.date :as date]
             [frontend.db :as db]
             [frontend.db.async :as db-async]
-            [frontend.db.model :as db-model]
             [frontend.db.file-based.model :as file-model]
+            [frontend.db.model :as db-model]
             [frontend.db.utils :as db-utils]
             [frontend.diff :as diff]
             [frontend.extensions.pdf.utils :as pdf-utils]
@@ -20,6 +20,7 @@
             [frontend.handler.assets :as assets-handler]
             [frontend.handler.block :as block-handler]
             [frontend.handler.common :as common-handler]
+            [frontend.handler.common.editor :as editor-common-handler]
             [frontend.handler.db-based.editor :as db-editor-handler]
             [frontend.handler.export.html :as export-html]
             [frontend.handler.export.text :as export-text]
@@ -34,6 +35,7 @@
             [frontend.modules.outliner.op :as outliner-op]
             [frontend.modules.outliner.tree :as tree]
             [frontend.modules.outliner.ui :as ui-outliner-tx]
+            [frontend.ref :as ref]
             [frontend.search :as search]
             [frontend.state :as state]
             [frontend.template :as template]
@@ -67,8 +69,7 @@
             [logseq.outliner.property :as outliner-property]
             [logseq.shui.popup.core :as shui-popup]
             [promesa.core :as p]
-            [rum.core :as rum]
-            [frontend.handler.common.editor :as editor-common-handler]))
+            [rum.core :as rum]))
 
 ;; FIXME: should support multiple images concurrently uploading
 
@@ -1007,12 +1008,12 @@
           copy-str (some->> adjusted-blocks
                             (map (fn [{:keys [id level]}]
                                    (if (config/db-based-graph? (state/get-current-repo))
-                                     (str (string/join (repeat (dec level) "\t")) "- " (page-ref/->page-ref id))
+                                     (str (string/join (repeat (dec level) "\t")) "- " (ref/->page-ref id))
                                      (condp = (get block :block/format :markdown)
                                        :org
-                                       (str (string/join (repeat level "*")) " " (block-ref/->block-ref id))
+                                       (str (string/join (repeat level "*")) " " (ref/->block-ref id))
                                        :markdown
-                                       (str (string/join (repeat (dec level) "\t")) "- " (block-ref/->block-ref id))))))
+                                       (str (string/join (repeat (dec level) "\t")) "- " (ref/->block-ref id))))))
                             (string/join "\n\n"))]
       (set-blocks-id! (map :id blocks))
       (util/copy-to-clipboard! copy-str))))
@@ -1025,7 +1026,7 @@
                    (remove nil?))
           ids-str (if (config/db-based-graph? (state/get-current-repo))
                     (some->> ids
-                             (map (fn [id] (block-ref/->block-ref id)))
+                             (map (fn [id] (ref/->block-ref id)))
                              (string/join "\n\n"))
                     (some->> ids
                              (map (fn [id] (util/format "{{embed ((%s))}}" id)))
@@ -1390,7 +1391,7 @@
                                     {:block-id block-id})))
         text (:block/title block)
         content (if asset-block
-                  (string/replace text (page-ref/->page-ref (:block/uuid asset-block)) "")
+                  (string/replace text (ref/->page-ref (:block/uuid asset-block)) "")
                   (string/replace text full-text ""))]
     (save-block! repo block content)
     (when (and local? delete-local?)
@@ -1497,7 +1498,7 @@
            (let [entity (first entities)]
              (insert-command!
               id
-              (page-ref/->page-ref (:block/uuid entity))
+              (ref/->page-ref (:block/uuid entity))
               format
               {:last-pattern (if drop-or-paste? "" commands/command-trigger)
                :restore?     true
@@ -1923,7 +1924,7 @@
 
       ;; block reference
       (insert-command! id
-                       (block-ref/->block-ref uuid-string)
+                       (ref/->block-ref uuid-string)
                        format
                        {:last-pattern (str block-ref/left-parens (if selected-text "" q))
                         :end-pattern block-ref/right-parens
@@ -2388,7 +2389,7 @@
               {:keys [selection-start selection-end selection]} selection]
           (if selection
             (do (delete-and-update input selection-start selection-end)
-                (insert (page-ref/->page-ref selection)))
+                (insert (ref/->page-ref selection)))
             (if-let [embed-ref (thingatpt/embed-macro-at-point input)]
               (let [{:keys [raw-content start end]} embed-ref]
                 (delete-and-update input start end)
@@ -3194,15 +3195,15 @@
           (if db?
             (p/do!
              (save-current-block!)
-             (util/copy-to-clipboard! (page-ref/->page-ref block-id)
+             (util/copy-to-clipboard! (ref/->page-ref block-id)
                                       {:graph (state/get-current-repo)
                                        :blocks [{:block/uuid (:block/uuid current-block)}]
                                        :embed-block? true}))
             (copy-block-ref! block-id #(str "{{embed ((" % "))}}")))
           (copy-block-ref! block-id
                            (if db?
-                             page-ref/->page-ref
-                             block-ref/->block-ref)))))))
+                             ref/->page-ref
+                             ref/->block-ref)))))))
 
 (defn copy-current-block-embed []
   (copy-current-block-ref "embed"))
@@ -3848,14 +3849,16 @@
 (defn copy-current-ref
   [block-id]
   (when block-id
-    (util/copy-to-clipboard! (block-ref/->block-ref block-id))))
+    (util/copy-to-clipboard! (ref/->block-ref block-id))))
 
 (defn delete-current-ref!
   [block ref-id]
   (when (and block ref-id)
-    (let [match (re-pattern (str "\\s?"
-                                 (string/replace (block-ref/->block-ref ref-id) #"([\(\)])" "\\$1")))
-          content (string/replace-first (:block/title block) match "")]
+    (let [content (if (config/db-based-graph?)
+                    (string/replace (:block/title block) (ref/->page-ref ref-id) "")
+                    (let [match (re-pattern (str "\\s?"
+                                                 (string/replace (ref/->block-ref ref-id) #"([\(\)])" "\\$1")))]
+                      (string/replace (:block/title block) match "")))]
       (save-block! (state/get-current-repo)
                    (:block/uuid block)
                    content))))
@@ -3864,7 +3867,7 @@
   [block ref-id]
   (when (and block ref-id)
     (let [repo (state/get-current-repo)
-          match (block-ref/->block-ref ref-id)
+          match (ref/->block-ref ref-id)
           ref-block (db/entity [:block/uuid ref-id])
           block-ref-content (->> (or (:block/title ref-block) "")
                                  (property-file/remove-built-in-properties-when-file-based repo
@@ -3879,7 +3882,7 @@
 (defn replace-ref-with-embed!
   [block ref-id]
   (when (and block ref-id)
-    (let [match (block-ref/->block-ref ref-id)
+    (let [match (ref/->block-ref ref-id)
           content (string/replace-first (:block/title block) match
                                         (util/format "{{embed ((%s))}}"
                                                      (str ref-id)))]

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

@@ -28,6 +28,7 @@
             [frontend.mobile.util :as mobile-util]
             [frontend.modules.outliner.op :as outliner-op]
             [frontend.modules.outliner.ui :as ui-outliner-tx]
+            [frontend.ref :as ref]
             [frontend.state :as state]
             [frontend.util :as util]
             [frontend.util.cursor :as cursor]
@@ -145,7 +146,7 @@
 (defn get-page-ref-text
   [page]
   (if (config/db-based-graph?)
-    (page-ref/->page-ref page)
+    (ref/->page-ref page)
     (file-page-handler/get-page-ref-text page)))
 
 (defn init-commands!
@@ -196,7 +197,7 @@
   (if (state/org-mode-file-link? (state/get-current-repo))
     (let [page-ref-text (get-page-ref-text q)
           value (gobj/get input "value")
-          old-page-ref (page-ref/->page-ref q)
+          old-page-ref (ref/->page-ref q)
           new-value (string/replace value
                                     old-page-ref
                                     page-ref-text)]
@@ -232,7 +233,7 @@
                              (text/get-namespace-last-part chosen)
                              chosen)
           wrapped-tag (if (and (util/safe-re-find #"\s+" chosen-last-part) (not wrapped?))
-                        (page-ref/->page-ref chosen-last-part)
+                        (ref/->page-ref chosen-last-part)
                         chosen-last-part)
           q (if (editor-handler/get-selected-text) "" q)
           last-pattern (if wrapped?
@@ -271,7 +272,7 @@
                                               [page (db/get-page page)])))
                                         [chosen' chosen-result])
             ref-text (if (and (de/entity? chosen-result) (not (ldb/page? chosen-result)))
-                       (page-ref/->page-ref (:block/uuid chosen-result))
+                       (ref/->page-ref (:block/uuid chosen-result))
                        (get-page-ref-text chosen'))
             result (when db-based?
                      (when-not (de/entity? chosen-result)
@@ -281,7 +282,7 @@
                                   :split-namespace? true})))
             ref-text' (if result
                         (let [title (:block/title result)]
-                          (page-ref/->page-ref title))
+                          (ref/->page-ref title))
                         ref-text)]
       (p/do!
        (editor-handler/insert-command! id

+ 2 - 2
src/main/frontend/mobile/action_bar.cljs

@@ -7,13 +7,13 @@
             [frontend.handler.editor :as editor-handler]
             [frontend.mixins :as mixins]
             [frontend.mobile.util :as mobile-util]
+            [frontend.ref :as ref]
             [frontend.state :as state]
             [frontend.ui :as ui]
             [frontend.util :as util]
             [frontend.util.url :as url-util]
             [goog.dom :as gdom]
             [goog.object :as gobj]
-            [logseq.common.util.block-ref :as block-ref]
             [rum.core :as rum]))
 
 (defn- action-command
@@ -64,7 +64,7 @@
         (action-command "cut" "Cut" #(editor-handler/cut-selection-blocks true))
         (action-command "trash" "Delete" #(editor-handler/delete-block-aux! block))
         (action-command "registered" "Copy ref"
-                        (fn [_event] (editor-handler/copy-block-ref! uuid block-ref/->block-ref)))
+                        (fn [_event] (editor-handler/copy-block-ref! uuid ref/->block-ref)))
         (action-command "link" "Copy url"
                         (fn [_event] (let [current-repo (state/get-current-repo)
                                            tap-f (fn [block-id]

+ 4 - 4
src/main/frontend/mobile/intent.cljs

@@ -1,7 +1,7 @@
 (ns frontend.mobile.intent
-  (:require ["@capacitor/filesystem" :refer [Filesystem]]
+  (:require ["@capacitor/action-sheet" :refer [ActionSheet]]
+            ["@capacitor/filesystem" :refer [Filesystem]]
             ["@capacitor/share" :refer [^js Share]]
-            ["@capacitor/action-sheet" :refer [ActionSheet]]
             ["path" :as node-path]
             ["send-intent" :refer [^js SendIntent]]
             [clojure.pprint :as pprint]
@@ -14,6 +14,7 @@
             [frontend.handler.editor :as editor-handler]
             [frontend.handler.notification :as notification]
             [frontend.mobile.util :as mobile-util]
+            [frontend.ref :as ref]
             [frontend.state :as state]
             [frontend.util :as util]
             [frontend.util.fs :as fs-util]
@@ -21,7 +22,6 @@
             [lambdaisland.glogi :as log]
             [logseq.common.config :as common-config]
             [logseq.common.util :as common-util]
-            [logseq.common.util.page-ref :as page-ref]
             [promesa.core :as p]))
 
 (defn open-or-share-file
@@ -121,7 +121,7 @@
              (.copy Filesystem (clj->js {:from url :to path}))
              (fn [error]
                (log/error :copy-file-error {:error error})))
-          url (page-ref/->page-ref title)
+          url (ref/->page-ref title)
           template (get-in (state/get-config)
                            [:quick-capture-templates :text]
                            "**{time}** [[quick capture]]: {url}")]

+ 13 - 0
src/main/frontend/ref.cljs

@@ -0,0 +1,13 @@
+(ns frontend.ref
+  "Reference-related fns"
+  (:require [frontend.config :as config]
+            [logseq.common.util.block-ref :as block-ref]
+            [logseq.common.util.page-ref :as page-ref]))
+
+(defn ->block-ref
+  [id]
+  (if (config/db-based-graph?)
+    (page-ref/->page-ref id)
+    (block-ref/->block-ref id)))
+
+(def ->page-ref page-ref/->page-ref)

+ 9 - 9
src/main/frontend/template.cljs

@@ -2,17 +2,17 @@
   "Provides template related functionality"
   (:require [clojure.string :as string]
             [frontend.date :as date]
-            [frontend.state :as state]
+            [frontend.db.conn :as conn]
             [frontend.db.utils :as db-utils]
-            [logseq.common.util.page-ref :as page-ref]
-            [logseq.db :as ldb]
-            [frontend.db.conn :as conn]))
+            [frontend.ref :as ref]
+            [frontend.state :as state]
+            [logseq.db :as ldb]))
 
 (defn- variable-rules
   []
-  {"today" (page-ref/->page-ref (date/today))
-   "yesterday" (page-ref/->page-ref (date/yesterday))
-   "tomorrow" (page-ref/->page-ref (date/tomorrow))
+  {"today" (ref/->page-ref (date/today))
+   "yesterday" (ref/->page-ref (date/yesterday))
+   "tomorrow" (ref/->page-ref (date/tomorrow))
    "time" (date/get-current-time)
    "current page" (when-let [current-page (or
                                            (state/get-current-page)
@@ -22,7 +22,7 @@
                                  (db-utils/entity [:block/uuid block-uuid])
                                  (ldb/get-page (conn/get-db) current-page))
                           current-page' (:block/title page)]
-                      (when current-page' (page-ref/->page-ref current-page'))))})
+                      (when current-page' (ref/->page-ref current-page'))))})
 
 (def template-re #"<%([^%].*?)%>")
 
@@ -41,5 +41,5 @@
                         :else
                         (if-let [nld (date/nld-parse match)]
                           (let [date (doto (goog.date.DateTime.) (.setTime (.getTime nld)))]
-                            (page-ref/->page-ref (date/journal-name date)))
+                            (ref/->page-ref (date/journal-name date)))
                           match))))))