Get all inlinks to current file filters by a specific heading

Hey there :wave:

What I’m trying to do

I’m trying to get a table with all inlinks to a specific note, but only if they are under a certain heading

To explain the use case, I’m using my daily notes to take note of my work meetings (using a # Meetings title, and using subtitle for each meeting, putting an example underneath)
In this subtitle we have a outgoing link to the whole project, for any information that would need to be “permanent”. And this specific note, I would like to have a list of all the linked call from the daily notes, but just in case I would link that project anywhere else, I need to filter this to make sure only calls get in that list - hope that makes sense
image

NB: the uppercase style is from CSS

Things I have tried

I’ve worked through Dataview documentation and found the function I think I need, but didn’t achieve to make it work.

I guess this is just because I don’t really understand how I should be using the meta.subpath thing

TABLE 
FROM [[]]
AND !outgoing([[]])
WHERE contains(meta.subpath, "Appels")

If anyone has an idea or see what is the issue… :nerd_face:

This might not be possible in plain DataView, only in DVJs (unless you have list items below the heading) but let’s wait for some DV master who knows the ins and outs of the DV docs and hacks.

I tried:

```dataview
TABLE
FROM [[]]
AND !outgoing([[]])
WHERE regexmatch(meta(file.inlinks).subpath, "regex to match my usual headers as I don't have yours")
```
  • Parsing error.

You don’t have the heading information for a random link available in an ordinary DQL query, as the links are just links and they’re not tied up to a section. If however, the link was contained in a list/task, then you’d have this information readily available.

So if you’re not eager to do javascript coding, I see two good options, and that is either to use lists or tasks to denote the call, and use either of these two syntaxes:


## RÉUNION & APPELS

- Called [[Thomas]] on some subject.
- [t] [[Thomas]] about something

In my vault with some custom styling this appears as:
image

To query these you could do something like:

```dataview
LIST item.text
FROM [[]]
FLATTEN file.lists as item
WHERE item.outlinks[0] = [[]] AND meta(item.section).subpath = "RÉUNION APPELS"
  AND !item.task
```

And similarly for the task item:

```dataview
TASK
FROM [[]]
FLATTEN file.tasks as item
WHERE item.outlinks[0] = [[]] AND meta(item.section).subpath = "RÉUNION APPELS"
```

For both of these queries note that the .subpath of the section link doesn’t include the ampersand, &, and I’m not sure if your telephone icon would be included either.

The main difference between these two query in the result they provide is that the task query provide a link back to its original definition, but the list variant is just a text result.

A complete larger example

Below is a full note, which showcases various alternatives related to this, where I’m linking back to the current file as an example, so the note is self contained. It do however still show how you could, if you’d like to, traverse the app.metadataCache to build your own notion of which link belongs to which heading.

In other words, if you’re not afraid of a little coding, you might find a way to achieve your original request within the code of the following note. But it’s mostly presented to display that even though possible, I’m not sure I would recommend it… To test it out in your vault, just put all of the text below into a note called “f76440 link by heading” (or something else but then you need to change the links to match that name), and read’em and weep. :smiley:

---
Tags: f76440
---
questionUrl:: http://forum.obsidian.md/t//76440

[[f76440 link by heading|no heading]]

## Under a heading

 [[f76440 link by heading|heading]]

## In a list

 - [[f76440 link by heading|list]]

## All inlinks to current file
```dataview
TABLE inlink, meta(inlink)
WHERE file = this.file
FLATTEN file.inlinks as inlink
```

Aka just the one, even though there a five different links in this file back to it self.
## Section of links for list items

```dataview
TABLE meta(item.section).subpath
WHERE file = this.file
FLATTEN file.lists as item
```

## Find heading for links in current file

```dataviewjs

const fileCache = app.metadataCache.getFileCache(dv.current().file)
const localHeadings = {} // indexed by offset
for (const heading of fileCache.headings) {
  localHeadings[heading.position?.start.offset] = heading.heading
}

const result = []
for (const link of fileCache.links) {
  const linkOffset = link.position.end.offset 
  let linkHeading = ""
  for (const [offset, heading] of Object.entries(localHeadings)) {
    if (linkOffset > offset) {
      linkHeading = heading
    } else if (linkOffset < offset)
      break
  }
  result.push([link.displayText, linkHeading])
}

dv.table(["display text", "Heading"], result)
```


## RÉUNION & APPELS

- Called [[f76440 link by heading|Thomas list]] on some subject.
- [T] [[f76440 link by heading|Thomas task]] about something

### table thingy
```dataview
TABLE meta(item.section).subpath, item.task, item.outlinks
FROM [[]]
FLATTEN file.lists as item
```

### list thingy
```dataview
LIST item.text
FROM [[]]
FLATTEN file.lists as item
WHERE meta(item.section).subpath = "RÉUNION APPELS"
```

### task thingy
```dataview
TASK
FROM [[]]
FLATTEN file.tasks as item
WHERE meta(item.section).subpath = "RÉUNION APPELS"
```

## RÉUNION lists from "anywhere"

### From a list (not task)
```dataview
LIST item.text
FROM [[]]
FLATTEN file.lists as item
WHERE item.outlinks[0] = [[]] AND meta(item.section).subpath = "RÉUNION APPELS"
  AND !item.task
```

### From a task 
```dataview
TASK
FROM [[]]
FLATTEN file.tasks as item
WHERE item.outlinks[0] = [[]] AND meta(item.section).subpath = "RÉUNION APPELS"
```

To respond to what’s wrong with this query:

  • FROM [[]] and !outgoing([[]]) – Here you ask for only incoming links to the current file, and at the same time doesn’t have any outgoing links to the current file. Essentially this is no file at all…
  • meta.subpath – This is just wrong syntax. You could do something like: meta(aLink).subpath where aLink is some link in your context. But you must define a link for it to extract the meta information from.
  • file.inlinks and file.outlinks are not decorated with any display paths or similar stuff, so you wouldn’t be able to use that anyways if it had been defined in the original file

Uhh.

Okay, let’s watch the Biathlon World Cup, go Italy.