Funnel all headings blocks with specific tags into a new note

Things I have tried

I’ve tried researching this issue with Google and on the forum, but I haven’t been able to find any solutions. It’s possible that I’m using the wrong terminology, as I’m new to Obsidian.

What I’m trying to do

Basically, what I want to do is when I add a specific tag to a heading in my daily note (or any note in my vault), that same heading and its contents are placed in another note that aggregates all of the headings with that same tag.

I’ve been using Dataview to try to do this, but it’s showing the name of the full note, not just the heading with the tag as a single line with a link, instead of displaying the full block.

An example would be:

In my DAILY NOTE 01-05-23 I would write something like

Remeber This

#Tag

Remember this one piece of information from today.

Then I would have another note labeled Check this out where I would also have

Remeber This

#Tag

Remember this one piece of information from today.

This is the Dataview script I tried:

table
where tags= BHZ106
sort file.day

Any help would be greatly appreciated.

Thanks in advance!

1 Like

Try this, and you don’t even need a tag. Where I’ve used “Health” or “Mood”, you can use “Remember This”:


In your daily notes, you might have a “Health” heading where you log your daily health information. If you want to collect the text under these headings from all of your notes, you can do this with Dataview.

Here is a working demo vault which you can download to test with:

:floppy_disk: Download demo vault

It will collect the sections under each of your requested daily note headings, and summarise them by day inside a single note:


How to set up

The latest version of this guide can always be found here.

Step 1:

Install Dataview, and turn on Javascript queries:

Step 2:

Create a new note and paste this code:

```dataviewjs
// Headings you would like to summarise the text for
const headings = ['Health', 'Mood']

// You can update this to filter as you like.
// Here it is only returning results inside the "Daily notes" folder
const pages = dv.pages('"Daily notes"')

const output = {}
headings.forEach(x => output[x] = [])
for (const page of pages) {
  const file = app.vault.getAbstractFileByPath(page.file.path)
  // Read the file contents
  const contents = await app.vault.read(file)
  for (let heading of headings) {
    // Sanitise the provided heading to use in a regex
    heading = heading.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&')
    const regex = `(?<=^|\n)#+ ${heading}\r?\n(.*?)(?=\n#+ |\n---|$)`
    // Extract the summary
    for (const block of contents.match(new RegExp(regex, 'isg')) || []) {
      const match = block.match(new RegExp(regex, 'is'))
      output[heading].push({
        title: file.basename,
        text: match[1].trim()
      })
    }
  }
}
Object.keys(output).forEach(heading => {
  dv.header(1, heading)
  output[heading].forEach(entry => {
    dv.header(4, entry.title)
    dv.paragraph(entry.text)
  })
})
```

You’ll need to update the two variables headings and pages at the top to match the location and format of your own files.

7 Likes

Another variant, if you’re using the Minimal theme, is to dedicate some checklist variants for stuff you’d like to remember and collate.

I’m using this to track stuff like where I hiked on a given day, if I spent money on something particular, if I visited somewhere special, new or interesting ideas. The way this works is that you have decorated tasks spread out in your daily notes (or whatever) like the following:

- [S] New computer (I wish... )
- [l] Visited the Great Place of Somewhere
- [S] Service on the car. Again
- [I] Maybe I should re-evaluate how much time spent in the Obsidian forum?

This would then render as:
image

And using either of these queries, you could collate the information somewhere else:

## Money spent on
```dataview
TASK 
WHERE status = "S"
```

## Places and Ideas
```dataview
TASK 
WHERE contains(list["I", "l"]), status)
```
(That's a list of upper case `I` for Ideas, and lowercase `l` for locations... )

Which produces this output:
image

See Checklists - Minimal Documentation, for the default decorations that Minimal offers, but do now that it’s also possible to relatively simply add your own custom task decorations.

Finally, you asked for headings, and I provide an alternative with list items, but I’ve used this for a little while no where I actually place a single of these task items (randomly spread) in my daily notes, and use it as a heading, and I find it works rather nicely, and it gives me an easy opportunity to gather up lists of the various decorated tasks for summation in either weekly or monthly notes.

1 Like

This worked amazingly!

Thank you!

1 Like

Thanks a lot! The vault helps me to test and learn the code. But my headings are like this:
‘# [[Routine]]’ There are two blanks before the text and one link. The code didn’t work. How can I modify it?

If you’ve got 2 spaces before the heading text you’ll need to change the above to:

#+\s+${heading}

Currently it’s looking for exactly 1 space.

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