From 0080a2be95d52d026be26b3fb07f69c0ac263cb7 Mon Sep 17 00:00:00 2001 From: Mega Yu Date: Thu, 8 Jan 2026 15:47:20 +0800 Subject: [PATCH] Reconstructed to meet bb requirements --- .../src/logseq/graph_parser/exporter.cljs | 154 ++++++++++-------- 1 file changed, 85 insertions(+), 69 deletions(-) diff --git a/deps/graph-parser/src/logseq/graph_parser/exporter.cljs b/deps/graph-parser/src/logseq/graph_parser/exporter.cljs index e3c60e8ad6..2b0f484f50 100644 --- a/deps/graph-parser/src/logseq/graph_parser/exporter.cljs +++ b/deps/graph-parser/src/logseq/graph_parser/exporter.cljs @@ -1256,6 +1256,87 @@ (concat txs (build-pdf-annotations-tx* asset-edn-map (get @pdf-annotation-pages asset-md-name) parent-asset image-asset-name-to-uuids opts)))))) +(defn- resolve-asset-data + [asset-link user-config linked-files linked-base-dir zotero-imported-files] + (let [link-map (second asset-link) + path* (-> link-map :url second) + zotero-path-data (when (map? path*) + (get-zotero-local-pdf-path user-config link-map)) + zotero-asset? (some? zotero-path-data) + linked-relative (when (and linked-files zotero-asset? (seq @linked-files)) + (let [value (first @linked-files)] + (swap! linked-files rest) + (string/replace-first value "attachments:" ""))) + linked-base (when (string? linked-relative) + (node-path/basename linked-relative)) + linked-path (when (and (string? linked-relative) + (string? linked-base-dir) + (not (string/blank? linked-base-dir))) + (node-path/join linked-base-dir linked-relative)) + {:keys [path link base]} (cond + linked-path {:path linked-path + :link (:link zotero-path-data) + :base linked-base} + zotero-asset? zotero-path-data + :else {:path path*}) + asset-name (cond + linked-path base + zotero-asset? (or (get zotero-imported-files (last (string/split link #"/"))) base) + :else (some-> path asset-path->name)) + path (cond + linked-path path + (and zotero-asset? asset-name) (string/replace path #"[^/]+$" asset-name) + :else path) + asset-link-or-name (or link asset-name) + external-props (when zotero-asset? + (if linked-path + {:zotero-linked-file linked-relative} + {:zotero-imported-file (string/join ns-util/namespace-char [(last (string/split link #"/")) asset-name])}))] + {:asset-link-or-name asset-link-or-name + :asset-name asset-name + :external-props external-props + :path path + :zotero-asset? zotero-asset?})) + +(defn- ensure-asset-data! + [assets asset-link-or-name path asset-name external-props (p/let [^js stat (title (node-path/basename asset-name)) + :block/uuid (get-asset-block-id assets asset-link-or-name)} + (when-let [metadata (not-empty (common-util/safe-read-map-string (:metadata (second asset-link))))] + {:logseq.property.asset/resize-metadata metadata})) + pdf-annotations-path (if (and zotero-asset? (string? asset-name)) + (node-path/join common-config/local-assets-dir asset-name) + (or asset-name asset-link-or-name)) + pdf-annotations-tx (when (= "pdf" (path/file-ext pdf-annotations-path)) + (build-pdf-annotations-tx pdf-annotations-path assets new-asset pdf-annotation-pages opts)) + asset-tx (concat [new-asset] pdf-annotations-tx)] + ;; (prn :asset-added! (node-path/basename asset-name)) + ;; (cljs.pprint/pprint asset-link) + ;; (prn :debug :asset-tx asset-tx) + (swap! assets assoc-in [asset-link-or-name :asset-created?] true) + {:asset-name-uuid [asset-link-or-name (:block/uuid new-asset)] + :asset-tx asset-tx})) + (defn- link-map :url second) - zotero-path-data (when (map? path*) - (get-zotero-local-pdf-path user-config link-map)) - zotero-asset? (some? zotero-path-data) - linked-relative (when (and linked-files zotero-asset? (seq @linked-files)) - (let [value (first @linked-files)] - (swap! linked-files rest) - (string/replace-first value "attachments:" ""))) - linked-base (when (string? linked-relative) - (node-path/basename linked-relative)) - linked-path (when (and (string? linked-relative) - (string? linked-base-dir) - (not (string/blank? linked-base-dir))) - (node-path/join linked-base-dir linked-relative)) - {:keys [path link base]} (cond - linked-path {:path linked-path - :link (:link zotero-path-data) - :base linked-base} - zotero-asset? zotero-path-data - :else {:path path*}) - asset-name (cond - linked-path base - zotero-asset? (or (get zotero-imported-files (last (string/split link #"/"))) base) - :else (some-> path asset-path->name)) - path (cond - linked-path path - (and zotero-asset? asset-name) (string/replace path #"[^/]+$" asset-name) - :else path) - asset-link-or-name (or link asset-name) - asset-data* (when asset-link-or-name (get @assets asset-link-or-name)) - external-props (when zotero-asset? - (if linked-path - {:zotero-linked-file linked-relative} - {:zotero-imported-file (string/join ns-util/namespace-char [(last (string/split link #"/")) asset-name])})) - _ (when (and asset-link-or-name - (not asset-data*) - (string/ends-with? path ".pdf") - (fn? - (p/let [^js stat (title (node-path/basename asset-name)) - :block/uuid (get-asset-block-id assets asset-link-or-name)} - (when-let [metadata (not-empty (common-util/safe-read-map-string (:metadata (second asset-link))))] - {:logseq.property.asset/resize-metadata metadata})) - pdf-annotations-path (if (and zotero-asset? (string? asset-name)) - (node-path/join common-config/local-assets-dir asset-name) - (or asset-name asset-link-or-name)) - pdf-annotations-tx (when (= "pdf" (path/file-ext pdf-annotations-path)) - (build-pdf-annotations-tx pdf-annotations-path assets new-asset pdf-annotation-pages opts)) - asset-tx (concat [new-asset] pdf-annotations-tx)] - ;; (prn :asset-added! (node-path/basename asset-name)) - ;; (cljs.pprint/pprint asset-link) - ;; (prn :debug :asset-tx asset-tx) - (swap! assets assoc-in [asset-link-or-name :asset-created?] true) - {:asset-name-uuid [asset-link-or-name (:block/uuid new-asset)] - :asset-tx asset-tx})) + (build-asset-tx asset-data asset-name asset-link-or-name asset-link pdf-annotation-pages opts assets zotero-asset?)) (when-not zotero-asset? ; no need to report warning for zotero managed pdf files (swap! ignored-assets conj {:reason "No asset data found for this asset path"