Gather all daily mentions of a given note as a timeline

If you need a way to present all mentions of a given note inside it, here’s how I do it:

In the gathering note place this code:

> [!Quote] Timeline of mentions
> `$=await dv.view("code/mentions")`

Go to your Obsidian vault folder, make a code folder and create there a file called mentions.js. Put this code in the file:

const this_path = dv.current().file.path
function containsMention(list) {
	for (let outlink of list.outlinks) {
		if (dv.page(outlink.path) && dv.page(outlink.path).file.path == this_path) return true;
	}
	return false;
}

let mentions = dv.pages('#daily AND "journal" AND [[#]]').where(t => t.file.lists.length > 0).file.lists.where(l => containsMention(l)).groupBy(t => t.path).sort(k => k.key, 'desc')

dv.header(4, mentions.length + " dailies")
for (let group of mentions) dv.taskList(group.rows)

The code finds all mentions of a note if it matches all these criteria:

  • the file is a daily note, that is:
    • it sits in the journal folder
    • it has a #daily tag in its meta-data
  • the mention follows this syntax:
- [[your note]]
  - stuff you want to mention
  - more stuff to mention

or just

- [[your note]] blah blah

For anyone wandering why not look for headers instead of lists, it’s currently impossible with dataview to parse outlinks in headings.

14 Likes

Thanks to @scholarInTraining whose snippets inspired me to play with javascript and exchange your findings :slight_smile:

1 Like

This is a really terrific thing, it solves rather elegantly a gnarly little issue I have been struggling with for a while. Unfortunately, the js script seems to stop all my Templater templates from working. Have you any idea what might be causing that, and if there is a cure for that ill?
The Inspector shows this error (if that helps. I know nothing of these things)
plugin:templater-obsidian:82 Templater Error: Template parsing error, aborting. dv is not defined

1 Like

Yes, templater does not like seeing scripts for other plugins in the same folder as your templater scripts! Perhaps make a subfolder in your scripts folder just for templater scripts, move your templater-specific scripts there, and then in Settings → Templater make sure it is looking just in that subfolder for scripts.

1 Like

BOOM! Just like that – the community comes to the rescue. Crikey I love this app/community :smile:
Now it is working just lovely - Many thanks!

3 Likes

Update - if you don’t want to use this snippet, there’s a plugin that does a similar job: influx. Check it out.

This is SO good and exactly what I was looking for. I made a slight modification for finding mentions anywhere.

let mentions = dv.pages('[[#]]').where(t => t.file.lists.length > 0).file.lists.where(l => containsMention(l)).groupBy(t => t.path).sort(k => k.key, 'desc')

But what I would really like to also do is have another query that is links to the current page that aren’t in lists. I don’t know enough Javascript to figure out how to do that.

I could just do

list
from [[]]
sort file.name

but that is redundant when on the same page as the code in this thread.
Any ideas?