Dataview plugin snippet showcase

where file.name != this.file.name

3 Likes

Gold! This plugin is just gold! Thank you @Moonbase59

1 Like

I did. It’s just a simple css class:

span.nav {
  border-top: 1px solid var(--gray-dark-3);
  border-bottom: 1px solid var(--gray-dark-3);
  clear: right;
  display: flex;
  flex-direction: row;
  justify-content: space-around;
}
1 Like

Anyone else able to help me with this?
How can I list backlinks and exclude notes I’ve already linked to?
paging @Moonbase59

List of backlinks not including outgoing links from this note

I made a short description, so that everyone can follow how to do things like that. It requires ```dataviewjs though.

Here’s what it looks like

Here’s the code

# List of backlinks not including outgoing links from this note

An outlink: [[Test Dataview Links]]

### outlinks

```dataview
list from outgoing([[#]])
```

### inlinks

```dataview
list from [[#]]
```

### Backlinks w/o the outgoing links

You can simply filter one array's elements by setting the condition based on other array's elements.

The `some()` method tests whether at least one element in the array passes the test implemented by the provided function. And I’ve added a function which just checks if the inlink path exists in the outlinks array with the same value to be able to filter from the first array using a `not` (`!`).

#### Long form for better understanding

```dataviewjs
var outlinks = dv.current().file.outlinks;
var inlinks = dv.current().file.inlinks;

dv.list(inlinks.filter(i => !outlinks.some(o => o.path === i.path)));
```

#### Short form

```dataviewjs
dv.list(dv.current().file.inlinks
    .filter(i => !dv.current().file.outlinks.some(
        o => o.path === i.path)));
```
10 Likes

I’ve only taken a quick glance but you should be able to do the same in regular dataview. Just in case anyone wants add on without having to use JS

```dataview
list
where contains(this.file.inlinks, file.link) 
      and !contains(this.file.outlinks, file.link)
```
15 Likes

Ha! I’m over-JS’ed! :laughing: Totally didn’t think of that, thanks for the alternative!

3 Likes

You sir are a magician. Thanks so very much for this. I appreciate your didactic spirit as well (teach a man to fish, and all that).

Personally I’m barely able to get to grips with the basics of dataview so I think dataviewjs is unrealistic for me for a while but I’d love to get there one day!

Yep this does it perfectly as well. Thanks very much!

Nested Queries?

Not sure if this is the right place to ask this, but is there a way to do nested queries? For example, I’d like to query pages that contain backlinks to pages with backlinks to a range of dates.

My use case is this: I’m trying to create a query for a list of math example questions from lectures in a specific date range. Each question is a note, which links to a lecture note, and then the lecture note gets linked to a date, like so:


An example of a question note. This gets linked to a lecture note in the “Source” field:


Which itself has a link to the date of a lecture

The example question notes and lecture notes are seperated into folders:

So is there a way to do this kind of query within a query? How would I go about querying, say, a list of example questions linked to lecture notes from August?

1 Like

Is it possible to truncate file/link names when showing results?

For example, one note may be listed as Note A - 202108131821. However, I would like it to be displayed as Note A. Is it possible to achieve this?

Thanks in advance.

```dataview
TABLE round(file.size * 1.005) as "Character Est.", round(file.size * 1.005 / 4.79) as "Word Est. (English)"
FROM "folder"
```

This is a simple snippet to display character count of all notes in a folder & also calculate an estimate of the word count.

Since dataview only offers file.size as attribute, there were some workarounds to achieve this:

Caveats:

  • the notes do appear in alphabetical order. If you are doing longform writing and the order of notes (chapters) is relevant, the notes need to have a specific numbering prepended.

(I have created/contributed to feature requests at the dataview-plugin, longform-plugin, and Better Word Count plugin, hoping that one of them will implement a better and more precise solution, but until then, this snippet will have to do.)

6 Likes

Great stuff for data lovers!
Just starting on a project to document all the restaurants I have visited.
So I have one page for each unique restaurant visited, and then another note with metadata using :: attributes for each restaurant visit.

Then with that data the idea is to create some summaries such as spent by restaurant etc.
However the GROUP BY statement doesn’t seem to take the unique restaurants when doing the sum
Table


Code for table
image

Any idea of why that might be?

The end result should be having a world map with the restaurants, and linked notes for each visit.

Here the test so far

2 Likes

thank you for this!!!

anyone can help me on this …

the list doesnt show links its plain text :confused:

Thanks in advance

1 Like

Use rows.file.link:wink:

2 Likes

legend… learning something every day…
Is there somewhere I should have read and known bout it ?
maybe there are more things that I might save you from answering :smiley: :smiley:

1 Like

The Dataview Documentation is a good start, although that is currently not quite up-to-date and heavily reworked. Hint: It’s currently quite uninviting, try the menu on the left side. :wink:

The forum here is also a good place to find examples (and sometimes a little explanation, too). The docs are rather technical and not always easy to comprehend.

Since we have Obsidian, I also strongly suggest: Make notes, wite down examples! :smiley:

2 Likes

After some tests, here is what I have for now.

  • = link(this.file.link, regexreplace(this.file.name, " - \d+", "")) truncates the name of the current note and re-constructs it as a link again. Therefore, [[Note A - 202108131821]] becomes [[Note A]], which is the desired result.
  • However, when I try to apply this to a Dataview table, I got some errors.
table link(rows.file.link, regexreplace(rows.file.name, " - \d+", "")) as Film
from #Film
where rating != null
group by rating as Rating
sort rating desc

The error message:

Dataview: Every row during final data extraction failed with an error; first 3:

            - No implementation of 'link' found for arguments: link, array

Does this indicate that some operations cannot be performed on Dataview arrays? Can this be resolved by using DataviewJS?

Any help would be really appreciated.

With the help from @blacksmithgu, I was able to resolve this issue by using the following DataviewJS code.

for (let group of dv.pages("#NoteDataview").groupBy(p => p["film-genre"])) {
    dv.header(3, group.key);
    dv.table(["Name", "Rating", "Watched"],
        group.rows
			.where(k => "film-rating" in k)
            .sort(k => k["film-rating"], 'desc')
            .map(k => [dv.func.link(k.file.path, k.file.name.replace(/ - \d+/, '')), k["film-rating"], k["date-watched"]]))
}

The link on GitHub for this issue: Truncate note name and point to the original note link · Discussion #426 · blacksmithgu/obsidian-dataview