Resurfacing notes in Roam

12 Jan, 2022
0 views
roam

I currently have 100 evergreen and 494 literature notes in my Roam database, so discovery has become a problem. I do create "maps of content" in order to more easily track the notes and organize them in topics, but I wanted to have Readwise-like note resurfacing. I wanted to resurface notes, like how Readwise resurfaces highlights. Thankfully, this is possible with the Roam API.

I tag my evergreen notes with the #e tag, by adding a "meta" bullet on top of them:

- Meta::
 - Category:: #e
 - Relevant notes::
 - Created at:: <%DATE%>

In order to resurface these notes in my daily notes, I wanted to randomly select five notes that contain the #e tag.

Here’s how to do that with the Roam API:

window.roamAlphaAPI.q(`[
 :find (pull ?referencingBlock [:block/page])
 :in $ ?pagetitle
 :where
 [?referencingBlock :block/refs ?referencedPage]
 [?referencedPage :node/title ?pagetitle]
 ]`,"e")
 .map(page => window.roamAlphaAPI.pull("[:node/title]", page[0].page.id))
 .sort(() => 0.5 - Math.random())
 .map(result => `[[${result[":node/title"]}]]`).slice(0, 5) 

Put this in a SmartBlock and you’re good to go:

AltStyle によって変換されたページ (->オリジナル) /