chore: move block-unique-title to handler

This commit is contained in:
Tienson Qin
2024-12-10 17:08:19 +08:00
parent 7d961ca915
commit 7f80b5c365
7 changed files with 37 additions and 43 deletions

View File

@@ -22,7 +22,8 @@
[frontend.handler.property.util :as pu]
[dommy.core :as dom]
[goog.object :as gobj]
[promesa.core :as p]))
[promesa.core :as p]
[datascript.impl.entity :as de]))
;; Fns
@@ -188,6 +189,31 @@
(-> (property-util/remove-built-in-properties format content)
(drawer/remove-logbook))))
(defn block-unique-title
"Multiple pages/objects may have the same `:block/title`.
Notice: this doesn't prevent for pages/objects that have the same tag or created by different clients."
[block]
(let [block-e (cond
(de/entity? block)
block
(uuid? (:block/uuid block))
(db/entity [:block/uuid (:block/uuid block)])
:else
block)
tags (remove (fn [t] (some-> (:block/raw-title block-e) (ldb/inline-tag? t)))
(map (fn [tag] (if (number? tag) (db/entity tag) tag)) (:block/tags block)))]
(if (and (seq tags)
(not (ldb/journal? block)))
(str (:block/title block)
" "
(string/join
", "
(keep (fn [tag]
(when-let [title (:block/title tag)]
(str "#" title)))
tags)))
(:block/title block))))
(defn edit-block!
[block pos & {:keys [_container-id custom-content tail-len save-code-editor?]
:or {tail-len 0