Snippets I’ve written for the Dataview Obsidian plugin.
For snippets that require a Dataview “view”, refer to the docs or this short guide.
Table of contents
Open Table of contents
Get days since note was created.
DataviewJS query:
$ = moment().diff(moment(dv.current().file.cday.toString()), "days");
Get notes that have any matching interests.
Sample frontmatter:
---
interests:
- sports
- cooking
---
Dataview query:
TABLE interests
FROM "People"
WHERE any(filter(interests, (x) => contains(this.interests, x)))
Get notes that have any matching interests and only return matching interests.
Sample frontmatter:
---
interests:
- sports
- cooking
---
Dataview query:
TABLE filter(interests, (x) => contains(this.interests, x)) as "interests"
FROM "People"
WHERE any(filter(interests, (x) => contains(this.interests, x)))
Get links to previous and next daily notes
This is a modified script from deezy in the Obsidian Discord.
Dataview view:
// Get list of notes ordered alphanumerically.
const pages = dv.pages(input.source).sort((page) => page.file.path);
// Get index of current page in list of pages.
const currPageIndex = pages.findIndex(
(page) => page.file.path === dv.current().file.path
);
// Create links to previous and next notes. If no previous/next note, use a fallback.
const getLinkSafe = (page, fallback) => page?.file?.link || fallback;
const prevLink = getLinkSafe(pages[currPageIndex - 1], "Earliest Entry");
const nextLink = getLinkSafe(pages[currPageIndex + 1], "Latest Entry");
dv.header(6, `<< ${prevLink} | ${nextLink} >>`);
Sample usage:
```dataviewjs
dv.view("00 Meta/03 Dataview Views/sequential-links", { source: '"Daily Notes"' })
```