mirror of
https://github.com/logseq/logseq.git
synced 2026-06-01 19:01:22 +00:00
fix(editor): remove duplicate blocks in references
Closes #1006, closes #846, closes #600
This commit is contained in:
@@ -1276,11 +1276,7 @@
|
||||
|
||||
(when (seq parents)
|
||||
(let [parents (for [{:block/keys [uuid content]} parents]
|
||||
(let [title (->> (take 24
|
||||
(-> (string/split content #"\n")
|
||||
first
|
||||
(text/remove-level-spaces format)))
|
||||
(apply str))]
|
||||
(let [title (string/trim (text/remove-level-spaces content format))]
|
||||
(when (and (not (string/blank? title))
|
||||
(not= (string/lower-case page-name) (string/lower-case title)))
|
||||
[:a {:href (rfe/href :page {:name uuid})}
|
||||
|
||||
@@ -840,6 +840,15 @@
|
||||
db-utils/seq-flatten)]
|
||||
(mapv (fn [page] [page (get-page-alias repo page)]) mentioned-pages))))
|
||||
|
||||
(defn- remove-children!
|
||||
[blocks]
|
||||
(let [childrens (->> (mapcat :block/children blocks)
|
||||
(map :db/id)
|
||||
(set))]
|
||||
(if (seq childrens)
|
||||
(remove (fn [block] (contains? childrens (:db/id block))) blocks)
|
||||
blocks)))
|
||||
|
||||
(defn get-page-referenced-blocks
|
||||
([page]
|
||||
(get-page-referenced-blocks (state/get-current-repo) page))
|
||||
@@ -870,14 +879,17 @@
|
||||
:where
|
||||
[?block :block/ref-pages ?ref-page]
|
||||
[(contains? ?pages ?ref-page)]]
|
||||
pages))]
|
||||
(->> query-result
|
||||
react
|
||||
db-utils/seq-flatten
|
||||
(remove (fn [block]
|
||||
(= page-id (:db/id (:block/page block)))))
|
||||
sort-blocks
|
||||
db-utils/group-by-page))))))
|
||||
pages))
|
||||
result (->> query-result
|
||||
react
|
||||
db-utils/seq-flatten
|
||||
(remove (fn [block]
|
||||
(= page-id (:db/id (:block/page block)))))
|
||||
sort-blocks
|
||||
db-utils/group-by-page
|
||||
(map (fn [[k blocks]]
|
||||
[k (remove-children! blocks)])))]
|
||||
result)))))
|
||||
|
||||
(defn get-date-scheduled-or-deadlines
|
||||
[journal-title]
|
||||
@@ -939,7 +951,9 @@
|
||||
ref-pages
|
||||
pages))))))
|
||||
sort-blocks
|
||||
db-utils/group-by-page)))))
|
||||
db-utils/group-by-page
|
||||
(map (fn [[k blocks]]
|
||||
[k (remove-children! blocks)])))))))
|
||||
|
||||
(defn get-block-referenced-blocks
|
||||
[block-uuid]
|
||||
|
||||
@@ -72,8 +72,8 @@
|
||||
(when-let [conn (conn/get-conn repo)]
|
||||
(try
|
||||
(d/pull conn
|
||||
selector
|
||||
eid)
|
||||
selector
|
||||
eid)
|
||||
(catch js/Error e
|
||||
nil)))))
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
([repo-url tx-data]
|
||||
(when-not config/publishing?
|
||||
(let [tx-data (->> (util/remove-nils tx-data)
|
||||
(remove nil?))]
|
||||
(remove nil?))]
|
||||
(when (seq tx-data)
|
||||
(when-let [conn (conn/get-conn repo-url false)]
|
||||
(d/transact! conn (vec tx-data))))))))
|
||||
@@ -106,4 +106,4 @@
|
||||
([repo-url key]
|
||||
(when-let [db (conn/get-conn repo-url)]
|
||||
(some-> (d/entity db key)
|
||||
key))))
|
||||
key))))
|
||||
|
||||
Reference in New Issue
Block a user