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
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!