Skip to content

Instantly share code, notes, and snippets.

@tombarys
Last active October 5, 2023 01:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tombarys/f1d5896cddfc655fa72b822de6ecbcbc to your computer and use it in GitHub Desktop.
Save tombarys/f1d5896cddfc655fa72b822de6ecbcbc to your computer and use it in GitHub Desktop.
Show children block count
;; Instructions for including the Clojure script (this) into your Roam can be found in my article
;; here: https://lifehacky.net/how-to-list-namespaces-and-find-more-in-roam-research-5c25d9f24556
;; Search for section "How to make it work in your Roam?" and think of "better-search" as of "children-block-count"
(ns reddit.8-7-2022-reagent
(:require [roam.datascript :as rd]
[reagent.core :as r]
[roam.datascript.reactive :as rdr]))
(defn show-num [uid]
(r/with-let [*kids (rdr/q '[:find (count ?b) .
:in $ ?uid
:where
[?a :block/uid ?uid]
[?b :block/parents ?a]] uid)]
[:span @*kids]))
(defn main [{:keys [block-uid]}]
(show-num block-uid))
@tombarys
Copy link
Author

tombarys commented Jul 8, 2022

CleanShot 2022-07-08 at 11 27 40

@Christian-Klaperek
Copy link

This is exactly what I need!!
What is clj? Where do I copy and paste this code?
Well I have to paste this code in every parent block? Or Fri I paste it just once, and it automatically works on all parent blocks? 😄

@tombarys
Copy link
Author

tombarys commented Oct 4, 2023

Instructions for including the Clojure script (this) into your Roam can be found in my article here: https://lifehacky.net/how-to-list-namespaces-and-find-more-in-roam-research-5c25d9f24556. Search there for section "How to make it work in your Roam?" and think of "better-search" as of "children-block-count".

And yes, you have to put the {{[roam/render]: (source_block_ID)}} into every parent you want to count.

@Christian-Klaperek
Copy link

thank you. I got as far as step number 2, and then got overwhelmed and gave up ....

image

@Christian-Klaperek
Copy link

The next step 2.2 says "Go to your [[Better search]] page and start editing some empty block."
but in the Better Search page, I can not create any new blocks. There is just the code in the Clojure code block, and can do nothing else ...

@Christian-Klaperek
Copy link

I went to a differnt page, and tried to add {{[roam/render]: (source_block_ID)}}

But when I add my ID for the source block which is ((l2p4Rv9FQ)) I only get this:

image

@tombarys
Copy link
Author

tombarys commented Oct 4, 2023

If you are ok with it, I can show you via short online meeting. What timezone are you in? Me CET.

@Christian-Klaperek
Copy link

Christian-Klaperek commented Oct 4, 2023 via email

@tombarys
Copy link
Author

tombarys commented Oct 4, 2023

For me in CET, time is -6 hours comparing to ICT. So generally 2pm to 2am your time is ok for me. But I have to find some window. Today I will be online again too late for you. Tommorow we can try around 15:30 your time? Send me your email pls.t

@Christian-Klaperek
Copy link

Christian-Klaperek commented Oct 4, 2023 via email

@tombarys
Copy link
Author

tombarys commented Oct 4, 2023

Sorry, Christian, your e-mail is hidden as of GitHub policy. Please write me through the https://barys.me form (remember to fill in the e-mail) at the bottom left. I will send you a Zoom link then at 15:30 ICT. :)

@Christian-Klaperek
Copy link

Christian-Klaperek commented Oct 5, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment