Summarize Daily Notes Using Dataview

You can extract the full “What happened today?” section via regex.

For best performance you’ll want to change the Dataview query dv.pages() to limit it to your daily notes only. If you use the tag “#daily”, that would be dv.pages('#daily')

```dataviewjs
const header = '## What happened today\\?'

// You can update this to filter as you like - filtering for just your daily notes would be good
const pages = dv.pages()

// This regex will return text from the Summary header, until it reaches
// the next header, a horizontal line, or the end of the file
const regex = new RegExp(`\n${header}\r?\n(.*?)(\n#+ |\n---|$)`, 's')

for (const page of pages) {
    const file = app.vault.getAbstractFileByPath(page.file.path)
    // Read the file contents
    const contents = await app.vault.read(file)
    // Extract the summary via regex
    const summary = contents.match(regex)
    if (summary) {
        // Output the header and summary
        dv.header(2, file.basename)
        dv.paragraph(summary[1].trim())
    }
}
```
10 Likes