Query Exporter plugin

I’ve written a plugin that lets you run a query, and export the results to json or markdown:

It’s pretty simple, but has a few options, like sort order, grouping blocks by title, and replacing or removing page refs.

Hopefully someone finds it useful :slight_smile:

thank you very much, the plugin is useful, I have installed it.

I have a question, if I want to query a page, and sort the result by order, how to render something like below?

#+BEGIN_QUERY
{:query (and (page [[example_page]]) "keyword")
:result-transform (fn [result] 
(sort-by 
    (fn [d] (get d :block/content ))
    result))
:collapsed? true}
#+END_QUERY

From what I can tell, the plugin API can only execute advanced queries, and doesn’t have the ability to run transforms. That means that sorting has to be done by the plugin itself.

The way I’ve handled this is by expecting the data returned from the query to be in a certain structure, part of which is the value on which to sort on. Basically, the there needs to be a property of the query result called meta which has a property called sortKey.

There are details on the GitHub page: GitHub - benrhughes/logseq-query-export: A Logseq plugin for running queries and exporting the results to markdown

To repeat some of that here:

[:find (pull ?b [
  :block/content
  {(:block/page :as meta) [(:block/original-name :as title) (:block/journal-day :as sortKey)]}
 ])
 :where
 [?b :block/refs ?p]
 [?p :block/name "logseq"]
]

will return a structure like

[ 
    [ 
        { 
            content: "markdown content", 
            meta: 
            { 
                title: "title", 
                sortKey: 123 
            } 
        } 
    ] 
]

with the journal-day as the sort key.

I’m not sure how to write a query that searches a certain page for a keyword, sorry. I’m pretty new to Logseq.

ok, thank you, i will try more