Advertisement
bgrolleman

On This Day Query Explained

Jan 28th, 2023
2,171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {
  2.  ; Set Title
  3.  :title "⌛ On this day..."
  4.  ; Get all blocks
  5.     :query [:find (pull ?b [*])
  6.        ; We want to filter on Today, so we get that variable as input (See input)
  7.        :in $ ?today
  8.        :where
  9.        ; Now to filter, first, we only want journal pages
  10.        [?b :block/page ?p]
  11.        [?p :page/journal? true]
  12.        ; Then we fetch the Day of the Journal page, store it in ?jd
  13.        [?p :page/journal-day ?jd]    
  14.        ; Tricky part, but what happens it turns date into string
  15.        ; Not sure, but I assume unix timeformat so YYYYMMDD
  16.        ; Then use subs to cutoff the YYYY
  17.        [(str ?jd) ?jds]    
  18.        [(subs ?jds 4 8) ?md1]
  19.        ; Then we do the same trick for today
  20.        [(str ?today) ?td]
  21.        [(subs ?td 4 8) ?md2]
  22.        ; What we are left with is a compare of Today without year, matches pages
  23.        ; without year
  24.        [(= ?md1 ?md2)]
  25.        ; Finally filter out today, as that's not history....yet
  26.        [(< ?jd ?today)]
  27.     ]
  28.     ; Make Logseq provide todays date
  29.     :inputs [:today]
  30.     ; Why yes we want to see the year
  31.     :breadcrumb-show? true
  32.     ; And show me everything unfolded
  33.     :collapsed? False
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement