Pulling the most recent meeting's summary so that it is viewable in another file

Hi everyone! Sorry for bothering y’all. I’m not really a coding type (although I love to cobble things together). I’ve been looking online for answers about how to do this, but coming up empty-handed.

What I’m trying to do

So I am a teacher. I have lots of classes with the same people. So I have:

  • A page for each individual student
  • A page for lesson notes

In the lesson notes, I have:

  • a section with a header for both a summary (## What We Did)
  • a section with a header for homework (## Homework)

In the YAML there’s a status: (default: “in-progress”, other option: “done”)

Each student has a folder where their meeting notes will go.

I want to be able to pull the summary of the latest lesson and homework into the student’s page, but for the sake of this post, let’s focus on the code for the summary portion (and I’ll just change it for the homework part since it should work similarly).

I think I basically need a dataview query that that pulls the header and the corresponding information underneath and then embeds it on the student page. It needs to pull this info from the most recent lesson marked “done”.
I’m stumped about how to make it pull the information from the most recent meeting marked “done” (cos I don’t know what I’m doing haha).
Also, before anyone asks - No, I don’t want to put this information in the YAML because it will be a lot (I have already built a table with a short summary preview to log past lessons).

Things I have tried

So I have been all over google, github (although I’m not super sure how to search it effectively), as well as here, and I have come across similar queries pulling summaries of the week and to-do lists and stuff, but since this is a bit different (targeting the most recent file and not within a specific date range), I’m not sure how to go about it.

I have found this code below. I think it just needs to be updated so it draws the information from the most recent lesson marked “done”. I know also that you can, for example, create a table with descending files and limit the query to 1. So I guess it needs to be something similar to that, but I’m not quite sure how to make that happen… so that’s why I’m here :grin:

const header = '## What We Did\\?'

// You can update this to filter as you like - filtering for just your daily notes would be good
const pages = dv.pages('"Students and Lessons/Students/THE STUDENT'S FOLDER"')

// 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) -I DONT KNOW IF I NEED TO UPDATE THIS AS WELL, AND IF SO, HOW
    // 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())
    }
}

Source: I got this code from here: Summarize Daily Notes Using Dataview - #9 by AlanG

Also, I’m not sure if I’d need some special script or something to run the RegExp portion of this code, but I’m vaguely aware of how to install scripts in Obsidian (I’ve seen it done in youtube vids)

Anyway, thanks in advance for any and all assistance! Hoping we can figure this out!

So I’ve been working on this and I’m closer to making it happen. Right now I have this and it functions however it’s using tags to work, not the status in the YAML:

const header = '## What We Did\\'

const pages = dv.pages('#Done and "Students and Lessons/Students/Folder"').sort(x => x.file.name, 'desc').limit(1)
const regex = new RegExp(`\n${header}\r?\n(.*?)(\n#+ |\n---|$)`, 's')

for (const page of pages) {
    const file = app.vault.getAbstractFileByPath(page.file.path)
    const contents = await app.vault.read(file)
    const summary = contents.match(regex)
    if (summary) {
        dv.header(2, file.basename)
        dv.paragraph(summary[1].trim())
    }
}

Any ideas how I can make this target the status field in the YAML instead of a tag?

Thanks a lot!

Also… so proud.!!!

2 Likes

So just as a follow-up, I figured this out this morning. Sharing in case it helps anyone else out in the future!

const header = '## What We Did\\'

const pages = dv.pages('"Students and Lessons/Students/Folder"')
.where(x => x.status == 'Done')
.sort(x => x.file.name, 'desc')
.limit(1)

const regex = new RegExp(`\n${header}\r?\n(.*?)(\n#+ |\n---|$)`, 's')

for (const page of pages) {
    const file = app.vault.getAbstractFileByPath(page.file.path)
    const contents = await app.vault.read(file)
    const summary = contents.match(regex)
    if (summary) {
        dv.header(2, file.basename)
        dv.paragraph(summary[1].trim())
    }
}

So I’m wondering if it would be possible to simply do this with the embed function… just have it target the most-recent note marked “Done”.

![[10.20.2023#What we did]]

I realized, too, I need a link back to the note file still :grimacing:
Any pointers would be hugely helpful!

Okay, I just asked ChatGPT and while its answer was incorrect, it gave me enough info to figure it out:

const header = '## What We Did\\'

const pages = dv.pages('"Students and Lessons/Students/0. Demo Folder"')
.where(x => x.status == 'Done')
.sort(x => x.file.name, 'desc')
.limit(1)

const regex = new RegExp(`\n${header}\r?\n(.*?)(\n#+ |\n---|$)`, 's')

for (const page of pages) {
    const file = app.vault.getAbstractFileByPath(page.file.path)
    const contents = await app.vault.read(file)
    const summary = contents.match(regex)
    if (summary) {
        const meetingNoteLink = `${file.path}`;
        dv.header(2, `[[${meetingNoteLink}|${file.basename}]]`);
        dv.paragraph(summary[1].trim());
    }
}

Does anyone know if it is possible to make Images render with this as well? (Currently, any images are just showing up as a link)

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