Skip to content

Commit

Permalink
fix(props): show hierarchy for page alias
Browse files Browse the repository at this point in the history
  • Loading branch information
andelf committed Nov 17, 2022
1 parent dd7460f commit 20c527a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
12 changes: 6 additions & 6 deletions deps/graph-parser/src/logseq/graph_parser/text.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@
(remove-level-space-aux! text block-pattern space? trim-left?)))))

(defn namespace-page?
[p]
(and (string? p)
(string/includes? p "/")
(not (string/starts-with? p "../"))
(not (string/starts-with? p "./"))
(not (gp-util/url? p))))
[page-name]
(and (string? page-name)
(string/includes? page-name "/")
(not (string/starts-with? page-name "../"))
(not (string/starts-with? page-name "./"))
(not (gp-util/url? page-name))))

(defn parse-non-string-property-value
"Return parsed non-string property value or nil if none is found"
Expand Down
45 changes: 24 additions & 21 deletions src/main/frontend/components/hierarchy.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,34 @@
[rum.core :as rum]
[frontend.util :as util]))

(defn get-relation
(defn- get-relation
"Get all parent pages along the namespace hierarchy path.
If there're aliases, only use the first namespaced alias."
[page]
(when-let [page (or (text/get-nested-page-name page) page)]
(when (or (text/namespace-page? page)
(:block/_namespace (db/entity [:block/name (util/page-name-sanity-lc page)])))
(let [repo (state/get-current-repo)
namespace-pages (db/get-namespace-pages repo page)
parent-routes (db-model/get-page-namespace-routes repo page)
pages (->> (concat namespace-pages parent-routes)
(distinct)
(sort-by :block/name)
(map (fn [page]
(or (:block/original-name page) (:block/name page))))
(map #(string/split % "/")))
page-namespace (db-model/get-page-namespace repo page)
page-namespace (util/get-page-original-name page-namespace)]
(cond
(seq pages)
pages
(let [repo (state/get-current-repo)
aliases (db/get-page-alias-names repo page)
all-page-names (conj aliases page)]
(when-let [page (first (filter text/namespace-page? all-page-names))]
(let [namespace-pages (db/get-namespace-pages repo page)
parent-routes (db-model/get-page-namespace-routes repo page)
pages (->> (concat namespace-pages parent-routes)
(distinct)
(sort-by :block/name)
(map (fn [page]
(or (:block/original-name page) (:block/name page))))
(map #(string/split % "/")))
page-namespace (db-model/get-page-namespace repo page)
page-namespace (util/get-page-original-name page-namespace)]
(cond
(seq pages)
pages

page-namespace
[(string/split page-namespace "/")]
page-namespace
[(string/split page-namespace "/")]

:else
nil)))))
:else
nil))))))

(rum/defc structures
[page]
Expand Down

0 comments on commit 20c527a

Please sign in to comment.