Bibliography: Use Dataview to get summary list of search occurances from a file?

What I’m trying to do

I’m trying to summarize links interspersed throughout a note in a single location in that same note. For instance, when taking notes on a book I’d like to use links to identify bibliography references:

"these are some notes on *This Book* by Author [[bib]]"

…and then collect all references in a bibliography section at the end:

### Bibliography
- ref 1
- ref 2
...
- ref n

Things I have tried

I can approximate this with an embedded search:

### Bibliography

\```query
[[bib]] file:(note_title)
\```

However, I think there may be a way to do this with Dataview that is cleaner and doesn’t require updating the note_title in the query each time.

I have searched the forums and broader interwebs and find lots of examples of using Dataview to pull data from other files, but not for pulling snippets from the same file.

Anyone done something similar?

A few questions:

  1. Does [[bib]] contain all your references? i.e. will that part of the query be the same every time?
  2. Do you want to see the line where [[bib]] shows up, as happens with the embedded query? That may be hard to do with Dataview.
  3. Do you use any templates for your notes, whether via the core plugin “Templates” or a community plugin such as “Templater” or the various others?

If yes to 3, the easiest solution I can think of would be to put your query in a template that refers to the title of the file in the syntax of whatever templating plugin you use (e.g. {{title}} for the core “Templates” plugin, and then insert that template via Command Palette or hotkey when you want a bibliography. No dataview needed.

3 Likes

To translate your example into a template as suggested by @scholarInTraining:


### Bibliography

```query
[[bib]] file:/^{{title}}$/
```

I’ve added a regular expression to the file: part to avoid matching any longer note names that contain the note’s name as a part.

3 Likes

Sorry for the slight diversion, but this is somewhat relevant. I was reading this topic and thought that it might be useful for anyone who might be interested in a feature request for expanded use of regex similar to what was shown here but applied to all the various operators, here is a link Let regex search work with tag: line:() and section:() options

One thing, I forgot to mention in the linked topic, but just added as an edit, is that regex also already works on the task: operator, the task-todo: operator, the task-done: operator, the content: operator, and the block: operator as well as the file: and path: operator .

https://help.obsidian.md/Plugins/Search#Search+operators

For people surprised to see these additional operators not shown in the search popup, the above page explains it much better than I can as well as some key syntax to take search to the next level. Anyways, I apologize for jumping in here and promoting a feature request, but I don’t feel it is too far out of place to do so in this context considering the conversation in the linked feature request was with @CawlinTeffid

Thanks so much for all your generous help here on the forum. It is very much appreciated. I feel like you would be a good moderator.

1 Like

Thanks all for the notes!

Yes, I do use a Templater template (here).

Since I’m using Templater instead of templates, I switched out {{title}} for <%tp.file.title%>:

\```query
[[bib]] file:(<%tp.file.title%>)
\```
1 Like

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