And as a template
Using :current-page
for the query and <% current page %>
for the function while handling lower-case and the “[[” “]]” -brackets.
Note that one can use this for different properties (e.g. “type” instead of “authors”) using in both the query and the function :type
instead of :authors
- the rest can actually stay the same (leads to the variable names to be strange though)
query-table:: true
query-properties:: [:title :authors]
template:: Person's Work
#+BEGIN_QUERY
{:title "Work"
:query [:find (pull ?b[*])
:in $ ?current-page
:where
[?b :block/properties ?prop]
[(get ?prop :authors) ?authors]
[?me-low :block/name ?current-page]
[?me-low :block/original-name ?me]
[(contains? ?authors ?me)]]
:inputs [:current-page]}
#+END_QUERY
- **Coauthors**
{{function (let [authors-list (map (fn [x] (:authors x)) result)] (let [authors (set/select (partial (fn [a b] (not= a (str/lower-case (str "[[" b "]]")))) (str/lower-case "<% current page %>")) (reduce set/union authors-list))](for [author authors] (let [num (count (filter identity (map (fn [x] (contains? x author)) authors-list)))](str author ": " num "\n")))))}}
Only the function, formatted by calva (Calva: Clojure & ClojureScript Interactive Programming - Visual Studio Marketplace):
(let [authors-list
(map (fn [x] (:authors x))
result)]
(let [authors
(set/select
(partial
(fn [a b]
(not= a
(str/lower-case (str "[[" b "]]"))))
(str/lower-case "<% current page %>"))
(reduce set/union authors-list))]
(for [author authors]
(let [num
(count
(filter identity (map (fn [x] (contains? x author)) authors-list)))]
(str author ": " num "\n")))))