Dataview
up:: Obsidian Plugins
- ποΈ Documentation
- DataviewJS Documentation
- Dataview plugin snippet showcase - Share & showcase - Obsidian Forum
- DataviewJS Snippet Showcase - Share & showcase - Obsidian Forum
General
- The links introduced through dataview are not Obsidian notes, so donβt show up in backlinks or the graph
- Emojis are valid YAML metadata!
- See note as dataview does:
app.plugins.plugins.dataview.api.page('Note Name')
Methods:
file.size
file.name
file.mtime
: modified timefile.ctime
: created timefile.tags
: tags of filefile.path
: βFolder/Name.mdβ
Lists
- From tag:
from #moc
- From folder:
from "Attachements"
- Links
- coming into:
from [[Test MOC]]
- going out:
from outgoing([[test moc]])
- coming into:
- Logical operators:
and
or
- negate:
list from -#personal
- String Concatenation:
list "File path: " + file.path + " :)"
Tasks:
- Take all check boxes:
task from #moc
where {condition}
- comparison operators:
<
,>
,!=
- Examples:
- exclude Templates:
WHERE !contains(file.name,"emplate")
- exclude note: `where file.name != βTo excludeβ
- modified at least yesterday:
where file.mtime >= date(today) - dur(1 day)
- without a (or empty) yaml frontmatter field:
where !dueDate
- exclude Templates:
Tables
table authors from "Sources"
- Sort:
sort file.name asc
- for ties: multiple properties
flatten
: Each author gets own row (duplicate)- Grouping:
table intensity, rows.file.name
from "Assignments"
group by something
Snippets
DataviewJS
βBurn outβ to markdown
List
dv.list(
dv.pages("").where(p => p.file.folder == "A - Test"
).file.link
)
Table: Tiers + Owned Checkbox
Table: Availability
Sorting
By tzhou
on Discord:
Pages read percentage
var pagesRead = dv.current().pagesRead; dv.paragraph("Read: **" + Math.floor((pagesRead / dv.current().pages * 100)) + "**% (" + (dv.current().pages - pagesRead) + "p left)")
To-do
wanted: list everything that doesnβt have the tag #publish
but links to a note that has it
Daily journaling
const dayInMonth = moment().format("D");
const currentMonth = moment().format("M");
var i = 1;
while (currentMonth > i) {
var entries = entriesSum(i);
var max = daysInMonth(i);
var perc = entries + "/" + max;
dv.span(
`### ${monthName(i)} <sup>[[${monthNote(i)}|${perc}]]</sup><br>${progressBar(entries, max)}`
);
// Current month
i++;
entries = entriesSum(i);
max = dayInMonth;
perc = entries + "/" + max;
if (currentMonth == i) {
dv.span(
`### π’ ${monthName(i)} <sup>[[${monthNote(i)}|${perc}]]</sup><br>${progressBar(entries, max)}`
);
}
}
// Math.floor(amountOfCompletedTasks / amountOfTasks * 100);
// <progress value="${amountOfCompletedTasks}" max="${amountOfTasks}">${amountOfCompletedTasks}</progress>
function monthName(month) {
return moment(`2022-${month}`).format("MMMM");
}
function entriesSum(month) {
var month = month.toString().padStart(2, '0');
const re = new RegExp(`2022-${month}-\\d{2}`);
return dv.pages('"10 Journals/2022.11 Dailies"').where(p => re.test(p.file.name)).array().length;
}
function daysInMonth(month) {
var month = month--;
return moment([2022, month]).daysInMonth();
}
function progressBar(entries, max) {
return `<progress value="${entries}" max="${max}">${entries}</progress>`;
}
function monthNote(month) {
return moment(`2022-${month}`).format("YYYY-MM-MMMM");
}