mirror of
https://github.com/logseq/logseq.git
synced 2026-05-05 19:36:35 +00:00
refactor: rename :block/original-name to :block/title
This commit is contained in:
@@ -35,7 +35,7 @@
|
||||
(->> (d/q '[:find (pull ?b [*])
|
||||
:in $
|
||||
:where
|
||||
[?b :block/original-name]
|
||||
[?b :block/title]
|
||||
[?b :block/name]] db)
|
||||
|
||||
(map (fn [[page]]
|
||||
@@ -61,5 +61,5 @@
|
||||
(->> (d/datoms db :avet :block/name)
|
||||
(map (fn [d]
|
||||
(let [e (d/entity db (:e d))]
|
||||
[(:block/original-name e)
|
||||
[(:block/title e)
|
||||
(block->content repo db (:block/uuid e) {} {})])))))
|
||||
|
||||
@@ -141,7 +141,7 @@
|
||||
journal-page? (and journal-page? (not (string/blank? journal-title)))
|
||||
filename (if journal-page?
|
||||
(worker-date/date->file-name journal-title (:journal-file-name-format context))
|
||||
(-> (or (:block/original-name page-block) (:block/name page-block))
|
||||
(-> (or (:block/title page-block) (:block/name page-block))
|
||||
wfu/file-name-sanity))
|
||||
sub-dir (cond
|
||||
journal-page? (:journals-directory context)
|
||||
|
||||
@@ -10,46 +10,46 @@
|
||||
;; FIXME: bring it back, decouple this from page renaming though
|
||||
(comment
|
||||
(defn merge-pages!
|
||||
[repo conn config from-page to-page]
|
||||
(let [from-page-name (:block/original-name from-page)
|
||||
to-page-name (:block/original-name to-page)]
|
||||
(when (and from-page to-page
|
||||
(not= from-page-name to-page-name))
|
||||
(let [db @conn
|
||||
to-id (:db/id to-page)
|
||||
from-id (:db/id from-page)
|
||||
datoms (d/datoms @conn :avet :block/page from-id)
|
||||
block-eids (mapv :e datoms)
|
||||
blocks (d/pull-many db '[:db/id :block/page :block/refs :block/path-refs :block/parent] block-eids)
|
||||
blocks-tx-data (map (fn [block]
|
||||
(let [id (:db/id block)]
|
||||
(cond->
|
||||
{:db/id id
|
||||
:block/page {:db/id to-id}
|
||||
:block/refs (rename-update-block-refs! (:block/refs block) from-id to-id)
|
||||
:block/order (db-order/gen-key nil)}
|
||||
[repo conn config from-page to-page]
|
||||
(let [from-page-name (:block/title from-page)
|
||||
to-page-name (:block/title to-page)]
|
||||
(when (and from-page to-page
|
||||
(not= from-page-name to-page-name))
|
||||
(let [db @conn
|
||||
to-id (:db/id to-page)
|
||||
from-id (:db/id from-page)
|
||||
datoms (d/datoms @conn :avet :block/page from-id)
|
||||
block-eids (mapv :e datoms)
|
||||
blocks (d/pull-many db '[:db/id :block/page :block/refs :block/path-refs :block/parent] block-eids)
|
||||
blocks-tx-data (map (fn [block]
|
||||
(let [id (:db/id block)]
|
||||
(cond->
|
||||
{:db/id id
|
||||
:block/page {:db/id to-id}
|
||||
:block/refs (rename-update-block-refs! (:block/refs block) from-id to-id)
|
||||
:block/order (db-order/gen-key nil)}
|
||||
|
||||
(= (:block/parent block) {:db/id from-id})
|
||||
(assoc :block/parent {:db/id to-id})))) blocks)
|
||||
replace-ref-tx-data (replace-page-ref from-page to-page)
|
||||
tx-data (concat blocks-tx-data replace-ref-tx-data)]
|
||||
(= (:block/parent block) {:db/id from-id})
|
||||
(assoc :block/parent {:db/id to-id})))) blocks)
|
||||
replace-ref-tx-data (replace-page-ref from-page to-page)
|
||||
tx-data (concat blocks-tx-data replace-ref-tx-data)]
|
||||
|
||||
(rename-page-aux repo conn config from-page-name to-page-name
|
||||
:merge? true
|
||||
:other-tx tx-data)
|
||||
(rename-page-aux repo conn config from-page-name to-page-name
|
||||
:merge? true
|
||||
:other-tx tx-data)
|
||||
|
||||
(worker-page/delete! repo conn (:block/uuid from-page) {:rename? true}))))))
|
||||
(worker-page/delete! repo conn (:block/uuid from-page) {:rename? true}))))))
|
||||
|
||||
(defn- rename-page-aux
|
||||
"Only accepts unsanitized page names"
|
||||
[repo conn page new-name & {:keys [merge? other-tx]}]
|
||||
(let [old-page-name (:block/original-name page)
|
||||
(let [old-page-name (:block/title page)
|
||||
new-page-name (common-util/page-name-sanity-lc new-name)]
|
||||
(when (and repo page)
|
||||
(let [page-txs (when-not merge?
|
||||
[{:db/id (:db/id page)
|
||||
:block/name new-page-name
|
||||
:block/original-name new-name}])
|
||||
:block/title new-name}])
|
||||
txs (concat page-txs other-tx)]
|
||||
(ldb/transact! conn txs {:outliner-op :rename-page
|
||||
:data (cond->
|
||||
@@ -61,14 +61,14 @@
|
||||
"Original names (unsanitized only)"
|
||||
[repo conn page new-name]
|
||||
(rename-page-aux repo conn page new-name)
|
||||
(println "Renamed " (:block/original-name page) " to " new-name))
|
||||
(println "Renamed " (:block/title page) " to " new-name))
|
||||
|
||||
(defn rename!
|
||||
[repo conn _config page-uuid new-name & {:keys [persist-op?]
|
||||
:or {persist-op? true}}]
|
||||
(let [db @conn]
|
||||
(when-let [page-e (d/entity db [:block/uuid page-uuid])]
|
||||
(let [old-name (:block/original-name page-e)
|
||||
(let [old-name (:block/title page-e)
|
||||
new-name (string/trim new-name)
|
||||
old-page-name (common-util/page-name-sanity-lc old-name)
|
||||
new-page-name (common-util/page-name-sanity-lc new-name)
|
||||
@@ -89,7 +89,7 @@
|
||||
(if (= old-page-name new-page-name) ; case changed
|
||||
(ldb/transact! conn
|
||||
[{:db/id (:db/id page-e)
|
||||
:block/original-name new-name}]
|
||||
:block/title new-name}]
|
||||
{:persist-op? persist-op?
|
||||
:outliner-op :rename-page})
|
||||
(rename-page! repo conn page-e new-name)))))))
|
||||
|
||||
@@ -114,13 +114,13 @@
|
||||
[db config page new-name]
|
||||
;; update all pages which have references to this page
|
||||
(let [to-page (ldb/get-page db new-name)
|
||||
old-original-name (:block/original-name page)
|
||||
old-title (:block/title page)
|
||||
blocks (:block/_refs (d/entity db (:db/id page)))
|
||||
tx (->> (map (fn [{:block/keys [uuid content properties format] :as block}]
|
||||
(let [content (let [content' (replace-old-page! config content old-original-name new-name format)]
|
||||
(let [content (let [content' (replace-old-page! config content old-title new-name format)]
|
||||
(when-not (= content' content)
|
||||
content'))
|
||||
properties (let [properties' (walk-replace-old-page! config properties old-original-name new-name format)]
|
||||
properties (let [properties' (walk-replace-old-page! config properties old-title new-name format)]
|
||||
(when-not (= properties' properties)
|
||||
properties'))]
|
||||
(when (or content properties)
|
||||
@@ -138,8 +138,8 @@
|
||||
|
||||
(defn rename-update-namespace!
|
||||
"update :block/namespace of the renamed block"
|
||||
[repo conn config page old-original-name new-name]
|
||||
(let [old-namespace? (text/namespace-page? old-original-name)
|
||||
[repo conn config page old-title new-name]
|
||||
(let [old-namespace? (text/namespace-page? old-title)
|
||||
new-namespace? (text/namespace-page? new-name)]
|
||||
(cond
|
||||
new-namespace?
|
||||
@@ -224,12 +224,12 @@
|
||||
new-page-name (common-util/page-name-sanity-lc new-name)
|
||||
page (d/pull @conn '[*] [:block/name old-page-name])]
|
||||
(when (and repo page)
|
||||
(let [old-original-name (:block/original-name page)
|
||||
(let [old-title (:block/title page)
|
||||
page-txs (when-not merge?
|
||||
[{:db/id (:db/id page)
|
||||
:block/uuid (:block/uuid page)
|
||||
:block/name new-page-name
|
||||
:block/original-name new-name}])
|
||||
:block/title new-name}])
|
||||
{:keys [old-path new-path tx-data]} (update-file-tx db old-page-name new-name)
|
||||
txs (concat page-txs
|
||||
other-tx
|
||||
@@ -250,7 +250,7 @@
|
||||
(merge {:old-path old-path
|
||||
:new-path new-path}))})
|
||||
|
||||
(rename-update-namespace! repo conn config page old-original-name new-name)))))
|
||||
(rename-update-namespace! repo conn config page old-title new-name)))))
|
||||
|
||||
(defn- rename-namespace-pages!
|
||||
"Original names (unsanitized only)"
|
||||
@@ -258,8 +258,8 @@
|
||||
(let [pages (ldb/get-namespace-pages @conn old-name {})
|
||||
page (d/pull @conn '[*] [:block/name (common-util/page-name-sanity-lc old-name)])
|
||||
pages (cons page pages)]
|
||||
(doseq [{:block/keys [name original-name]} pages]
|
||||
(let [old-page-title (or original-name name)
|
||||
(doseq [{:block/keys [name title]} pages]
|
||||
(let [old-page-title (or title name)
|
||||
;; only replace one time, for the case that the namespace is a sub-string of the sub-namespace page name
|
||||
;; Example: has pages [[work]] [[work/worklog]],
|
||||
;; we want to rename [[work/worklog]] to [[work1/worklog]] when rename [[work]] to [[work1]],
|
||||
@@ -279,8 +279,8 @@
|
||||
nested-pages-ns (ldb/get-pages-by-name-partition @conn ns-prefix)]
|
||||
(when nested-pages
|
||||
;; rename page "[[obsidian]] is a tool" to "[[logseq]] is a tool"
|
||||
(doseq [{:block/keys [name original-name]} nested-pages]
|
||||
(let [old-page-title (or original-name name)
|
||||
(doseq [{:block/keys [name title]} nested-pages]
|
||||
(let [old-page-title (or title name)
|
||||
new-page-title (string/replace
|
||||
old-page-title
|
||||
(page-ref/->page-ref old-ns-name)
|
||||
@@ -290,8 +290,8 @@
|
||||
(println "Renamed " old-page-title " to " new-page-title)))))
|
||||
(when nested-pages-ns
|
||||
;; rename page "[[obsidian/page1]] is a tool" to "[[logseq/page1]] is a tool"
|
||||
(doseq [{:block/keys [name original-name]} nested-pages-ns]
|
||||
(let [old-page-title (or original-name name)
|
||||
(doseq [{:block/keys [name title]} nested-pages-ns]
|
||||
(let [old-page-title (or title name)
|
||||
new-page-title (string/replace
|
||||
old-page-title
|
||||
(common-util/format ns-prefix-format-str old-ns-name)
|
||||
@@ -305,7 +305,7 @@
|
||||
:or {persist-op? true}}]
|
||||
(let [db @conn
|
||||
page-e (d/entity db [:block/uuid page-uuid])
|
||||
old-name (:block/original-name page-e)
|
||||
old-name (:block/title page-e)
|
||||
new-name (string/trim new-name)
|
||||
old-page-name (common-util/page-name-sanity-lc old-name)
|
||||
new-page-name (common-util/page-name-sanity-lc new-name)
|
||||
@@ -329,7 +329,7 @@
|
||||
(= old-page-name new-page-name) ; case changed
|
||||
(ldb/transact! conn
|
||||
[{:db/id (:db/id page-e)
|
||||
:block/original-name new-name}]
|
||||
:block/title new-name}]
|
||||
{:persist-op? persist-op?
|
||||
:outliner-op :rename-page})
|
||||
|
||||
|
||||
@@ -169,12 +169,12 @@
|
||||
|
||||
(defmethod local-block-ops->remote-ops-aux :update-page-op
|
||||
[_ & {:keys [db block-uuid *remote-ops]}]
|
||||
(when-let [{page-name :block/name original-name :block/original-name}
|
||||
(when-let [{page-name :block/name title :block/title}
|
||||
(d/entity db [:block/uuid block-uuid])]
|
||||
(swap! *remote-ops conj
|
||||
[:update-page {:block-uuid block-uuid
|
||||
:page-name page-name
|
||||
:original-name (or original-name page-name)}])))
|
||||
:title (or title page-name)}])))
|
||||
|
||||
(defmethod local-block-ops->remote-ops-aux :remove-op
|
||||
[_ & {:keys [db remove-op *remote-ops]}]
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
[:map
|
||||
[:block-uuid :uuid]
|
||||
[:page-name :string]
|
||||
[:original-name :string]]]]
|
||||
[:title :string]]]]
|
||||
[:remove-page
|
||||
[:cat :keyword
|
||||
[:map
|
||||
@@ -128,8 +128,7 @@
|
||||
[:map
|
||||
[:op :keyword]
|
||||
[:self :uuid]
|
||||
[:page-name :string]
|
||||
[:block/original-name :string]
|
||||
[:block/title :string]
|
||||
[:db/ident {:optional true} :keyword]
|
||||
[:block/order {:optional true} db-malli-schema/block-order]
|
||||
[::m/default extra-attr-map-schema]]]
|
||||
|
||||
@@ -79,7 +79,7 @@
|
||||
block-uuid (:block/uuid (d/entity db-after e))
|
||||
a->add?->v->t (e->a->add?->v->t e)
|
||||
{add?->block-name->t :block/name
|
||||
add?->block-original-name->t :block/original-name
|
||||
add?->block-title->t :block/title
|
||||
add?->block-uuid->t :block/uuid
|
||||
add?->block-parent->t :block/parent
|
||||
add?->block-order->t :block/order}
|
||||
@@ -87,7 +87,7 @@
|
||||
[retract-block-uuid t1] (some-> add?->block-uuid->t (get false) first)
|
||||
[retract-block-name _] (some-> add?->block-name->t (get false) first)
|
||||
[add-block-name t2] (some-> add?->block-name->t latest-add?->v->t (get-first-vt true))
|
||||
[add-block-original-name t3] (some-> add?->block-original-name->t
|
||||
[add-block-title t3] (some-> add?->block-title->t
|
||||
latest-add?->v->t
|
||||
(get-first-vt true))
|
||||
[add-block-parent t4] (some-> add?->block-parent->t latest-add?->v->t (get-first-vt true))
|
||||
@@ -105,7 +105,7 @@
|
||||
(or add-block-parent add-block-order)
|
||||
(conj [:move (or t4 t5) {:block-uuid block-uuid}])
|
||||
|
||||
(or add-block-name add-block-original-name)
|
||||
(or add-block-name add-block-title)
|
||||
(conj [:update-page (or t2 t3) {:block-uuid block-uuid}]))
|
||||
update-op (when-let [av-coll (not-empty (update-op-av-coll db-before db-after a->add?->v->t*))]
|
||||
(let [t (max-t a->add?->v->t*)]
|
||||
|
||||
@@ -497,10 +497,10 @@
|
||||
[repo conn update-page-ops]
|
||||
(let [config (worker-state/get-config repo)]
|
||||
(doseq [{:keys [self _page-name]
|
||||
original-name :block/original-name
|
||||
title :block/title
|
||||
:as op-value} update-page-ops]
|
||||
(let [create-opts {:uuid self}
|
||||
[_ page-name page-uuid] (worker-page/rtc-create-page! conn config (ldb/read-transit-str original-name) create-opts)]
|
||||
[_ page-name page-uuid] (worker-page/rtc-create-page! conn config (ldb/read-transit-str title) create-opts)]
|
||||
;; TODO: current page-create fn is buggy, even provide :uuid option, it will create-page with different uuid,
|
||||
;; if there's already existing same name page
|
||||
(assert (= page-uuid self) {:page-name page-name :page-uuid page-uuid :should-be self})
|
||||
|
||||
@@ -207,7 +207,7 @@
|
||||
;; closed value
|
||||
(property-value-when-closed e)
|
||||
;; :page or :date properties
|
||||
(:block/original-name e)
|
||||
(:block/title e)
|
||||
;; block generated by template
|
||||
(and
|
||||
(:logseq.property/created-from-template e)
|
||||
@@ -220,7 +220,7 @@
|
||||
(remove string/blank?))
|
||||
hide? (get-in property [:block/schema :hide?])]
|
||||
(when (and (not hide?) (seq values))
|
||||
(str (:block/original-name property)
|
||||
(str (:block/title property)
|
||||
": "
|
||||
(string/join "; " values))))))
|
||||
(string/join ", "))))
|
||||
@@ -265,7 +265,7 @@
|
||||
{:id (str (:block/uuid p))
|
||||
:name (:block/name p)
|
||||
:built-in? (boolean (db-property/property-value-content (:logseq.property/built-in? p)))
|
||||
:original-name (:block/original-name p)}))
|
||||
:title (:block/title p)}))
|
||||
|
||||
(defn- hidden-page?
|
||||
[page]
|
||||
@@ -290,7 +290,7 @@
|
||||
(map original-page-name->index)
|
||||
(bean/->js))
|
||||
indice (fuse. pages
|
||||
(clj->js {:keys ["original-name"]
|
||||
(clj->js {:keys ["title"]
|
||||
:shouldSort true
|
||||
:tokenize true
|
||||
:distance 1024
|
||||
@@ -328,7 +328,7 @@
|
||||
datoms (filter
|
||||
(fn [datom]
|
||||
;; Capture any direct change on page display title, page ref or block content
|
||||
(contains? #{:block/uuid :block/name :block/original-name :block/content :block/properties :block/schema} (:a datom)))
|
||||
(contains? #{:block/uuid :block/name :block/title :block/content :block/properties :block/schema} (:a datom)))
|
||||
data)]
|
||||
(when (seq datoms)
|
||||
(get-blocks-from-datoms-impl repo tx-report datoms))))
|
||||
@@ -396,7 +396,7 @@
|
||||
(keep
|
||||
(fn [{:keys [item]}]
|
||||
{:id (:id item)
|
||||
:title (:original-name item)}))
|
||||
:title (:title item)}))
|
||||
(distinct)
|
||||
(filter (fn [{:keys [title]}]
|
||||
(exact-matched? q title)))
|
||||
|
||||
Reference in New Issue
Block a user