Obsidian - Daily Note + Random Review

18 Apr 2023 in TIL

I’ve been dutifully collecting notes in Obsidian for a while now, but the idea of going through and cleaning them all up was daunting. There are hundreds of notes that are just copy/pasted from other sources, screenshots of interesting things or rough notes on a topic.

Then I was reading about how you can use Periodic Notes to generate daily notes in Obsidian when I stumbled across this post from Michelle Mac. It showed how you can generate a list of random notes based on a tag.

I use tags in the page front matter rather than inline hashtags, so I needed to rework the logic a little. I also don’t keep all my notes in the same “Evergreen” folder, so I needed different logic for the filename.

Here’s what I ended up with. It generates a list of three posts when it runs. If you want to use it, change the values in allowedTags to source whichever pages you need:

js
<%*
const randomNotes = [];
const allowedTags = ["stub", "unedited"];
app.metadataCache.getCachedFiles().forEach(filename => {
let data = app.metadataCache.getCache(filename);
if (!data.frontmatter) {
return;
}
const tags = (data.frontmatter.tags || []).filter(t => allowedTags.indexOf(t) !== -1)
if (tags.length > 0) {
const p = filename.split("/");
const f = p[p.length-1].split(".md")[0];
randomNotes.push(f);
}
});
var i = 0
do {
const randomIndex = Math.floor(Math.random() * randomNotes.length);
tR += `- [[${randomNotes[randomIndex]}]]` + "\n"
i++
} while (i<3);
%>