From 82a70921fb0c62ccfb5a9799f843a2c9ce1c1f2b Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Fri, 27 Sep 2024 08:15:26 +0800 Subject: [PATCH] feat: able to reference an asset file --- src/main/frontend/components/block.cljs | 23 ++++++++++++++++++++--- src/main/frontend/handler/editor.cljs | 5 ++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/main/frontend/components/block.cljs b/src/main/frontend/components/block.cljs index 507d301ed..1f4d5ea0c 100644 --- a/src/main/frontend/components/block.cljs +++ b/src/main/frontend/components/block.cljs @@ -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)) diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index 8c7c817b7..08a77f2ba 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -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)])]