fix(breadcrumb): resolve uuid refs in breadcrumb labels

This commit is contained in:
Mega Yu
2026-05-13 16:38:42 +08:00
parent 3f5b52cc07
commit 143bfbcd26
2 changed files with 28 additions and 3 deletions

View File

@@ -4,7 +4,8 @@
Converts page/block entities into flat segment maps, then applies a
display-budget algorithm to determine which segments are visible and
which are folded into an ellipsis."
(:require [clojure.string :as string]))
(:require [clojure.string :as string]
[logseq.db.frontend.content :as db-content]))
;; ---------------------------------------------------------------------------
;; Text normalization
@@ -122,6 +123,15 @@
cleaned (when line (strip-markdown-markup line))]
(truncate-segment-text cleaned))))
(defn- entity-display-title
[entity raw-title]
(or (when (and (string? raw-title)
(re-find db-content/id-ref-pattern raw-title))
(db-content/recur-replace-uuid-in-block-title
(assoc entity :block/title raw-title)
10))
raw-title))
;; ---------------------------------------------------------------------------
;; Block type detection
;; ---------------------------------------------------------------------------
@@ -192,7 +202,9 @@
[entity]
(when entity
(let [page? (some? (:block/name entity))
raw-title (or (:block/raw-title entity) (:block/title entity))
raw-title (entity-display-title
entity
(or (:block/raw-title entity) (:block/title entity)))
;; DB version: structural type is stored in :logseq.property.node/display-type
;; (Code/Quote/Math blocks) or inferred from :block/tags (Query family).
;; org-mode markers like #+BEGIN_SRC in raw-title are also recognised as

View File

@@ -134,7 +134,20 @@
{:db/id 1
:block/uuid #uuid "00000000-0000-0000-0000-000000000001"
:block/raw-title "plain text"})]
(is (= "plain text" (:text seg))))))
(is (= "plain text" (:text seg)))))
(testing "block uuid page refs are resolved to page title refs"
(let [ref-uuid #uuid "00000000-0000-0000-0000-000000000002"
seg (model/block->breadcrumb-segment
{:db/id 1
:block/uuid #uuid "00000000-0000-0000-0000-000000000001"
:block/raw-title (str "See [[" ref-uuid "]]")
:block/refs [{:db/id 2
:block/uuid ref-uuid
:block/name "aaa"
:block/title "aaa"}]})]
(is (= "See [[aaa]]" (:text seg)))
(is (= "See [[aaa]]" (:full-text seg))))))
;; ---------------------------------------------------------------------------
;; block->breadcrumb-segment — structural type detection