Skip to content

Add support for logseq queries#85

Open
farcaller wants to merge 1 commit intoyoyurec:mainfrom
farcaller:query
Open

Add support for logseq queries#85
farcaller wants to merge 1 commit intoyoyurec:mainfrom
farcaller:query

Conversation

@farcaller
Copy link
Copy Markdown

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]))
 ]"

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant