Filter duplicate outlinks from an inline query

Hi, I use this inline queries instead of the native way for displaying out- and in-links. For me, it’s visually less messy.

___
Source: `= this.file.inlinks`
Links: `= this.file.outlinks`

But while inlinks are working fine. In backlinks, I see duplicates.

Let’s say I have a Baby_note. I mention it once in a Mamy_note and twice in a Dady_note. Also, inside Baby_note I talk once about Crayons_note, and twice about Cars_note. This is what I get.

___
Source: [[Mamy_note]], [[Dady_note]]
Links: [[Crayons_note]], [[Cars_note]], [[Cars_note]]

What I’m trying to do

Can I get rid of this second instance of a Cars_note?

Things I have tried

I get a feeling, I should use a $ sign and a groupBy or filter. Here are probably same clues: Need help with this dataviewJS code: .file.outlinks displaying duplicates of the same note.

But I don’t know JavaScript, so… Anyone willing to help?

By the way, is there any good place to learn JavaScript for as limited use, as for Obsidian Dataview? I mean I’d like to know some basics, but every time I try, I get kind of overwhelmed, since computer science is totally not my department.

Someone can offer good advice on that but in the meantime…
If you had taken your problem to a better chat bot, it would have done it within two tries (I fed the solution from the linked place and some pertinent part of the Dataview docs):

`$= dv.current().file.inlinks.filter((value, index, self) => index === self.findIndex(t => t.path === value.path))`
`$= dv.current().file.outlinks.filter((value, index, self) => index === self.findIndex(t => t.path === value.path))`

Wanting to set alphabetical order on these was a little trickier, but with some prodding (offering ideas from the forum, or actually, in this case, from my own computer notes), I managed to work it out:

`$= Array.from(new Set(dv.current().file.inlinks.filter((value, index, self) => index === self.findIndex(t => t.path === value.path)))).sort((a, b) => a.path.localeCompare(b.path))`
`$= Array.from(new Set(dv.current().file.outlinks.filter((value, index, self) => index === self.findIndex(t => t.path === value.path)))).sort((a, b) => a.path.localeCompare(b.path))`

So you were on the right track but didn’t follow it through.
Best of luck

1 Like

:grin: You’re right. Chatbots writing code…, I have yet to register, they already exist.

Still, they probably wouldn’t be so kind to even sort it for me alphabetically, just out of kindness :stuck_out_tongue: It works perfectly. And when I’ve got the answer served on a gold platter, it even kinda makes sense. Thank you very much.

1 Like

Hi again, there is one little quirk about this solution that I didn’t notice before. It is not essential to me (and i don’t know how to change it - obviously), but I thought I’ll mention it here, if someone expected it. All the links show as existing files even if they don’t. I mean, you see non existing pages as a thin text for a split second, and then they all render in a bold typeface.

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