enhance: auto redirects to source page when alias page is empty

More info here: https://discuss.logseq.com/t/improve-implementation-of-aliases/81/22?u=tienson
pull/1074/head
Tienson Qin 2021-01-05 22:50:10 +08:00
parent d46f158c83
commit 34a09048e2
3 changed files with 11 additions and 5 deletions

View File

@ -251,24 +251,26 @@
(string/capitalize original-page-name)
original-page-name)
page (string/lower-case page-name)
source-page-name (or (when source-page (:page/name source-page))
redirect-page-name (if (db/page-empty? (state/get-current-repo) page-name)
(or (when source-page (:page/name source-page))
page)
page)
href (if html-export?
(util/encode-str page)
(rfe/href :page {:name source-page-name}))]
(rfe/href :page {:name redirect-page-name}))]
[:a.page-ref
{:href href
:on-click (fn [e]
(util/stop e)
(if (gobj/get e "shiftKey")
(when-let [page-entity (db/entity [:page/name source-page-name])]
(when-let [page-entity (db/entity [:page/name redirect-page-name])]
(state/sidebar-add-block!
(state/get-current-repo)
(:db/id page-entity)
:page
{:page page-entity}))
(route-handler/redirect! {:to :page
:path-params {:name source-page-name}}))
:path-params {:name redirect-page-name}}))
(when (and contents-page?
(state/get-left-sidebar-open?))
(ui-handler/close-left-sidebar!)))}

View File

@ -50,7 +50,7 @@
get-page-properties-content get-page-referenced-blocks get-page-referenced-pages get-page-unlinked-references
get-pages get-pages-relation get-pages-that-mentioned-page get-public-pages get-tag-pages
journal-page? local-native-fs? mark-repo-as-cloned! page-alias-set page-blocks-transform pull-block
set-file-last-modified-at! transact-files-db! with-block-refs-count get-modified-pages]
set-file-last-modified-at! transact-files-db! with-block-refs-count get-modified-pages page-empty? get-alias-source-page]
[frontend.db.react
get-current-marker get-current-page get-current-priority get-handler-keys set-file-content! set-key-value

View File

@ -798,6 +798,10 @@
(db-utils/seq-flatten)
(distinct))))
(defn page-empty?
[repo page]
(nil? (:page/file (db-utils/entity repo [:page/name (string/lower-case page)]))))
(defn get-pages-relation
[repo with-journal?]
(when-let [conn (conn/get-conn repo)]