In dataview, differentiate between task-level tags and page-level tags

Is there a way in dataviewjs to know if a tag has been applied at page-level or inline task-level?

My use case:
I apply a tag at page-level and at task-level (in-line) like so:

1.   NOTE TYPE with PAGE-LEVEL TAG
      #myTag

     ... some note content...
2.  NOTE TYPE with TASK-LEVEL TAG
     .... some note content ...

     - [ ] some task #myTag
     - [ ] another task #myTag
     
     .... more note content

I’d like to return a list using dataviewjs where #myTag is applied at page level ONLY not at task-level , ie NOTE TYPE 1 only.

What I’ve tried so far:
dv.pages(“#myTag”) returns all the pages that contain #myTag **ie NOTE TYPE 1 and NOTE TYPE 2 **. This shows all pages with page-level tags (desired behaviour) , but also the pages containing tasks with task-level tags (undesired behaviour).

My current workaround is

  1. get all pages containing #myTag at page level and task level (mixedPages).
  2. get all tasks with #myTag at task-level. Get all the pages containing these tagged tasks (taskLevelTaggedPages).
  3. Then subtract the taskLevelTaggedPages from mixedPages to get pageLevelTaggedPages. (pageLevelTaggedPages = mixedPages - taskLevelTaggedPages)

see code below.

const mixedPages = dv.pages("#myTag")
const taggedTasks = mixedPages.file.tasks.
                        where(t => t.tags.includes("#myTag"))

const taskLevelTaggedPages = [...new Set(taggedTasks.path)]
                             .map(p => p.split("/")[p.split("/").length - 1]
                             .slice(0, -3))

const pageLevelTaggedPages = mixedPages.file.name
                            .filter(n => !taskLevelTaggedPages.includes(n))

dv.list(pageLevelTaggedPages)

However i was wondering if there was a way to directly check if a tag was applied at task level or page level instead of this workaround method? It would help in solving for certain edge cases.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.