feat: import from logseq edn

feat: import edn with provided uuid

feat: overwrite page uuid; use properties in content

feat: error handling for importing

feat: support json import

chore: fix lint by splitting setup ui
This commit is contained in:
Junyi Du
2022-05-10 22:10:12 +08:00
parent 459262cd24
commit 0cdacc35e2
8 changed files with 294 additions and 75 deletions

View File

@@ -116,27 +116,35 @@
[page]))))
(defn create!
"Create page.
:redirect? - when true, redirect to the created page, otherwise return sanitized page name.
:split-namespace? - when true, split hierarchical namespace into levels.
:create-first-block? - when true, create an empty block if the page is empty.
:uuid - when set, use this uuid instead of generating a new one."
([title]
(create! title {}))
([title {:keys [redirect? create-first-block? format properties split-namespace? journal?]
([title {:keys [redirect? create-first-block? format properties split-namespace? journal? uuid]
:or {redirect? true
create-first-block? true
format nil
properties nil
split-namespace? true}}]
(let [title (string/trim title)
title (gp-util/remove-boundary-slashes title)
page-name (util/page-name-sanity-lc title)
repo (state/get-current-repo)]
split-namespace? true
uuid nil}}]
(let [title (string/trim title)
title (gp-util/remove-boundary-slashes title)
page-name (util/page-name-sanity-lc title)
repo (state/get-current-repo)
with-uuid? (if (uuid? uuid) uuid true)] ;; FIXME: prettier validation
(when (db/page-empty? repo page-name)
(let [pages (if split-namespace?
(gp-util/split-namespace-pages title)
[title])
format (or format (state/get-preferred-format))
pages (map (fn [page]
(-> (block/page-name->map page true)
;; only apply uuid to the deepest hierarchy of page to create if provided.
(-> (block/page-name->map page (if (= page title) with-uuid? true))
(assoc :block/format format)))
pages)
pages)
txs (->> pages
;; for namespace pages, only last page need properties
drop-last
@@ -149,6 +157,7 @@
(when (seq txs)
(db/transact! txs)))
(prn "creating" page-name) ;; TODO Junyi
(when create-first-block?
(when (or
(db/page-empty? repo (:db/id (db/entity [:block/name page-name])))