feat: able to reference an asset file

refactor/assets
Tienson Qin 2024-09-27 08:15:26 +08:00
parent 17e808989a
commit 82a70921fb
2 changed files with 22 additions and 6 deletions

View File

@ -871,6 +871,14 @@
(when draw-component
(draw-component {:file file :block-uuid block-uuid}))))
(rum/defc asset-cp
[config block]
(let [asset-type (:logseq.property.asset/type block)]
(asset-link config (:block/title block)
(path/path-join (str "../" common-config/local-assets-dir) (str (:block/uuid block) "." asset-type))
nil
nil)))
(rum/defc page-reference < rum/reactive
"Component for page reference"
[html-export? s {:keys [nested-link? show-brackets? id] :as config} label]
@ -882,13 +890,17 @@
show-brackets? (if (some? show-brackets?) show-brackets? (state/show-brackets?))
block-uuid (:block/uuid config)
contents-page? (= "contents" (string/lower-case (str id)))
block (db/get-page s)]
block (db/get-page s)
asset? (some? (:logseq.property.asset/type block))]
(cond
(string/ends-with? s ".excalidraw")
[:div.draw {:on-click (fn [e]
(.stopPropagation e))}
(excalidraw s block-uuid)]
asset?
(asset-cp config block)
(or (ldb/page? block) (:block/tags block))
[:span.page-reference
{:data-ref s}
@ -1047,16 +1059,21 @@
block-type (keyword (pu/lookup properties :logseq.property/ls-type))
hl-type (pu/lookup properties :logseq.property/hl-type)
repo (state/get-current-repo)
stop-inner-events? (= block-type :whiteboard-shape)]
stop-inner-events? (= block-type :whiteboard-shape)
asset? (some? (:logseq.property.asset/type block))]
(if (and block (:block/title block))
(let [title [:span.block-ref
(block-content (assoc config :block-ref? true :stop-events? stop-inner-events?)
block nil (:block/uuid block)
(:slide? config))]
inner (if label
inner (cond
asset?
(asset-cp config block)
label
(->elem
:span.block-ref
(map-inline config label))
:else
title)]
[:div.block-ref-wrap.inline
{:data-type (name (or block-type :default))

View File

@ -1448,8 +1448,7 @@
file-rpath (cond-> file-rpath
(not (nil? matched-alias))
(string/replace #"^[.\/\\]*assets[\/\\]+" ""))
dir (or (:dir matched-alias) repo-dir)
checksum (assets-handler/get-file-checksum file)]
dir (or (:dir matched-alias) repo-dir)]
(if (util/electron?)
(let [from (not-empty (.-path file))]
(js/console.debug "Debug: Copy Asset #" dir file-rpath from)
@ -1580,7 +1579,7 @@
:block/tags (:db/id asset)}
result (api-insert-new-block! file-name
{:page (:block/uuid asset)
:block-uuid block-id
:custom-uuid block-id
:edit-block? false
:properties properties})
new-entity (db/entity [:block/uuid (:block/uuid result)])]