The issue:
It’s a little complex. I’ll try to be as specific as possible.
I have a folder called MOCs/Peoples, which have people notes in it. Each people note have a templater which automatically puts the people note in the peoples folder. My daily notes are in the like DailyNotes/2024/October/31st October 2024.
[IMP] I also have a dataviewjs query in each people note which shows when I met them through their link & “#meet” in the daily note, similar code for when I had dream of them using their link & #dream, also some more criteria.
I’ll paste example of one dataviewjs query:
// Get the current note's name
const currentNoteName = dv.current().file.name;
// Define the target link and text to search for
const targetLink = `[[${currentNoteName}]]`;
const targetText = "#meet";
// Define the folder to search in (replace "YourFolder" with the actual folder path)
const folderPath = "";
// Get all files within the specified folder
const filesInFolder = dv.pages(`"${folderPath}"`);
// Initialize an array to hold results
let results = [];
// Iterate over each file in the specified folder
for (const file of filesInFolder) {
// Load the file content
let fileContent = await dv.io.load(file.file.path);
// Remove all DataviewJS code blocks to avoid self-mentions
const codeBlockRegex = /```dataviewjs[\s\S]*?```/g;
fileContent = fileContent.replace(codeBlockRegex, "");
// Split the file content into paragraphs
const paragraphs = fileContent.split("\n\n");
// Find the index of the paragraph that contains both the link and text
const mentionedParagraphIndex = paragraphs.findIndex(p => p.includes(targetLink) && p.includes(targetText));
// If a matching paragraph is found, add it to the results
if (mentionedParagraphIndex !== -1) {
results.push({
file: `[[${file.file.name}]]`,
mention: paragraphs[mentionedParagraphIndex].trim()
});
}
}
// Display the results in a table if mentions are found
if (results.length > 0) {
dv.table(
["Note", "Paragraph containing current note link and #meet"],
results.map(result => [result.file, result.mention])
);
} else {
dv.paragraph("No paragraphs containing both the current note link and #meet were found in any file in the folder.");
}
What I’m trying to do:
I want to create a template (using templater or dataviewjs), which when applied to a people note creates a link to a note of above dataview query with title as:
" meets, meetings & dreams with {title of the people note name where the this dataviewjs query code is linked} from the {the year from which the the dataviewjs query I mentioned has pulled the data}.
I want it automatically made for every year.
In simpler words, I want the meets of that person as a note linked to the person’s note yearwise"
Please don’t single people out for questions that could be answered by others. If ReaderGuy42 sees this and replies, great. No need to ping them. Thanks.
So, I’m not totally clear on what you actually want. A link to a note or a template that you can insert? The latter would be easier:
# meets, meetings & dreams with <% tp.file.title %> from <% tp.date.now(format: string = "YYYY-MM-DD") %>
```dataviewjs
// Define the target link you're looking for
const targetLink = "<% tp.file.title %>"; // The link you're tracking, e.g., [[xyz]]
// Define the folder to search in (replace "YourFolder" with the actual folder path)
const folderPath = "YourFolder";
// Get all files within the specified folder
const filesInFolder = dv.pages(`"${folderPath}"`);
// Initialize an array to hold results
let results = [];
// Iterate over each file in the specified folder
for (const file of filesInFolder) {
// Load the file content
let fileContent = await dv.io.load(file.file.path);
// Remove all DataviewJS code blocks to avoid self-mentions
const codeBlockRegex = /```dataviewjs[\s\S]*?```/g;
fileContent = fileContent.replace(codeBlockRegex, "");
// Split the file content into paragraphs
const paragraphs = fileContent.split("\n\n");
// Filter paragraphs that contain the target link
const mentions = paragraphs.filter(p => p.includes(targetLink));
// If mentions are found, add them to results with file name
if (mentions.length > 0) {
results.push({
file: file.file.name,
mentions: mentions.map(p => p.trim())
});
}
}
// Display the results in a table if mentions are found
if (results.length > 0) {
dv.table(
["File", "Paragraphs containing xyz"],
results.flatMap(result => result.mentions.map(p => [result.file, p]))
);
} else {
dv.paragraph("No mentions of xyz found in any file in the folder.");
}
```
That will take the note title, e.g. “Johnson, Fred” and put it in the header, as well as look for links with that title.
Also ariehen is right, there are plenty of people who can help, not just me, plus most of them are more qualified
I want a persons note having, a link to a other note, saying “[person 2024]” that note will be having the dataviewjs query you provided me before.
after 2024 ends, I want an automatic note created which says “[person 2025]”.
I want it to be automatic without manually creating yearly notes for people, as there will be many people notes.
The query you provided me for [link of the persons note] & #meet. I tweaked a little using claude:
// Get the current note's name
const currentNoteName = dv.current().file.name;
// Define the target link and text to search for
const targetLink = `[[${currentNoteName}]]`;
const targetText = "#meet";
// Define the folder to search in (replace "YourFolder" with the actual folder path)
const folderPath = "";
// Get all files within the specified folder
const filesInFolder = dv.pages(`"${folderPath}"`);
// Initialize an array to hold results
let results = [];
// Iterate over each file in the specified folder
for (const file of filesInFolder) {
// Load the file content
let fileContent = await dv.io.load(file.file.path);
// Remove all DataviewJS code blocks to avoid self-mentions
const codeBlockRegex = /```dataviewjs[\s\S]*?```/g;
fileContent = fileContent.replace(codeBlockRegex, "");
// Split the file content into paragraphs
const paragraphs = fileContent.split("\n\n");
// Find the index of the paragraph that contains both the link and text
const mentionedParagraphIndex = paragraphs.findIndex(p => p.includes(targetLink) && p.includes(targetText));
// If a matching paragraph is found, add it to the results
if (mentionedParagraphIndex !== -1) {
results.push({
file: `[[${file.file.name}]]`,
mention: paragraphs[mentionedParagraphIndex].trim()
});
}
}
// Display the results in a table if mentions are found
if (results.length > 0) {
dv.table(
["Note", "Paragraph containing current note link and #meet"],
results.map(result => [result.file, result.mention])
);
} else {
dv.paragraph("No paragraphs containing both the current note link and #meet were found in any file in the folder.");
}
I also know this question is complex & will be needing a lot of time. I am extremely grateful for your help.