yoyurec / logseq-banners-plugin

136 stars 11 forks source link

Add support for logseq queries #85

Open farcaller opened 4 months ago

farcaller commented 4 months ago

Hope you're alive and well @yoyurec.

This PR adds support for defining a query to generate the page props. The query is fetched from the graph config, thus allowing unique props per graph.

It solves #66 and #77.

The way the parser works, keywords don't survive the trip from the config and back into the query, so unfortunately it must be a string in the config.

Here's an example (put this into the graph config):

 :custom/banners-query
"[:find [?banner]  ; only return one entry
  :keys banner      ; the keys here will directly propagate into props
  :in $ ?id         ; id is the page id or nil if it's the home (all journals) page 
  :where

  ; we pick one of... (on id and banner)
  (or-join [?id ?banner]
           ; if the id is nil, it's the journals page:
           (and [(= ?id nil)] [(ground \"../assets/journal-index.jpg\") ?banner])
           ; otherwise, if it's a journal page:
           (and [?id :block/journal? true] [(ground \"../assets/journal-day.jpg\") ?banner])
           ; can use all kinds of queries in here, e.g. return weird-banner prop instead of banner:
           (and [?id :block/properties ?prop] [(get ?prop :weird-banner) ?banner]))
 ]"