Change your colour scheme

Using Obsidian for meal planning


In my App defaults post, I mentioned I use Obsidian for various tasks, one of them being meal planning, so I thought I’d share how I actually manage that.


Obsidian, obviously.

Secondly, it relies on having the Dataview plugin installed. Dataview is a really neat plugin that provides a simple scripting language over your Obsidian vault, that you can use to query and display data from your files.

Storing the data

My Obsidian vault is also where I share my recipes. Each recipe is stored under the recipes/ directory, and when I add a new one I add tags that I can then query against. For example, my recipe for a Broccoli and Cheddar Soup is tagged with #easy and #lunch, because it’s easy to make and I can take it with me for lunch. Truly, revolutionary stuff.

Querying the data

I’ll admit, I didn’t come up with this query myself, instead I adapted it from this Reddit comment. Here’s the full query I use for generating my weekly meal plan:

const tags = ["#recipe", "#lunch", "#easy"]

const recipes = dv.pages(tags.join(' and '));
const maxItems = Math.min(recipes.length, 2);
const randomNum = DateTime.now().toFormat("WW") % recipes.length;

const items = Array(maxItems).fill().map((_, i) => recipes[((randomNum + i) % recipes.length)])

dv.list(items.map((item) => (item.file.link)))

It’s fairly straightforward. I query for every item that’s tagged with #recipe, #easy and #lunch. Then, I pick a “random” number (it’s not random - it’s the modulo of the number of recipes by the week of the year). As the Reddit comment points out, this way I have repeatable results for each week of the year - otherwise my meal plan would change every time I opened it.

Then, I pick use that number as an index to select at most two of the recipes that match the tags, and then list them. Easy!

Screenshot showing a heading that says "Meal Plan". The subheading lists two meals under "Lunch": Stir-fried chicken & vegetables, and Lemon & Garlic Butter Shrimp

And that’s more-or-less it. I’m only generating my lunch meal plan at the minute - I have one for dinner but I’ve not got many recipes, so unless I want to eat the same thing every night until the end of time it’s best to ignore it.

About the author

My face

I'm Lewis Dale, a software engineer and web developer based in the UK. I write about writing software, silly projects, and cycling. A lot of cycling. Too much, maybe.