fix: pdf related properties for db graphs

Added to new property ns as file and file-path are too generic to be top-level.
Also fixed bugs in page creation
pull/11311/head
Gabriel Horner 2024-05-09 13:35:44 -04:00
parent 123cb8fc42
commit 70d92c8f7a
3 changed files with 35 additions and 28 deletions

View File

@ -185,7 +185,11 @@
{:type :checkbox
:hide? true
:view-context :page
:public? true}}))
:public? true}}
:logseq.property.pdf/file
{:schema {:type :string :hide? true :public? true :view-context :page}}
:logseq.property.pdf/file-path
{:schema {:type :string :hide? true :public? true :view-context :page}}))
(def built-in-properties
(->> built-in-properties*
@ -209,7 +213,7 @@
(def logseq-property-namespaces
#{"logseq.property" "logseq.property.table" "logseq.property.tldraw"
"logseq.task"})
"logseq.property.pdf" "logseq.task"})
(defn logseq-property?
"Determines if keyword is a logseq property"

View File

@ -168,21 +168,22 @@
(page-handler/<create! page-name {:redirect? false :create-first-block? false
:split-namespace? false
:format format
;; FIXME: file and file-path properties for db version
:properties {:file (case format
:markdown
(util/format "[%s](%s)" label url)
:properties {(pu/get-pid :logseq.property.pdf/file)
(case format
:markdown
(util/format "[%s](%s)" label url)
:org
(util/format "[[%s][%s]]" url label)
:org
(util/format "[[%s][%s]]" url label)
url)
:file-path url}})
url)
(pu/get-pid :logseq.property.pdf/file-path)
url}})
(db-model/get-page page-name)))
;; try to update file path
(do
(property-handler/add-page-property! page-name (pu/get-pid :logseq.property/file-path) url)
(property-handler/add-page-property! page-name (pu/get-pid :logseq.property.pdf/file-path) url)
page)))))
(defn ensure-ref-block!
@ -236,8 +237,7 @@
(let [id (:block/uuid block)
page (db-utils/pull (:db/id (:block/page block)))
page-name (:block/original-name page)
;; FIXME: file-path property for db version
file-path (:file-path (:block/properties page))
file-path (pu/get-block-property-value block :logseq.property.pdf/file-path)
hl-page (pu/get-block-property-value block :logseq.property/hl-page)]
(when-let [target-key (and page-name (subs page-name 5))]
(p/let [hls (resolve-hls-data-by-key$ target-key)

View File

@ -33,21 +33,23 @@
(defn- build-page-tx [repo conn config date-formatter format properties page {:keys [whiteboard? class? tags]}]
(when (:block/uuid page)
(let [page-entity [:block/uuid (:block/uuid page)]
page (merge page
(when (seq properties) {:block/properties properties})
(when whiteboard? {:block/type "whiteboard"})
(when class? {:block/type "class"})
(when tags {:block/tags (mapv #(hash-map :db/id
(:db/id (d/entity @conn [:block/uuid %])))
tags)}))
page-empty? (ldb/page-empty? @conn (:block/name page))
db-based? (sqlite-util/db-based-graph? repo)]
(if (and (seq properties)
(not whiteboard?)
(not db-based?)
page-empty?)
[page (properties-block repo conn config date-formatter properties format page-entity)]
[page]))))
page' (merge page
(when whiteboard? {:block/type "whiteboard"})
(when tags {:block/tags (mapv #(hash-map :db/id
(:db/id (d/entity @conn [:block/uuid %])))
tags)}))]
(if (sqlite-util/db-based-graph? repo)
[(merge page'
;; FIXME: Add refs for properties?
properties
(when class? {:block/type "class"}))]
(let [file-page (merge page'
(when (seq properties) {:block/properties properties}))]
(if (and (seq properties)
(not whiteboard?)
(ldb/page-empty? @conn (:block/name page)))
[file-page (properties-block repo conn config date-formatter properties format page-entity)]
[file-page]))))))
(defn get-title-and-pagename
[title]
@ -68,6 +70,7 @@
* :whiteboard? - when true, adds a :block/type 'whiteboard'
* :tags - tag uuids that are added to :block/tags
* :persist-op? - when true, add an update-page op
* :properties - properties to add to the page
TODO: Add other options"
[repo conn config title
& {:keys [create-first-block? format properties uuid persist-op? whiteboard? class? today-journal?]