How do I retrieve and paste what is written after a particular heading?

I use obsidian to keep a daily diary. At the end of the diary, I make a heading ## What I saw and put a page link below it to the file where I wrote my impressions of the movies and dramas I saw that day.

I asked ChatGPT if I could use the templater code to put all the page links under the ## What I saw heading in this week’s diary file together during the weekly review,

Invalid reference date format, try specifying one with the argument ‘reference_format’

I get an error message saying “I’m not sure how to do this” and asking ChatGPT does not resolve the error. Here is the code. How can I get it to work?

<%*
<%*
// Get the date range for the week
let today = tp.date.now("YYYY-MM-DD");
let startOfWeek = tp.date.weekday(today, 0, "YYYY-MM-DD");
let endOfWeek = tp.date.weekday(today, 6, "YYYY-MM-DD");

// Get a list of daily note files within a date range
let dailyNotes = tp.file.folder_files("/").filter(f => {
  let fileName = tp.file.name(f);
  return fileName.match(/^\d{4}\/\d{2}\/\d{4}-\d{2}-\d{2}$/) && fileName >= startOfWeek && fileName <= endOfWeek;
});

// Get page links from each Daily Notebook file to the page after the heading ## Seen
let pageLinks = [];
for (let note of dailyNotes) {
  let noteContent = tp.file.include(note);
  let match = noteContent.match(/## What I saw\n((?:- \[\[.+?\]\]\n)+)/);
  if (match) {
    pageLinks.push(match[1]);
  }
}

// Inserts the retrieved page link at the current cursor position
%>
<% tp.file.cursor() %>
<% pageLinks.join("\n") %>

The diary files are stored as a folder hierarchy. The date format of the daily notebook is YYYY/MM/YYYY-MM-DD. As an example, today’s diary file is stored in the 2023 folder as folder 09 and in the 09 folder as 2023-09-09.md. The resulting file is diary/2023/09/2023-09-09.md.

I am doing a deepL translation, so please forgive me if the text is uncomfortable!
Thank you for reading!

You might find something useful in this script:

Summarise text under headings with Dataview

There’s a demo vault linked on that page which you can download and play around with. It might help you figure out how to achieve what you want.

ThankYou!

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