Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Prepend the current repo name to the title if the repo exists #10953

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
129 changes: 71 additions & 58 deletions src/main/frontend/handler/route.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@
(recent-handler/add-page-to-recent! (state/get-current-repo) page-name
click-from-recent?)
(let [m (cond->
(default-page-route page-name)
(default-page-route page-name)

anchor
(assoc :query-params {:anchor anchor})

(boolean? push)
(assoc :push push))]
(boolean? push)
(assoc :push push))]
(redirect! m)))))

(defn redirect-to-whiteboard!
Expand All @@ -99,63 +99,76 @@
:path-params {:name (str name)}
:query-params (merge {:block-id block-id})}))))

(defn- display-page-name
"Return the display name of the page"
[path-params title-suffix]
(let [name (:name path-params)
block? (util/uuid-string? name)
block (when block? (db/entity [:block/uuid (uuid name)]))
page (when-not block? (db/pull [:block/name (util/page-name-sanity-lc name)]))
text (cond
(and block? block) (let [content (text/remove-level-spaces (:block/content block)
(:block/format block) (config/get-block-pattern (:block/format block)))]
(if (> (count content) 48)
(str (subs content 0 48) "...")
content))
block? "Page no longer exists!!"
:else (or (util/get-page-original-name page)
"Logseq"))]
(str text title-suffix)))

(defn get-title
[name path-params]
(case name
:home
"Logseq"
:whiteboards
(t :whiteboards)
:repos
"Repos"
:repo-add
"Add another repo"
:graph
(t :graph)
:all-files
(t :all-files)
:all-pages
(t :all-pages)
:all-journals
(t :all-journals)
:file
(str "File " (:path path-params))
:new-page
"Create a new page"
:page
(let [name (:name path-params)
block? (util/uuid-string? name)]
(if block?
(if-let [block (db/entity [:block/uuid (uuid name)])]
(let [content (text/remove-level-spaces (:block/content block)
(:block/format block) (config/get-block-pattern (:block/format block)))]
(if (> (count content) 48)
(str (subs content 0 48) "...")
content))
"Page no longer exists!!")
(let [page (db/pull [:block/name (util/page-name-sanity-lc name)])]
(or (util/get-page-original-name page)
"Logseq"))))
:whiteboard
(let [name (:name path-params)
block? (util/uuid-string? name)]
(str
(if block?
(t :untitled)
(let [page (db/pull [:block/name (util/page-name-sanity-lc name)])]
(or (util/get-page-original-name page)
"Logseq"))) " - " (t :whiteboard)))
:tag
(str "#" (:name path-params))
:diff
"Git diff"
:draw
"Draw"
:settings
"Settings"
:import
"Import data into Logseq"
"Logseq"))
(let [short-repo-name (some-> (state/get-current-repo)
db/get-repo-name
db/get-short-repo-name)
title-suffix (if short-repo-name
(str " - " short-repo-name)
"")]
(case name
:home
(or (not-empty short-repo-name) "Logseq")
:whiteboards
(str (t :whiteboards) title-suffix)
:repos
"Repos"
:repo-add
"Add another repo"
:graph
(str (t :graph) title-suffix)
:all-files
(str (t :all-files) title-suffix)
:all-pages
(str (t :all-pages) title-suffix)
:all-journals
(str (t :all-journals) title-suffix)
:file
(str "File " (:path path-params) title-suffix)
:new-page
(str "Create a new page" title-suffix)
:page
(display-page-name path-params title-suffix)
:whiteboard
(let [name (:name path-params)
block? (util/uuid-string? name)]
(str
(if block?
(t :untitled)
(let [page (db/pull [:block/name (util/page-name-sanity-lc name)])]
(or (util/get-page-original-name page)
"Logseq"))) " - " (t :whiteboard)
title-suffix))
:tag
(str "#" (:name path-params) title-suffix)
:diff
(str "Git diff" title-suffix)
:draw
(str "Draw" title-suffix)
:settings
"Settings"
:import
"Import data into Logseq"
"Logseq")))

(defn update-page-title!
[route]
Expand Down