Skip to content

Commit

Permalink
fix: missing refs for property text values when creating a page
Browse files Browse the repository at this point in the history
  • Loading branch information
tiensonqin committed Apr 7, 2024
1 parent 85e65bd commit b5f0f58
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
22 changes: 15 additions & 7 deletions deps/graph-parser/src/logseq/graph_parser/block.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@
properties)
[]))

(defn- extract-refs-from-property-value
[value format]
(cond
(coll? value)
(filter (fn [v] (and (string? v) (not (string/blank? v)))) value)
(string? value)
(let [ast (gp-mldoc/inline->edn value (gp-mldoc/default-config format))]
(text/extract-refs-from-mldoc-ast ast))
:else
nil))

(defn- get-page-ref-names-from-properties
[properties user-config]
(let [page-refs (->>
Expand All @@ -162,8 +173,9 @@
(keyword k))))
;; get links ast
(map last)
(mapcat (or (:extract-refs-from-property-value-fn user-config)
text/extract-refs-from-mldoc-ast))
(mapcat (fn [value]
(let [f (or (:extract-refs-from-property-value-fn user-config) extract-refs-from-property-value)]
(f value (get user-config :format :markdown)))))
;; comma separated collections
(concat (->> (map second properties)
(filter coll?)
Expand Down Expand Up @@ -513,11 +525,7 @@
id (get-custom-id-or-new-id {:properties properties})
property-refs (->> (get-page-refs-from-properties
properties db date-formatter
(assoc user-config
:extract-refs-from-property-value-fn
(fn [refs]
(when (coll? refs)
refs))))
user-config)
(map :block/original-name))
pre-block? (if (:heading properties) false true)
block {:block/uuid id
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/handler/editor.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@
refs (gp-block/get-page-refs-from-properties properties
(db/get-db (state/get-current-repo))
(state/get-date-formatter)
(state/get-config))]
(assoc (state/get-config) :format format))]
{:block/pre-block? true
:block/uuid (db/new-block-id)
:block/properties properties
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/handler/page.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
last-txs (build-page-tx format properties (last pages) journal? whiteboard?)
txs (concat txs last-txs)]
(when (seq txs)
(db/transact! txs)))
(db/transact! repo txs {:outliner-op :create-page})))

(when create-first-block?
(when (or
Expand Down

0 comments on commit b5f0f58

Please sign in to comment.