Skip to content

Commit b2497c0

Browse files
committed
fix: pages starting with "@" fail to import from markdown
related to logseq/db-test#680
1 parent a97fec1 commit b2497c0

2 files changed

Lines changed: 20 additions & 16 deletions

File tree

deps/graph-parser/src/logseq/graph_parser/exporter.cljs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -892,14 +892,15 @@
892892
;; {:url ["Complex" {:protocol "zotero", :link "select/library/items/6VCW9QFJ"}], :label [["Plain" "Dechow and Struppa - 2015 - Intertwingled.pdf"]], :full_text "[Dechow and Struppa - 2015 - Intertwingled.pdf](zotero://select/library/items/6VCW9QFJ)", :metadata ""}
893893
(defn- get-zotero-local-pdf-path
894894
[config m]
895-
(let [link (:link (second (:url m)))
896-
label (second (first (:label m)))
897-
id (last (string/split link #"/"))]
898-
(when (and link id label)
899-
(when-let [zotero-data-dir (get-in config [:zotero/settings-v2 "default" :zotero-data-directory])]
900-
{:link (str "zotero://" link)
901-
:path (node-path/join zotero-data-dir "storage" id label)
902-
:base label}))))
895+
(when (= "zotero" (:protocol (second (:url m))))
896+
(let [link (:link (second (:url m)))
897+
label (second (first (:label m)))
898+
id (last (string/split link #"/"))]
899+
(when (and link id label)
900+
(when-let [zotero-data-dir (get-in config [:zotero/settings-v2 "default" :zotero-data-directory])]
901+
{:link (str "zotero://" link)
902+
:path (node-path/join zotero-data-dir "storage" id label)
903+
:base label})))))
903904

904905
(defn- walk-ast-blocks
905906
"Walks each ast block in order to its full depth. Saves multiple ast types for
@@ -1048,10 +1049,11 @@
10481049
"Given an asset's relative or full path, create a unique name for identifying an asset.
10491050
Must handle to paths as ../assets/*, assets/* and with subdirectories"
10501051
[path]
1051-
(or (re-find #"assets/.*$" path)
1052-
;; pdf outside logseq graphs
1053-
(when (string/ends-with? path ".pdf")
1054-
path)))
1052+
(when (string? path)
1053+
(or (re-find #"assets/.*$" path)
1054+
;; pdf outside logseq graphs
1055+
(when (string/ends-with? path ".pdf")
1056+
path))))
10551057

10561058
(defn- update-asset-links-in-block-title [block-title asset-name-to-uuids ignored-assets]
10571059
(reduce (fn [acc [asset-name asset-uuid]]
@@ -1213,11 +1215,13 @@
12131215
(p/let [asset-maps* (p/all (map
12141216
(fn [asset-link]
12151217
(p/let [path* (-> asset-link second :url second)
1218+
zotero-asset? (when (map? path*)
1219+
(= "zotero" (:protocol (second (:url (second asset-link))))))
12161220
{:keys [path link base]} (if (map? path*)
12171221
(get-zotero-local-pdf-path user-config (second asset-link))
12181222
{:path path*})
1219-
asset-name (-> path asset-path->name)
1220-
asset-link-or-name (or link (-> path asset-path->name))
1223+
asset-name (some-> path asset-path->name)
1224+
asset-link-or-name (or link (some-> path asset-path->name))
12211225
asset-data* (when asset-link-or-name (get @assets asset-link-or-name))
12221226
_ (when (and asset-link-or-name
12231227
(not asset-data*)
@@ -1261,7 +1265,7 @@
12611265
(swap! assets assoc-in [asset-link-or-name :asset-created?] true)
12621266
{:asset-name-uuid [asset-link-or-name (:block/uuid new-asset)]
12631267
:asset-tx asset-tx}))
1264-
(do
1268+
(when-not zotero-asset? ; no need to report warning for zotero managed pdf files
12651269
(swap! ignored-assets conj
12661270
{:reason "No asset data found for this asset path"
12671271
:path (-> asset-link second :url second)

src/main/frontend/components/imports.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@
363363
bytes-array (js/Uint8Array. buffer)
364364
checksum (db-asset/<get-file-array-buffer-checksum buffer)
365365
asset-id (d/squuid)
366-
asset-name (gp-exporter/asset-path->name (:path file))
366+
asset-name (some-> (:path file) gp-exporter/asset-path->name)
367367
assets-dir (path/path-join repo-dir common-config/local-assets-dir)
368368
asset-type (db-asset/asset-path->type (:path file))
369369
{:keys [with-edn-content pdf-annotation?]} (buffer-handler bytes-array)]

0 commit comments

Comments
 (0)