Dataview JS

I am working to memorize a growing list of texts, each of which I store in Obsidian as its own file. I want to create a page that will automatically list 3-4 already memorized texts that I should work on each day, to ensure that texts learnt a while ago are practiced alongside newer memorizations that still need shoring up. More specifically, each text will be scored based on how long ago it was originally memorized, how long ago I last recited it, and a rating for how fluent the recall was. The 3 or 4 highest-scoring texts will be displayed in a table, with a dropdown input item that allows me to select a rating for each of the day’s recommended texts (0-2, rating how well I recalled it). When a rating is selected, the frontmatter field containing the date of last recitation is updated to today’s date, and the rating is entered as well.

This should be very doable in a dataviewjs block, and I may use Meta Bind to implement the input field. However, I’m not using Meta Bind for anything else, so I may implement the input in javascript.

I have loaded the data I need into a data array using dv.pages(). However, I am not sure how best to calculate the date differentials, i.e. determining how many days have passed since a text was memorized, and since it was last recited. The example previewed by dv.paragraph below produces the correct result, but it seems that there ought to be a quicker way.

const poems = dv.pages('"Poems Collected"')
 .filter(t => t.file.name !== dv.current().file.name)
 .filter(t => t.memorized)
 .map(t => [t.title, t.authors, t.memorized, t.recited, t.recital])

dv.paragraph( (dv.date("2025-11-05") - poems[0][3]) / 86400000)

Also, is there a better way to approach the data structure here? Accessing via indexes seems less ideal than, e.g., via properties.

I’m sure I’ll have other questions, so I plan to keep this thread going for other help I may need along the way. Hopefully others might learn something as well.

I would check out the spaced repetition plugin to see if you’re reinventing the wheel!

but with dataviewjs and metabind I would make a button that updated a frontmatter value to declare when a note was most recently checked, then use some moment.js math to work out the difference between now and then

Thanks for the tip on Spaced Repetition. I’ll check that out!

1 Like