Skip to content

Instantly share code, notes, and snippets.

@rootiest
Last active June 23, 2025 02:57
Show Gist options
  • Save rootiest/5df3c92cc07300ce64cf97c8ed435cbe to your computer and use it in GitHub Desktop.
Save rootiest/5df3c92cc07300ce64cf97c8ed435cbe to your computer and use it in GitHub Desktop.
Dynamic Obsidian Note for retrieving data from people-journals (Requires DataView and Meta-Bind)
---
meta-date: 2025-06-21
meta-name: Chris
---
# Search within People Notes
Pick Date: `INPUT[datePicker(title(Choose date)):meta-date]`
Pick Name: `INPUT[text(placeholder(Enter name..)):meta-name]`
```meta-bind-button
label: "Refresh Data"
id: refresh-dataview
style: primary
actions:
- type: command
command: "dataview:dataview-rebuild-current-view"
```
```dataviewjs
// Get metadata from the current note's frontmatter
const metaName = dv.current()["meta-name"];
const metaDateValue = dv.current()["meta-date"];
// --- Start of Conditional Logic ---
// 1. First, check if the required frontmatter exists.
if (!metaName || !metaDateValue) {
dv.paragraph("⚠️ **Error:** Could not find 'meta-name' or 'meta-date' in the frontmatter.");
} else {
// 2. If it exists, proceed to find the target note.
const metaDate = metaDateValue.toFormat("yyyy-MM-dd");
const targetPage = dv.pages('"People"').where(p => p.file.name.includes(metaName)).first();
if (!targetPage) {
dv.paragraph(`⚠️ **Error:** No note found in the "People" folder with a filename containing "${metaName}".`);
} else {
// 3. If the note is found, check for the heading and create the link.
const cache = dv.app.metadataCache.getFileCache(targetPage.file);
const targetHeading = cache?.headings?.find(h => h.level === 1 && h.heading === metaDate);
if (targetHeading) {
// SUCCESS: Heading was found, so create the link.
const link = `![[${targetPage.file.path}#${metaDate}|View the entry for ${metaDate}]]`;
dv.paragraph(link);
} else {
// FINAL CASE: The note was found, but the specific heading was not.
dv.paragraph(`ℹ️ A note for "${metaName}" was found, but a heading for **${metaDate}** does not exist within it.`);
}
}
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment