| 
					
				 | 
			
			
				@@ -11,82 +11,70 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             [frontend.storage :as storage] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             [logseq.graph-parser.db :as gp-db] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             [logseq.db.sqlite.create-graph :as sqlite-create-graph] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            [logseq.common.util :as common-util] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             [logseq.db :as ldb] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             [frontend.components.title :as title])) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 (defn- build-links 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   [links] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  (map (fn [[from to]] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-         {:source from 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-          :target to}) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-       links)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  (keep (fn [[from to]] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          (when (and from to) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            {:source (str from) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+             :target (str to)})) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        links)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 (defn- build-nodes 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   [dark? current-page page-links tags nodes namespaces] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   (let [parents (set (map last namespaces)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         current-page (or current-page "") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        pages (set (flatten nodes))] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        pages (util/distinct-by :db/id nodes)] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     (->> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      pages 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      (remove nil?) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      (mapv (fn [p] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-             (let [p (str p) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                   current-page? (= p current-page) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+             (let [page-title (:block/title p) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                   current-page? (= page-title current-page) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    color (case [dark? current-page?] ; FIXME: Put it into CSS 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            [false false] "#999" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            [false true]  "#045591" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            [true false]  "#93a1a1" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            [true true]   "#ffffff") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                   color (if (contains? tags p) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                   color (if (contains? tags (:db/id p)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            (if dark? "orange" "green") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            color) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                   n (get page-links p 1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                   n (get page-links page-title 1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    size (int (* 8 (max 1.0 (js/Math.cbrt n))))] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                (cond-> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                  {:id p 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                   :label p 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                   :size size 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                   :color color} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                  (contains? parents p) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                  (assoc :parent true)))))))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+               (cond-> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                {:id (str (:db/id p)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                 :label (title/block-unique-title p) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                 :size size 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                 :color color 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                 :block/created-at (:block/created-at p)} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                 (contains? parents (:db/id p)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                 (assoc :parent true)))))))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                   ;; slow 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 (defn- uuid-or-asset? 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  [id] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  (or (util/uuid-string? id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      (string/starts-with? id "../assets/") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      (= id "..") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      (string/starts-with? id "assets/") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      (string/ends-with? id ".gif") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      (string/ends-with? id ".jpg") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      (string/ends-with? id ".png"))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  [label] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  (or (util/uuid-string? label) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      (string/starts-with? label "../assets/") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      (= label "..") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      (string/starts-with? label "assets/") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      (string/ends-with? label ".gif") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      (string/ends-with? label ".jpg") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      (string/ends-with? label ".png"))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 (defn- remove-uuids-and-files! 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   [nodes] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   (remove 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   (fn [node] (uuid-or-asset? (:id node))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   (fn [node] (uuid-or-asset? (:label node))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    nodes)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 (defn- normalize-page-name 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  [{:keys [nodes links page-name->title]}] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  (let [links (->> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-               (map 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                 (fn [{:keys [source target]}] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                   (let [source (get page-name->title source) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                         target (get page-name->title target)] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                     (when (and source target) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                       {:source source :target target}))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                 links) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-               (remove nil?)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        nodes (->> (remove-uuids-and-files! nodes) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  [{:keys [nodes links]}] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  (let [nodes' (->> (remove-uuids-and-files! nodes) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    (util/distinct-by (fn [node] (:id node))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                   (map (fn [node] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                          (if-let [title (get page-name->title (:id node))] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            (assoc node :id title :label title) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            nil))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    (remove nil?))] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    {:nodes nodes 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    {:nodes nodes' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      :links links})) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 (defn build-global-graph 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -95,13 +83,11 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         current-page (or (:block/name (db/get-current-page)) "")] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     (when-let [repo (state/get-current-repo)] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       (let [relation (db/get-pages-relation repo journal?) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            tagged-pages (map (fn [[x y]] [x (common-util/page-name-sanity-lc y)]) (db-model/get-all-tagged-pages repo)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            namespaces (map (fn [[x y]] [x (common-util/page-name-sanity-lc y)]) (db/get-all-namespace-relation repo)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            tagged-pages (db-model/get-all-tagged-pages repo) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            namespaces (db/get-all-namespace-relation repo) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             tags (set (map second tagged-pages)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             full-pages (db/get-all-pages repo) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            full-pages-map (into {} (map (juxt :block/name identity) full-pages)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            all-pages (map title/block-unique-title full-pages) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            page-name->title (zipmap (map :block/name full-pages) all-pages) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            db-based? (config/db-based-graph? repo) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             created-ats (map :block/created-at full-pages) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             ;; build up nodes 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -113,26 +99,23 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				               (remove ldb/journal?) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				               (not excluded-pages?) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				               (remove (fn [p] (true? (pu/get-block-property-value p :logseq.property/exclude-from-graph-view))))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            links (concat (seq relation) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                          (seq tagged-pages) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                          (seq namespaces)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            linked (set (flatten links)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            build-in-pages (->> (if (config/db-based-graph? repo) sqlite-create-graph/built-in-pages-names gp-db/built-in-pages-names) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            links (concat relation tagged-pages namespaces) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            linked (set (mapcat identity links)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            build-in-pages (->> (if db-based? sqlite-create-graph/built-in-pages-names gp-db/built-in-pages-names) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                 (map string/lower-case) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                 set) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            nodes (cond->> (map :block/name full-pages') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            nodes (cond->> full-pages' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     (not builtin-pages?) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    (remove (fn [p] (contains? build-in-pages (string/lower-case p)))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    (remove #(contains? build-in-pages (:block/name %))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     (not orphan-pages?) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    (filter #(contains? linked (string/lower-case %)))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    (filter #(contains? linked (:db/id %)))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            links (map (fn [[x y]] [(str x) (str y)]) links) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             page-links (reduce (fn [m [k v]] (-> (update m k inc) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                                  (update v inc))) {} links) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            links (build-links (remove (fn [[_ to]] (nil? to)) links)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            links (build-links links) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             nodes (build-nodes dark? (string/lower-case current-page) page-links tags nodes namespaces)] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        (-> {:nodes (map #(assoc % :block/created-at (get-in full-pages-map [(:id %) :block/created-at])) nodes) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-             :links links 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-             :page-name->title page-name->title} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        (-> {:nodes nodes 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+             :links links} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             normalize-page-name 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             (assoc :all-pages 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    {:created-at-min (apply min created-ats) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -144,95 +127,79 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     (when-let [repo (state/get-current-repo)] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       (let [page-entity (db/get-page page) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             page-id (:db/id page-entity) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            tags (if (config/db-based-graph? repo) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                   (set (map #(:block/name (db/entity repo (:db/id %))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                             (:block/tags page-entity))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                   (:tags (:block/properties page-entity))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            tags (remove #(= page %) tags) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            tags (when (config/db-based-graph? repo) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                   (set (map :db/id (:block/tags page-entity)))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            tags (set (remove #(= page-id %) tags)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             ref-pages (db/get-page-referenced-pages repo page-id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             mentioned-pages (db/get-pages-that-mentioned-page repo page-id show-journal) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            namespaces (map (fn [[x y]] [x (common-util/page-name-sanity-lc y)]) (db/get-all-namespace-relation repo)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            namespaces (db/get-all-namespace-relation repo) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             links (concat 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    namespaces 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                   (map (fn [[p _aliases]] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                          [page p]) ref-pages) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                   (map (fn [[p _aliases]] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                          [p page]) mentioned-pages) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                   (map (fn [ref-page] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                          [page-id ref-page]) ref-pages) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                   (map (fn [page] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                          [page-id page]) mentioned-pages) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    (map (fn [tag] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                          [page tag]) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                          [page-id tag]) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         tags)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            other-pages (->> (concat (map first ref-pages) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                     (map first mentioned-pages)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            other-pages (->> (concat ref-pages mentioned-pages) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                              (remove nil?) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                              (set)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             other-pages-links (mapcat 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                               (fn [page] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                 (let [page-id (:db/id (db/get-page page)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                       ref-pages (-> (map first (db/get-page-referenced-pages repo page-id)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                               (fn [page-id] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                 (let [ref-pages (-> (db/get-page-referenced-pages repo page-id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                                      (set) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                                      (set/intersection other-pages)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                       mentioned-pages (-> (map first (db/get-pages-that-mentioned-page repo page-id show-journal)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                       mentioned-pages (-> (db/get-pages-that-mentioned-page repo page-id show-journal) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                                            (set) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                                            (set/intersection other-pages))] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    (concat 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                    (map (fn [p] [page p]) ref-pages) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                    (map (fn [p] [p page]) mentioned-pages)))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    (map (fn [p] [page-id p]) ref-pages) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    (map (fn [p] [p page-id]) mentioned-pages)))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                other-pages) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             links (->> (concat links other-pages-links) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        (remove nil?) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        (distinct) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        (build-links)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             nodes (->> (concat 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        [page] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        (map first ref-pages) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        (map first mentioned-pages) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        [page-id] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        ref-pages 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        mentioned-pages 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         tags) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        (remove nil?) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                       (distinct)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            nodes (build-nodes dark? page links (set tags) nodes namespaces) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            full-pages (db/get-all-pages repo) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            all-pages (map common-util/get-page-title full-pages) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            page-name->title (zipmap (map :block/name full-pages) all-pages)] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                       (map db/entity) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                       (util/distinct-by :db/id)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            nodes (build-nodes dark? page links tags nodes namespaces)] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         (normalize-page-name 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          {:nodes nodes 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-          :links links 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-          :page-name->title page-name->title}))))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          :links links}))))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 (defn build-block-graph 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   "Builds a citation/reference graph for a given block uuid." 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  [block theme] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  [block-uuid theme] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   (when-let [repo (state/get-current-repo)] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    (let [dark? (= "dark" theme) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-          ref-blocks (db/get-block-referenced-blocks block) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-          namespaces (map (fn [[x y]] [x (common-util/page-name-sanity-lc y)]) (db/get-all-namespace-relation repo)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-          other-blocks (->> (concat (map first ref-blocks)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            (remove nil?) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            (set)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-          other-blocks-links (mapcat 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                              (fn [block] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                (let [ref-blocks (-> (map first (db/get-block-referenced-blocks block)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                                     (set) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                                     (set/intersection other-blocks))] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                  (concat 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                   (map (fn [p] [block p]) ref-blocks)))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                              other-blocks) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-          links (concat 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                 (->> other-blocks-links 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                      (remove nil?) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                      (distinct) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                      (build-links)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                 namespaces) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-          nodes (->> (concat 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                      [block] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                      (map first ref-blocks)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                     (remove nil?) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                     (distinct) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    (when-let [block (and (uuid? block-uuid) (db/entity [:block/uuid block-uuid]))] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      (let [dark? (= "dark" theme) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ref-blocks (->> (concat (:block/_refs block) (:block/refs block)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            (map (fn [b] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                   (if (ldb/page? b) b (:block/page b)))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            (remove (fn [node] (= (:db/id block) (:db/id node)))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            (util/distinct-by :db/id)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            namespaces (db/get-all-namespace-relation repo) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            links (->> (concat 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        namespaces 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        (map (fn [p] [(:db/id block) (:db/id p)]) ref-blocks)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                       (remove nil?) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                       (distinct) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                       (build-links)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            nodes (->> (cons block ref-blocks) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                       distinct 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        ;; FIXME: get block tags 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                     ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-          nodes (build-nodes dark? block links #{} nodes namespaces)] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      (normalize-page-name 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-       {:nodes nodes 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        :links links})))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                       ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            nodes (build-nodes dark? block links #{} nodes namespaces)] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        (normalize-page-name 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         {:nodes nodes 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          :links links}))))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 (defn n-hops 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   "Get all nodes that are n hops from nodes (a collection of node ids)" 
			 |