How to sort by journal day of block

I have blocks that I always define in my journal as follows:

October 4th, 2022
- Some article
type:: content/article

- Some podcast
type:: content/podcast

I successfully created a query to get all contents with this:

(or [(contains? ?type "content/article")]
     [(contains? ?type "content/podcast")])

And this filter also works, which makes sure we’re looking at entries defined in the journal:

            [?b :block/parent ?parent] ; 
            [?parent :block/journal? true]

Now I would like to sort the results by the day of the journal entry. I know that journal blocks define a :block/journal-day property.

I tried assembling a :result-transform to sort it but with no success.

I tried this:

  :result-transform (fn [result]
	                   (sort-by (fn [h]
	                     (get-in h [:block/parent :block/journal-day])) result));

and also this

  :result-transform (fn [result]
	                   (sort-by (fn [h]
	                     (get (get h ::block/parent) :block/journal-day)) result))

But nothing works. It seems to me like it could just be some syntax that I am not getting right.
Could someone please help me with this?

Ok, so the following worked!

:result-transform (fn [result]
	                   (sort-by (fn [h]
	                     (get (get h :block/page) :block/journal-day)) result))
1 Like

I will mark the above as a solution, but please let me know if there are nicer ways to go about it :smile:

1 Like