I want to extent Nicole van der Hoeven’s people template (https://youtu.be/4jYUQXy0nsg?si=O8k_oHlAs3SZ1UWp&t=762) such that all paragraphs in any daily note mentioning “[[JohnDoe]]” are listed at the bottom of JohnDoe’s note.
Question1: Is it correct that I cannot get and filter paragraphs of daily notes in DataView?
Things I have tried
I assume Question1 is true, thus I use the following dataviewjs script:
const pages = dv.pages('"daily"');
const pagesWithContent = await Promise.all(
pages.map(async page => {
const content = await dv.io.load(page.file.path);
return {page, content};
})
);
const filteredPagesWithContent = pagesWithContent.filter(page => {
return page.content.includes('[[JohnDoe]]');
});
let tableRows = [];
for (const { page, content } of filteredPagesWithContent) {
let paragraphs = content.split("\n").filter(para => para.includes('[[JohnDoe]]'));
let link = dv.fileLink(page.file.path);
let paraContent = paragraphs.join("\n\n");
tableRows.push([link, paraContent]);
};
dv.table(["Page", "Paragraphs"], tableRows);
Question2: Is it possible to use dv.pages(...); to get all the daily pages that contain link “[[JohnDoe]]”?
Question3: Do I really need to call dv.io.load(page.file.path)?
Question4: How do I get the formatting in the table right? For instance, if I have in my daily notes the paragraph
THX:: Tipps by [[Hermann]]:
* [[JohnDoe]] should do foo
* otherwise keep doing bar
I would like to get the whole paragraph in my table, but I only see:
Q3: i always use that
Q5: if you use dv.io.load with regex you can use something like .*${currentFile}.* or .*\[\[${basename}\]\].* to get the whole line or paragraph as context
Thanks, Yurcee, I guess dv.io.load is the way to go then.
I don’t understand your Q5: It is an answer to my Question4, right? What should those regexs in dv.io.load do?
But with dv.io.load(page.file.path), I do get the whole notes, exactly as they are in my daily folder. I did find a bug in my script wrt Question4: I should use content.split("\n\n") instead of content.split("\n"). However, the paragraph is displayed in the table with empty lines and I don’t understand why:
q1: according to posts on the forum and the official dataview documentation you can get to task and list items but not plain text, which you can get with dvjs’s dv.io.load – so if you have structured you dailies with indented lists like in the linked example, you can get at them with plain dataview
q4: i have a feeling you want the plain dv method because of the issue experienced with dvjs? then try extracting the text in a different way – i saw on the forum this done some way, where results were separated by html tags, so you can do html stuff with dvjs as well
surprisingly, it is quite fast as well…for big vaults i do multiple extractions for note syntax checks and it works well, although dataview does NOT index main body text content at startup