fix: new page doesn't have block/uuid

This commit is contained in:
Tienson Qin
2023-06-14 17:29:55 +08:00
parent 0f1cbb3bc7
commit 32173ff95e
5 changed files with 17 additions and 14 deletions

View File

@@ -614,7 +614,7 @@
(str (gp-property/colons-org "id") " " (:block/uuid block)))))]
(string/replace-first c replace-str ""))))))
(defn block-exists-in-another-page?
(defn block-exists-in-another-page?
"For sanity check only.
For renaming file externally, the file is actually deleted and transacted before-hand."
[db block-uuid current-page-name]

View File

@@ -70,7 +70,7 @@ and handles unexpected failure."
([block]
(parse-block block nil))
([{:block/keys [uuid content format] :as block} {:keys [with-id?]
:or {with-id? true}}]
:or {with-id? true}}]
(when-not (string/blank? content)
(let [block (dissoc block :block/pre-block?)
ast (format/to-edn content format nil)

View File

@@ -2,7 +2,10 @@
"DB-based graph implementation"
(:require [frontend.db :as db]
[clojure.string :as string]
[frontend.format.block :as block]))
[frontend.format.block :as block]
[frontend.config :as config]
[frontend.format.mldoc :as mldoc]
[logseq.graph-parser.mldoc :as gp-mldoc]))
(defn- remove-non-existed-refs!
[refs]
@@ -17,8 +20,12 @@
(let [block (or (and (:db/id block) (db/pull (:db/id block))) block)
block (if (string/blank? content)
block
(let [block (merge block
(block/parse-block (assoc block :block/content content)))]
(let [ast (mldoc/->edn (string/trim content) (gp-mldoc/default-config :markdown))
first-elem-type (first (ffirst ast))
block-with-title? (mldoc/block-with-title? first-elem-type)
content' (str (config/get-block-pattern :markdown) (if block-with-title? " " "\n") content)
block (merge block
(block/parse-block (assoc block :block/content content')))]
(update block :block/refs remove-non-existed-refs!)))
block (if (and left (not= (:block/left block) left)) (assoc block :block/left left) block)]
(-> block

View File

@@ -14,8 +14,7 @@
[frontend.util :as util]
[frontend.util.property :as property]
[logseq.graph-parser.util :as gp-util]
[cljs.spec.alpha :as s]
[frontend.config :as config]))
[cljs.spec.alpha :as s]))
(s/def ::block-map (s/keys :opt [:db/id :block/uuid :block/page :block/left :block/parent]))
@@ -144,10 +143,7 @@
(dissoc :block/children :block/meta :block.temp/top? :block.temp/bottom?
:block/title :block/body :block/level)
(gp-util/remove-nils))
m (if (or (config/db-based-graph? (state/get-current-repo))
(state/enable-block-timestamps?))
(block-with-timestamps m)
m)
m (block-with-timestamps m)
other-tx (:db/other-tx m)
id (:db/id (:data this))
block-entity (db/entity id)]
@@ -217,8 +213,8 @@
(map-indexed (fn [idx child]
(let [parent [:block/uuid left-id]]
(cond->
{:db/id (:db/id child)
:block/parent parent}
{:db/id (:db/id child)
:block/parent parent}
(zero? idx)
(assoc :block/left parent))))
immediate-children)))

View File

@@ -139,7 +139,7 @@
(not (contains? (:file/unlinked-dirs @state/state)
(config/get-repo-dir repo)))))
;; (prn "[DEBUG] Outliner transact:")
;; (prn :debug "Outliner transact:")
;; (frontend.util/pprint {:txs txs :opts opts})
(try