A fun one today!
Tasks that don’t reference a page regardless of nesting
This will exclude any tasks that are referencing a page or that one of the parent blocks references a page. This query uses rules for recursive searching.
To change this to reference instead of don’t reference, just remove the (not
and closing )
around (check-ref ?p ?b)
#+BEGIN_QUERY
{:title "🔨 TODO"
:query [:find (pull ?b [*])
:in $ % ; % is used to pull in the rules below.
:where
[?b :block/marker ?marker]
[(contains? #{"TODO"} ?marker)]
;; Exclude pagename
[?p :block/name "pagename"]
(not (check-ref ?p ?b)) ; this calls the rules below.
]
:rules [ ; whenever two rules have the same name an or is applied. I'm not exactly sure how to explain it!
[(check-ref ?p ?b) ; definition of the rule, name and parameters.
[?b :block/refs ?p] ; rule content to be executed
]
[(check-ref ?p ?b)
[?b :block/parent ?t]
(check-ref ?p ?t) ; calling the rule again within this rule will make it recursive.
]
]
:breadcrumb-show? false
:collapsed? true
}
#+END_QUERY