fix: Can't edit a page called Logseq

close #1792
pull/1803/head
Tienson Qin 2021-05-11 15:30:38 +08:00
parent a28216c980
commit 42542aac23
2 changed files with 21 additions and 12 deletions

View File

@ -163,6 +163,24 @@
format ast properties
file content utf8-content journal?))))
(defn with-block-uuid
[pages]
(->> (util/distinct-by :block/name pages)
(map (fn [page]
(if (:block/uuid page)
page
(assoc page :block/uuid (db/new-block-id)))))))
(defn with-ref-pages
[pages blocks]
(let [ref-pages (->> (mapcat :block/refs blocks)
(filter :block/name))]
(->> (concat pages ref-pages)
(group-by :block/name)
vals
(map (partial apply merge))
(with-block-uuid))))
(defn extract-all-blocks-pages
[repo-url files metadata]
(when (seq files)
@ -176,17 +194,7 @@
(remove empty?))]
(when (seq result)
(let [[pages block-ids blocks] (apply map concat result)
ref-pages (->> (mapcat :block/refs blocks)
(filter :block/name))
pages (->> (concat pages ref-pages)
(group-by :block/name)
vals
(map (partial apply merge)))
pages (->> (util/distinct-by :block/name pages)
(map (fn [page]
(if (:block/uuid page)
page
(assoc page :block/uuid (db/new-block-id))))))
pages (with-ref-pages pages blocks)
blocks (map (fn [block]
(let [id (:block/uuid block)
properties (get-in metadata [:block/properties id])]

View File

@ -142,7 +142,8 @@
file-content [{:file/path file}]
tx (if (contains? config/mldoc-support-formats format)
(let [delete-blocks (db/delete-file-blocks! repo-url file)
[pages block-ids blocks] (extract-handler/extract-blocks-pages repo-url file content utf8-content)]
[pages block-ids blocks] (extract-handler/extract-blocks-pages repo-url file content utf8-content)
pages (extract-handler/with-ref-pages pages blocks)]
(concat file-content delete-blocks pages block-ids blocks))
file-content)
tx (concat tx [(let [t (tc/to-long (t/now))]