wip: export refactor

1. Move fns to worker
2. Don't rely on :block/file, use db blocks to build page content
This commit is contained in:
Tienson Qin
2024-01-21 18:15:44 +08:00
parent 760a9f8c25
commit e571c571ec
10 changed files with 254 additions and 431 deletions

View File

@@ -15,11 +15,11 @@
(string/trim "
- 1
id:: 61506710-484c-46d5-9983-3d1651ec02c8
- 2
id:: 61506711-5638-4899-ad78-187bdc2eaffc
- 3
id:: 61506712-3007-407e-b6d3-d008a8dfa88b
- ((61506712-3007-407e-b6d3-d008a8dfa88b))
- 2
id:: 61506711-5638-4899-ad78-187bdc2eaffc
- 3
id:: 61506712-3007-407e-b6d3-d008a8dfa88b
- ((61506712-3007-407e-b6d3-d008a8dfa88b))
- 4
id:: 61506712-b8a7-491d-ad84-b71651c3fdab")}
{:file/path "pages/page2.md"
@@ -27,7 +27,7 @@
(string/trim "
- 3
id:: 97a00e55-48c3-48d8-b9ca-417b16e3a616
- {{embed [[page1]]}}")}])
- {{embed [[page1]]}}")}])
(use-fixtures :once
{:before (fn []
@@ -44,18 +44,18 @@
{:remove-options #{:property}})))
(string/trim "
- 1
- 2
- 3
- 3")
- 2
- 3
- 3")
"61506710-484c-46d5-9983-3d1651ec02c8"
(string/trim "
- 3
- 1
- 2
- 3
- 3
- 4")
- 1
- 2
- 3
- 3
- 4")
"97a00e55-48c3-48d8-b9ca-417b16e3a616"))
@@ -65,25 +65,25 @@
(string/trim "
- 1
id:: 61506710-484c-46d5-9983-3d1651ec02c8
- 2
id:: 61506711-5638-4899-ad78-187bdc2eaffc
- 3
id:: 61506712-3007-407e-b6d3-d008a8dfa88b
- 3")
- 2
id:: 61506711-5638-4899-ad78-187bdc2eaffc
- 3
id:: 61506712-3007-407e-b6d3-d008a8dfa88b
- 3")
"61506710-484c-46d5-9983-3d1651ec02c8"
(string/trim "
- 3
id:: 97a00e55-48c3-48d8-b9ca-417b16e3a616
- 1
id:: 61506710-484c-46d5-9983-3d1651ec02c8
- 2
id:: 61506711-5638-4899-ad78-187bdc2eaffc
- 3
id:: 61506712-3007-407e-b6d3-d008a8dfa88b
- 3
- 4
id:: 61506712-b8a7-491d-ad84-b71651c3fdab")
- 1
id:: 61506710-484c-46d5-9983-3d1651ec02c8
- 2
id:: 61506711-5638-4899-ad78-187bdc2eaffc
- 3
id:: 61506712-3007-407e-b6d3-d008a8dfa88b
- 3
- 4
id:: 61506712-b8a7-491d-ad84-b71651c3fdab")
"97a00e55-48c3-48d8-b9ca-417b16e3a616"))
(deftest export-blocks-as-markdown-level<N
@@ -93,13 +93,13 @@
:other-options {:keep-only-level<=N 2}})))
(string/trim "
- 1
- 2")
- 2")
"61506710-484c-46d5-9983-3d1651ec02c8"
(string/trim "
- 3
- 1
- 4")
- 1
- 4")
"97a00e55-48c3-48d8-b9ca-417b16e3a616"))
(deftest export-blocks-as-markdown-newline-after-block
@@ -110,24 +110,24 @@
(string/trim "
- 1
- 2
- 2
- 3
- 3
- 3")
- 3")
"61506710-484c-46d5-9983-3d1651ec02c8"
(string/trim "
- 3
- 1
- 1
- 2
- 2
- 3
- 3
- 3
- 3
- 4")
- 4")
"97a00e55-48c3-48d8-b9ca-417b16e3a616"))
@@ -143,12 +143,11 @@
[{:path "pages/page2.md" :content (:file/content (nth test-files 1)) :names ["page2"] :format :markdown}])))
(deftest-async export-repo-as-edn-str
(p/do!
(let [edn-output (edn/read-string
(@#'export/export-repo-as-edn-str (state/get-current-repo)))]
(is (= #{:version :blocks} (set (keys edn-output)))
"Correct top-level keys")
(is (= (sort (concat (map :block/original-name default-db/built-in-pages)
["page1" "page2"]))
(sort (map :block/page-name (:blocks edn-output))))
"Correct pages"))))
(p/let [edn-output (edn/read-string
(@#'export/<export-repo-as-edn-str (state/get-current-repo)))]
(is (= #{:version :blocks} (set (keys edn-output)))
"Correct top-level keys")
(is (= (sort (concat (map :block/original-name default-db/built-in-pages)
["page1" "page2"]))
(sort (map :block/page-name (:blocks edn-output))))
"Correct pages")))