Can dataview query list the contents of this file?

TL:DR I has no idea what I am doing :smirk:

I am writing TL;DR’s for a lot of very large documents. Right now I am duplicating the contents of the document creating and summarizing it, [[#Heading]] links, and putting my notes into a TL;DR callout.

I was thinking that it would be nice to have a dataview query at the top of the document that would atomatically gather all of the TL;DR collouts that I am writting and place them at the top of the document. This would be nice for when I am reading the document I could write a quick TL;DR then move on, and then I would not have to rewrite the top block.

Things I have tried

Honestly, I am very new to dataview and have no idea where to start querying almost anything.

> [!tldr] TL;DR
> ```dataview
> LIST
> FROM /path/to/This/document
> ```

Should I be using a TAG:: for this maybe Tag:: TLDR

What I’m trying to do

The following is what I would like my document to look like once it is done.

Top Heading

TL;DR

[!tldr] TL;DR

  • 1st really awesome note
  • 2nd really awesome note
  • 3rd really awesome note

1st Heading

[!tldr] TL;DR

  • 1st really awesome note

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed fringilla tortor est, in lacinia nisl feugiat vitae. Ut iaculis, arcu sit amet accumsan fringilla, urna tellus auctor mi, non mollis erat orci eget dui. Ut arcu lacus, ornare at vulputate tincidunt, dignissim auctor ex.

2nd Heading

[!tldr] TL;DR

  • 2nd really awesome note

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed fringilla tortor est, in lacinia nisl feugiat vitae. Ut iaculis, arcu sit amet accumsan fringilla, urna tellus auctor mi, non mollis erat orci eget dui. Ut arcu lacus, ornare at vulputate tincidunt, dignissim auctor ex.

3rd Heading

[!tldr] TL;DR

  • 3rd really awesome note

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed fringilla tortor est, in lacinia nisl feugiat vitae. Ut iaculis, arcu sit amet accumsan fringilla, urna tellus auctor mi, non mollis erat orci eget dui. Ut arcu lacus, ornare at vulputate tincidunt, dignissim auctor ex.

I’m not sure if I understand well your goal. But let’s start with some examples.

Example note:

# Top Heading

## TL;DR

> [!tldr] TL;DR
> {your code - see dataview queries examples}
> 

## 1st Heading

> [!tldr] TL;DR
> 
> - 1st really awesome note

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed fringilla tortor est, in lacinia nisl feugiat vitae. 

## 2nd Heading

> [!tldr] TL;DR
> 
> - 2nd really awesome note

Sed fringilla tortor est, in lacinia nisl feugiat vitae. Ut iaculis, arcu sit amet accumsan fringilla, urna tellus auctor mi, non mollis erat orci eget dui. 

## 3rd Heading

> [!tldr] TL;DR
> 
> tldr:: 3rd really awesome note

Ut arcu lacus, ornare at vulputate tincidunt, dignissim auctor ex.

## 4th Heading

> [!tldr] TL;DR
> 
> - 4th really awesome note #tldr

- Lorem ipsum dolor sit amet, consectetur adipiscing elit.

## 5th Heading

> [!tldr] TL;DR
> 
> - 5th really awesome note #tldr

Lorem ipsum dolor sit amet, consectetur adipiscing elit.
- Ut iaculis, arcu sit amet accumsan fringilla, urna tellus auctor mi, non mollis erat orci eget dui. Ut arcu lacus, ornare at vulputate tincidunt, dignissim auctor ex.

## 6th Heading

> [!tldr] TL;DR
> 
> (tldr:: 6th really awesome note)

Lorem ipsum dolor sit amet, consectetur adipiscing elit.


Using an inline field

In fact you can use the inline fields (key:: value), a dataview specific feature. (don’t call it “tags”, to avoid confusion with the real tags).

You can see the examples in 3rd Heading and 6th Heading with the key tldr::.

The difference between the two examples is related with the way it renders: if you enable in dataview settings the “inline field highlighting”, the use of curved brackets removes the key in the render output, presenting only the “value”.

To this example you can use this type of query:

LIST WITHOUT ID tldr
WHERE file.path = this.file.path
FLATTEN tldr


Using lists

In the other cases we have lists (bullet point lists) inside each callout.
Dataview doesn’t query the full content, only things considered metadata (implicit or created). For now, callouts aren’t metadata. But lists are, in same way as tasks. And these two cases are the only metadata with association to the section/heading.

So, we can query all lists in the document with this query:

LIST WITHOUT ID Lists.text
WHERE file.path = this.file.path
FLATTEN file.lists AS Lists

But, as you can see, this query list all the lists, including any bullet point list outside callouts.


Filtering lists

To avoid the previous case (lists outside the callouts), we need to create a kind of specific data inside the wanted comments/notes. In 4th Heading and 5th Heading I added a tag (“#tldr”) but could be an inline field…

To select only that cases we can use this query:

LIST WITHOUT ID Lists.text
WHERE file.path = this.file.path
FLATTEN file.lists AS Lists
WHERE contains(Lists.tags, "#tldr")


Filtering lists - extra

But you can add some “extra” code to a better output. For example: remove the used tag (#tldr) in the outputted text and add a link to the section where the list is placed.

To do that I suggest a Table instead of a List:

TABLE WITHOUT ID replace(Lists.text, "#tldr", "") AS "My comments", link(Lists.link, meta(Lists.section).subpath) AS "Section"
WHERE file.path = this.file.path
FLATTEN file.lists AS Lists
WHERE contains(Lists.tags, "#tldr")


And… that’s all

4 Likes

Super helpful, mnvwvnm ! Thanks as always…

Wow, that was way more detail than I expected. Thanks! This really helps. Lots here to study and figure out what you did.

Thanks that was really helpful to understand.

@mnvwvnm I think your first solution is the best option for what I am trying to achieve. Though, I will be looking into the others to understand better dataview.

I am adding the following TL;DR callout containing a simple dataview at the top of very long, complicated, hard to understand documents.

> [!tldr] TL;DR
> ```dataview
> LIST WITHOUT ID tldr
> WHERE file.path = this.file.path
> FLATTEN tldr
> ```

Then above any paragraph or section that I want to summarize I write another TL;DR callout making sure to add - tldr:: to the beginning of my summary as well as a [[#Link]] so that I can jump to that section.

> [!tldr] TL;DR
> - tldr:: [[#LinkToSection]] Some awesome Note

The result of this is that the dataview at the top of the document gathers all the lines marked with the inline field tldr:: and puts them nicely in an easy-to-read TL;DR callout.

Now when I am trying to understand these documents I can link to a section and their is a TL;DR for that section and there is a summation of the entire document at the top of the file that is automatically changed if I change my understanding of the sections below. I don’t have to change the note twice per edit.

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