Skip to content

Commit

Permalink
impl zd/index key
Browse files Browse the repository at this point in the history
  • Loading branch information
carbon-hvze committed Jul 28, 2023
1 parent 53c6cf8 commit 36ac7c9
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/zd/blocks/zd.clj
Original file line number Diff line number Diff line change
@@ -1,12 +1,51 @@
(ns zd.blocks.zd
(:require [zd.link :as link]
[zd.zentext :as zentext]
[zd.datalog :as d]
[zd.memstore :as memstore]
[zd.meta :as meta]
[clojure.string :as str]
[stylo.core :refer [c]]
[zd.methods :as methods]))

(defn indent-item [pth]
(let [lvl (count pth)
scale 1]
[:div {:class (c :flex [:py 1] [:px 1] :items-center {:position "relative"})
:style (str "padding-left:" (* scale (- lvl 1)) "rem")}
(map-indexed (fn [i el]
[:div
{:style (when-not (= lvl 1)
"border-left: 1px solid #ccc;")
:class (c [:w 2] {:top "-0.3rem"
:position "absolute"
:bottom 0})}])
pth)
(when-not (= lvl 1)
[:div {:style (str "left:" (* scale lvl) "rem")
:class (c {:border-top "1px solid #ccc"
:width "0.5rem"
:top "13px"})}])]))

(defmethod methods/renderkey :zd/index
[ztx ctx block]
(let [docs (->> '{:find [?docname]
:where [[?e :meta/docname ?docname]]
:order-by [[?docname :asc]]}
(d/query ztx)
(map (fn [v] {:s (first v)
:ps (str/split (str (first v)) #"\.")}))
(partition-by #(= 1 (count (:ps %))))
(partition 2)
(map (fn [[h t]]
(concat h t))))]
[:div {:class (c :flex :flex-wrap [:w "100%"])}
(for [gr docs]
[:div {:class (c [:py 2] :text-sm :flex-col :flex)}
(for [{:keys [s ps]} gr]
[:div (conj (indent-item ps)
(link/symbol-link ztx s))])])]))

(defmethod methods/renderkey :zd/docname
[ztx ctx {data :data :as block}]
[:div {:class (str "badge " (name (c :border [:my 1] [:mr 2] :inline-flex :rounded [:p 0])))}
Expand Down

0 comments on commit 36ac7c9

Please sign in to comment.