Auto-assign tags/page references to blocks based on query results, "dynamic" pages

It would be neat to automatically assign tags (= page references) to blocks based on the results of a simple or advanced query. This is useful in situations, where the tag can be derived by looking at the block’s content, so the block does not need to be tagged manually.

The name can be a link to an existing page OR a new “dynamic” page (there might be a better term).
Dynamic page = create a name for query results and refer to them by using this name in the same way as normal page links.

Example 1: Assign page name Logseq Discourse to all blocks with content https://discuss.logseq.com. That should give us all blocks with a forum URL, like

- Link to the forum: https://discuss.logseq.com/
- [My feature request](https://discuss.logseq.com/t/allow-to-use-more-clojure-functions-in-advanced-queries-akin-to-datomic-graph-traversal/16275)

Now it’s like all forum URLs have a page link [[Logseq Discourse]], but done done automatically! We are able refer to this set of queried blocks in other places:

- Find all forum discussions [here]([[Logseq Discourse]])

Where to actually declare this name "Logseq Discourse" and connect it to a query?
I am not sure, it can be a dummy page with a query as content. But it would be wasteful to create dummy pages and markdown files only to get a name, so might define these on a block level:

- dynamic-page:: Logseq Discourse
  {{query "https://discuss.logseq.com"}}

Example 2: Find all Markdown codeblocks and give them a name [[My code blocks]].

- dynamic-page:: My code blocks
  {{query "```"}}
- dynamic-page:: My Python code blocks
  {{query "```python"}}

Example 3: Compose dynamic pages from smaller components
Think LEGO :grinning:. Build up more complex things from smaller bricks. First, have everything related to Clojure docs under name [[Clojure documentation]]:

- dynamic-page:: Clojure documentation
  {{query (or "https://clojure.org" "https://clojuredocs.org")}}

Then collect everything Clojure-related under [[All about Clojure]], reusing above name:

- dynamic-page:: All about Clojure
  {{query (or [[Clojure]] [[Clojure documentation]])}}

[[Clojure]] is a normal page here. Now link to [[All about Clojure]].

Advantages

  • Incoorporate queries naturally into Logseq via page links we all know.
  • Craft once, reuse everywhere
    • Might be useful for newcomers, that don’t know how to write more complex queries. Get help, copy paste it and don’t care about implementation.
  • No manual tagging of blocks in those cases, where page link can be derived by looking at block content or context (via queries). Examples: URLs, Markdown codeblocks, quotes, Regex.

This sounds easy to implement, but what do we really want to achieve?

  • Have a page that gathers some blocks? What if we:
    • create the new page manually
    • put there a query
    • have that query bring results every time we open that page
  • Mass-apply a tag to some blocks to save typing? What do we do with new blocks added later?
    • Check every new block, just in case it needs the tag too?
    • Repeat the mass-application from time to time on demand?
  • Something else?
1 Like

I had a similar idea but in the form of more operators based on regex and domains, like:

  • (domain example.com)
  • (youtube channel)
  • (youtube playlist)
  • (github repo)
  • (github issue)
  • (github logseq/logseq)

and so on, to be used like this:

{{query (and (github logseq/logseq) (github issue))}}

The query above is meant to look for all blocks that contain a URL to a issue on Logseq’s GitHub repo.

Even better if the user could define a custom operator using a regex.