Browse Source

feat: add namespace pages hierarchy

Tienson Qin 4 years ago
parent
commit
581bc70af3

+ 36 - 0
src/main/frontend/components/hierarchy.cljs

@@ -0,0 +1,36 @@
+(ns frontend.components.hierarchy
+  (:require [frontend.search :as search]
+            [clojure.string :as string]
+            [frontend.components.block :as block]
+            [rum.core :as rum]
+            [frontend.ui :as ui]))
+
+(defn get-relation
+  ([page]
+   (get-relation page 100))
+  ([page limit]
+   (->> (search/page-search page limit)
+        (filter #(or
+                  (= page %)
+                  (string/starts-with? % (str page "/"))
+                  (string/includes? % (str "/" page "/"))
+                  (string/ends-with? % (str "/" page))))
+        (map #(string/split % #"/"))
+        (remove #(= % [page])))))
+
+(rum/defc structures
+  [page]
+  (let [namespaces (get-relation page)]
+    (when (seq namespaces)
+      [:div.page-hierachy.mt-6
+       (ui/foldable
+        [:h2.font-bold.opacity-30 "Hierarchy"]
+        [:ul.namespaces {:style {:margin "12px 24px"}}
+         (for [namespace namespaces]
+           [:li.my-2
+            (->>
+             (for [page namespace]
+               (when (and (string? page) page)
+                 (block/page-reference false page {} nil)))
+             (interpose [:span.mx-2.opacity-30 "/"]))])]
+        true)])))

+ 3 - 0
src/main/frontend/components/page.cljs

@@ -20,6 +20,7 @@
             [frontend.components.svg :as svg]
             [frontend.components.export :as export]
             [frontend.extensions.graph-2d :as graph-2d]
+            [frontend.components.hierarchy :as hierarchy]
             [frontend.ui :as ui]
             [frontend.components.content :as content]
             [frontend.config :as config]
@@ -404,6 +405,8 @@
               (reference/references route-page-name false)
               (str route-page-name "-refs"))]
 
+           (hierarchy/structures route-page-name)
+
            ;; TODO: or we can lazy load them
            (when-not sidebar?
              [:div {:key "page-unlinked-references"}