add zotero importing test

This commit is contained in:
Mega Yu
2026-01-31 16:57:15 +08:00
parent 0ad5558791
commit 76b9676e93
13 changed files with 256 additions and 5 deletions

View File

@@ -125,6 +125,11 @@
options' (merge default-export-options
{:user-options (merge {:convert-all-tags? false} (dissoc options :assets :verbose))
;; asset file options
:<get-file-stat (fn [path]
(let [abs-path (if (node-path/isAbsolute path)
path
(node-path/resolve file-graph-dir path))]
(.stat (js/require "fs/promises") abs-path)))
:<read-and-copy-asset (fn [file *assets buffer-handler]
(<read-and-copy-asset file *assets buffer-handler assets))}
(select-keys options [:verbose]))]
@@ -210,17 +215,17 @@
;; Counts
;; Includes journals as property values e.g. :logseq.property/deadline
(is (= 32 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Journal]] @conn))))
(is (= 33 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Journal]] @conn))))
(is (= 5 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Asset]] @conn))))
(is (= 9 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Asset]] @conn))))
(is (= 5 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Task]] @conn))))
(is (= 4 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Query]] @conn))))
(is (= 2 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Card]] @conn))))
(is (= 5 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Quote-block]] @conn))))
(is (= 2 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Pdf-annotation]] @conn))))
(is (= 7 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Pdf-annotation]] @conn))))
;; Properties and tags aren't included in this count as they aren't a Page
(is (= 11
(is (= 13
(->> (d/q '[:find [?b ...]
:where
[?b :block/title]
@@ -239,7 +244,8 @@
(is (= 0 (count @(:ignored-properties import-state))) "No ignored properties")
(is (= 0 (count @(:ignored-assets import-state))) "No ignored assets")
(is (= 1 (count @(:ignored-files import-state))) "Ignore .edn for now")
(is (= 5 (count @assets))))
;; 2 zotero pdf are external files so not counted here
(is (= 7 (count @assets))))
(testing "logseq files"
(is (= ".foo {}\n"
@@ -419,6 +425,28 @@
:logseq.property.asset/resize-metadata {:height 288, :width 252}}
(db-test/readable-properties (db-test/find-block-by-content @conn "greg-popovich-thumbs-up_1704749687791_0")))
"Asset has correct properties")
(is (= {:block/tags [:logseq.class/Asset]
:logseq.property.asset/type "pdf"
:logseq.property.asset/external-url "zotero://select/library/items/QDM8H6EH"
:logseq.property.asset/external-file-name "zotero-link://it/Understanding EXPLAIN.pdf"}
(select-keys
(db-test/readable-properties (db-test/find-block-by-content @conn "Understanding EXPLAIN"))
[:block/tags
:logseq.property.asset/type
:logseq.property.asset/external-url
:logseq.property.asset/external-file-name]))
"Zotero linked pdf asset has correct external path info")
(is (= {:block/tags [:logseq.class/Asset]
:logseq.property.asset/type "pdf"
:logseq.property.asset/external-url "zotero://select/library/items/RX5JS7SY"
:logseq.property.asset/external-file-name "zotero-path://RX5JS7SY/zlib.pdf"}
(select-keys
(db-test/readable-properties (db-test/find-block-by-content @conn "zlib"))
[:block/tags
:logseq.property.asset/type
:logseq.property.asset/external-url
:logseq.property.asset/external-file-name]))
"Zotero imported pdf asset has correct external path info")
(is (= (d/entity @conn :logseq.class/Asset)
(:block/page (db-test/find-block-by-content @conn "greg-popovich-thumbs-up_1704749687791_0")))
"Imported into Asset page")
@@ -447,6 +475,90 @@
db-test/readable-properties)
:logseq.property.pdf/hl-value :logseq.property/ls-type))
"Pdf area highlight has correct properties")
(is (= {:block/tags [:logseq.class/Pdf-annotation]
:logseq.property/asset "Understanding EXPLAIN"
:logseq.property.pdf/hl-color :logseq.property/color.yellow
:logseq.property.pdf/hl-page 6}
(select-keys
(db-test/readable-properties (db-test/find-block-by-content @conn #"EXPLAIN is a really nice command"))
[:block/tags
:logseq.property/asset
:logseq.property.pdf/hl-color
:logseq.property.pdf/hl-page]))
"Zotero linked pdf text highlight links to correct asset")
(is (= {:block/tags [:logseq.class/Pdf-annotation]
:logseq.property/asset "zlib"
:logseq.property.pdf/hl-color :logseq.property/color.red
:logseq.property.pdf/hl-page 1}
(select-keys
(db-test/readable-properties (db-test/find-block-by-content @conn #"The zlib library is a general purpose data compression library"))
[:block/tags
:logseq.property/asset
:logseq.property.pdf/hl-color
:logseq.property.pdf/hl-page]))
"Zotero imported pdf text highlight links to correct asset")
(let [area-hl (d/q '[:find (pull ?b [:block/title
{:block/tags [:db/ident]}
{:logseq.property/asset [:block/title]}
{:logseq.property.pdf/hl-image [:block/title]}
{:logseq.property.pdf/hl-color [:db/ident]}
:logseq.property.pdf/hl-type
:logseq.property.pdf/hl-page]) .
:where
[?asset :block/title "Understanding EXPLAIN"]
[?asset :block/tags :logseq.class/Asset]
[?b :block/title "[:span]"]
[?b :logseq.property/asset ?asset]]
@conn)]
(is (= {:logseq.property.pdf/hl-color :logseq.property/color.green
:logseq.property.pdf/hl-page 8
:block/tags [:logseq.class/Pdf-annotation]
:logseq.property/asset "Understanding EXPLAIN"
:logseq.property.pdf/hl-image "pdf area highlight"
:logseq.property.pdf/hl-type :area}
(-> area-hl
(update :block/tags #(mapv :db/ident %))
(update :logseq.property/asset #(:block/title %))
(update :logseq.property.pdf/hl-color #(:db/ident %))
(update :logseq.property.pdf/hl-image #(:block/title %))
(select-keys [:block/tags
:logseq.property/asset
:logseq.property.pdf/hl-color
:logseq.property.pdf/hl-page
:logseq.property.pdf/hl-image
:logseq.property.pdf/hl-type])))
"Zotero linked pdf area highlight links to correct asset"))
(let [area-hl (d/q '[:find (pull ?b [:block/title
{:block/tags [:db/ident]}
{:logseq.property/asset [:block/title]}
{:logseq.property.pdf/hl-image [:block/title]}
{:logseq.property.pdf/hl-color [:db/ident]}
:logseq.property.pdf/hl-type
:logseq.property.pdf/hl-page]) .
:where
[?asset :block/title "zlib"]
[?asset :block/tags :logseq.class/Asset]
[?b :block/title "[:span]"]
[?b :logseq.property/asset ?asset]]
@conn)]
(is (= {:logseq.property.pdf/hl-color :logseq.property/color.blue
:logseq.property.pdf/hl-page 1
:block/tags [:logseq.class/Pdf-annotation]
:logseq.property/asset "zlib"
:logseq.property.pdf/hl-image "pdf area highlight"
:logseq.property.pdf/hl-type :area}
(-> area-hl
(update :block/tags #(mapv :db/ident %))
(update :logseq.property/asset #(:block/title %))
(update :logseq.property.pdf/hl-color #(:db/ident %))
(update :logseq.property.pdf/hl-image #(:block/title %))
(select-keys [:block/tags
:logseq.property/asset
:logseq.property.pdf/hl-color
:logseq.property.pdf/hl-page
:logseq.property.pdf/hl-image
:logseq.property.pdf/hl-type])))
"Zotero imported pdf area highlight links to correct asset"))
;; Quotes
(is (= {:block/tags [:logseq.class/Quote-block]

Binary file not shown.

View File

@@ -0,0 +1,53 @@
{:highlights [{:id #uuid "697874ba-26e9-4e8a-a55d-0639d337dcc6",
:page 6,
:position {:bounding {:x1 67.03125,
:y1 344.90625,
:x2 612.7423095703125,
:y2 379.3333740234375,
:width 702,
:height 993.418487394958},
:rects ({:x1 67.03125,
:y1 344.90625,
:x2 612.7423095703125,
:y2 364.2396240234375,
:width 702,
:height 993.418487394958}
{:x1 67.03125,
:y1 360,
:x2 238.0740203857422,
:y2 379.3333740234375,
:width 702,
:height 993.418487394958}),
:page 6},
:content {:text "EXPLAIN is a really nice command that gives you lots of informations but it's often easy to not know what to do with all this"},
:properties {:color "yellow"}}
{:id #uuid "69787518-9eb8-4fd0-ad3b-b394e28bb547",
:page 8,
:position {:bounding {:x1 84,
:y1 163,
:x2 637,
:y2 327,
:width 702,
:height 993.418487394958},
:rects (),
:page 8},
:content {:text "[:span]", :image 1769501975346},
:properties {:color "green"}}
{:id #uuid "69787540-7a52-40af-a70a-cedd315934cf",
:page 42,
:position {:bounding {:x1 119.05208587646484,
:y1 95.67709350585938,
:x2 243.25509643554688,
:y2 133.01040649414062,
:width 702,
:height 993.418487394958},
:rects ({:x1 119.05208587646484,
:y1 95.67709350585938,
:x2 243.25509643554688,
:y2 133.01040649414062,
:width 702,
:height 993.418487394958}),
:page 42},
:content {:text "Conclusion"},
:properties {:color "blue"}}],
:extra {:page 8}}

View File

@@ -0,0 +1,36 @@
{:highlights [{:id #uuid "69787399-f51c-45a2-8971-78dc6c66a0ec",
:page 1,
:position {:bounding {:x1 123.89583587646484,
:y1 164.3125,
:x2 438.8349304199219,
:y2 180.9791717529297,
:width 702,
:height 908.470588235294},
:rects ({:x1 123.89583587646484,
:y1 164.3125,
:x2 438.8349304199219,
:y2 180.9791717529297,
:width 702,
:height 908.470588235294}
{:x1 143.625,
:y1 166.9791717529297,
:x2 432.40625,
:y2 178.4479217529297,
:width 702,
:height 908.470588235294}),
:page 1},
:content {:text "The zlib library is a general purpose data compression library."},
:properties {:color "red"}}
{:id #uuid "697873d7-5953-4753-897e-62ac47348634",
:page 1,
:position {:bounding {:x1 116,
:y1 530,
:x2 627,
:y2 690,
:width 702,
:height 908.470588235294},
:rects (),
:page 1},
:content {:text "[:span]", :image 1769501651181},
:properties {:color "blue"}}],
:extra {:page 2}}

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

View File

@@ -0,0 +1,2 @@
- [[zlib]]
- [[Understanding EXPLAIN]]

View File

@@ -399,4 +399,7 @@
;; - :triple-lowbar (default)
;; ;use triple underscore `___` for slash `/` in page title
;; ;use Percent-encoding for other invalid characters
;; use relative path here only for ci test, won't work on the Electron client
:zotero/settings-v2 {"default" {:type-id "1234567", :prefer-citekey? false, :attachments-block-text "Attachments", :page-insert-prefix "", :extra-tags "", :zotero-linked-attachment-base-directory "../book", :zotero-data-directory "../zotero"}}
:file/name-format :triple-lowbar}

View File

@@ -0,0 +1,5 @@
- Attachments
- [Understanding EXPLAIN.pdf](zotero://select/library/items/QDM8H6EH) {{zotero-linked-file "it/Understanding EXPLAIN.pdf"}}
- Notes
- ((697874ba-26e9-4e8a-a55d-0639d337dcc6)) definition
- ((69787518-9eb8-4fd0-ad3b-b394e28bb547)) select

View File

@@ -0,0 +1,20 @@
file:: [Understanding EXPLAIN.pdf](../../book/it/Understanding EXPLAIN.pdf)
file-path:: ../../book/it/Understanding EXPLAIN.pdf
- EXPLAIN is a really nice command that gives you lots of informations but it's often easy to not know what to do with all this
ls-type:: annotation
hl-page:: 6
hl-color:: yellow
id:: 697874ba-26e9-4e8a-a55d-0639d337dcc6
- [:span]
ls-type:: annotation
hl-page:: 8
hl-color:: green
id:: 69787518-9eb8-4fd0-ad3b-b394e28bb547
hl-type:: area
hl-stamp:: 1769501975346
- Conclusion
ls-type:: annotation
hl-page:: 42
hl-color:: blue
id:: 69787540-7a52-40af-a70a-cedd315934cf

View File

@@ -0,0 +1,15 @@
file:: [zlib.pdf](../../zotero/RX5JS7SY/zlib.pdf)
file-path:: ../../zotero/storage/RX5JS7SY/zlib.pdf
- The zlib library is a general purpose data compression library.
ls-type:: annotation
hl-page:: 1
hl-color:: red
id:: 69787399-f51c-45a2-8971-78dc6c66a0ec
- [:span]
ls-type:: annotation
hl-page:: 1
hl-color:: blue
id:: 697873d7-5953-4753-897e-62ac47348634
hl-type:: area
hl-stamp:: 1769501651181

View File

@@ -0,0 +1,5 @@
- Attachments
- [PDF](zotero://select/library/items/RX5JS7SY) {{zotero-imported-file RX5JS7SY, "zlib.pdf"}}
- Notes
- ((69787399-f51c-45a2-8971-78dc6c66a0ec)) definition
- ((697873d7-5953-4753-897e-62ac47348634)) links

Binary file not shown.