Help: #howto Build Recipe "database" in Obsidian (complex)

In my case, Dataview and Templater are fine as they are, I do not need Graph View for what I want to accomplish. The many variables there will be in what I want to build, changing in every case, ask for something strong like Dataview and Templater that give me predictable outcome time and again. I just don’t like calculating all that by hand and breaking my brain over it, when that’s not necessary :slight_smile:

Graph View is very useful for me BEFORE I put in all the variables, perhaps finding connections I didn’t see before.

Essentially, what I am trying to build is some form of “Life Assistance” thingy, that takes whatever data I have on food, exercise, mental coping mechanisms on the one hand, and on the other hand a specific person’s physical or mental complaints and spits out a range of different and perhaps synergetic “actions” this person could try to improve their health. Of course this will never be an official medical advice, always consult your doctor before incorperating anything into your life that comes out of the Life Assistance.

I am not sure I can pull this off, but I am confident that I can at least build a Recipe Database to begin with. With @Moonbase59 's help :smiley:

How many <3 <3 <3 <3 <3 would fit in this little typing window?? THANKS a bunch for the .zip !!!

Paprika has an (undocumented) API. I wonder if it’s worth making a plugin to sync recipes?

2 Likes

Hi Jeremy! Your name was already brought to my attention by Matthias :slight_smile:

Your suggestion is making my mind go in overdrive haha!

  • Obsidian, once you get the hang of it, is super easy to work with and type stuff into. Easier than entering everything in Paprika. Mostly because I think I can convert everything I already have (as .txt, .pdf, .docx and .html) with the help of Obsidian and Pandoc (still need to learn that, but I know it can be done) so no retyping needed, just some cleaning up perhaps.

  • Paprika is a real cool recipe manager, with many features I probably don’t need in the recipes in Obsidian and it has an iOS version that syncs almost realtime. So easy to be able to use my iPad as a cookbook in the kitchen on its own standard, it even has an option to keep the screen from going dark while you are cooking.

So, since both have their own unique possibiities,

  • YES, a syncing plugin would be EXTREMELY cool to have :smiley: !

=> but someone else who is smart and willing to give it time, would need to do that, because I am by no means skilled enough in that area.

Do you think it would be very difficult and time consuming?

Okay, a little update here about what I have been doing with the Recipes, for those interested. It’s also a #remindertoself (which I - of course - also put into my “Build Recipe “database” in Obsidian”-note which lives in my vault.

Sure enough, I want Recipes as a whole, to be in Dutch. After all, that’s my language. So, I needed to figure out what I could change without the risk of breaking everything. Which of course happened, to a n00b like myself :stuck_out_tongue: . Like, at least 3 times :joy: Glad I left the zip in the vault, I have unpacked and started over also 3 times.

Anyway, the first time I unpacked Recipes.zip somewhere deep in my vault, where I eventually want it to end up. Oh boy! Nothing worked anymore. I checked your screenshots (the ones in this discussion, above) and saw you had the whole thing in the root of your vault.

So, 2nd try, I deleted my try & error Recipes folder and I unpacked Recipes.zip in the root of my vault, expecting it to work then. It did. Yay!!! I made some changes, like the word “recipe” is called “recept” in Dutch. I didn’t know if I could just change that everywhere, in markup and in Dataview(js) - but after a few errors, I got that working. Cmd-R proved to be my saviour quite a few times, after I initially thought I made a mistake. My godgiven cleverness :stuck_out_tongue: kicked in just in time to hit that combo and what do you know, voila! It worked after all. Pet on my own head :grin:

But then I wanted to change categories and other stuff and kaboom! it stopped working all over again and even Cmd-R didn’t save me this time. I didn’t delete everything, but I did unpack an extra instance of Recipes, for comparison. Should have done that straightaway - not so clever I didn’t do that :stuck_out_tongue: but at least I thought of it in time for round 3.

I managed to move Recipes from the root to 1 level higher up, closer to where I wanted it to be. And I discovered, that changing the path in the Dataview code in the -TOC notes, was enough to make it work. Yay!! It needed another hit on the Cmd-R, because it kept saying that the two recipe notes weren’t created yet and refreshing the note itself wasn’t enough, apparently. But who cares. I love Cmd-R :wink: !

Now comes the creepy part - moving it to its permanent (for now) place in my vault and not breaking it. Shouldn’t be so hard, I think. But I also want to rename Recipes into Recepten…ewww! although, my sense of logic tells me, that again the onnly place I will need to change that, is in the -TOC notes. Because as far as I can see, that is - at the moment - the only place the Dataview code needs a specific path.

Just for laughs, here is a piece of my own comments in my “Build Recipe “database” in Obsidian” note:

If I need to move the recipe database to another spot in the vault, I need to update some instances of the Dataview code, specifically in the -TOC notes. Because the Dataview code in those notes, points to where exactly should be searched for recipes. I figured that out all by myself, through trial and error :wink: - Javascript and other code is not all that straightaway obvious to me, being an alpha person. Even though it’s called a language! I assumed it would go through the entire vault, looking for recipes. But apparently, it does not :slight_smile: - it needs “directions”, so to speak.

So far my Recipes adventures :wink: - y’all are probably used to way shorter forum discussion messages, but hey - like I said, I am an alpha/language person, better with words than with code. I just don’t give up easily, and beta stuff like code and science and the like do have my interest, I only lack the talent for understanding it fast and in depth.

Very good so far!

I could actually run in whatever folder, only it did always pick up my Templates (in the templates folder) up, too, so I thought "let it start in some folder “Recipes” and take what’s there (and its subfolders).

The easy step is actually in the two “TOC” notes, just change

list
from "Recipes" and #food
where recipe
sort file.name asc

to wherever your starting folder is. Don’t forget to also change the tags like #food—you might have called it “spijs” or something. Should you also have changed the variable names in the YAML, like maybe “recipe: Melon Salad” to “recept: Meloen salade”, you also need to modify the “where” clause—it looks if a note contains a “recipe” variable.

Unfortunately the ingredients notes also contain dataviewjs code that needs to be changed in every one—we don’t yet have a better way, maybe code including will come some day, so we could reuse the same code.

Here’s an ingredient dataviewjs, to find in which recipes this ingredient is used:

```dataviewjs
dv.list(dv.pages('"Recipes" and #recipe and -#toc')
    .where(p => p.recipe && p.ingredients.map(e => e[0])
        .indexOf(dv.current().ingredient) >= 0)
    .file.link
);
```

Change

  • "Recipes" to your new recepten start folder,
  • #recipe to your new tag word for recept,
  • -#toc to your new tag word for TOCs (to _ex_clude them from the search!)
  • p.recipe to your new YAML variable for the recipe: xxx entry, like p.recept
  • p.ingredients.map to your new YAML variable for ingredients, like p.ingrediënten.map (don’t know if non-ASCII works, though)
  • dv.current().ingredient to the new YAML variable for ingredient: xxx in the ingredients notes, like dv.current().ingrediënt

The good thing:

  • Since it’s the same code always, you can copy-paste

The bad thing:

  • You have to do this in all existing ingredients notes

And don’t forget to change the templates in the templates folder, too! (recipe and ingredient)

In the recipe template and all existing recipes, you need to change

  • all =this.something to = this.yourword
  • the dataviewjs code. You should now already have a good idea how, and I’ll leave this as an exercise. Please avoid typing mistakes, a wrong dot, bracket or lowercase/uppercase variation can break the whole thing! (Hint: ingredients, portions)

Have fun and let us now if things like ë and ij work in dataviewjs and Javascript variable names!

How much time the world could save if we all had just one language—for this little unimportant dirt ball we live on in a huge universe one language would be more than sufficient. We are all the same humans, after all. Sigh.

2 Likes

Hi :slight_smile: :blush:

Thanks for wrapping up the instances that need to be changed. I figured a lot of it out - which is imho the best way of learning, at least to begin with - and now I can go see if I can do it right. I like self-challenges. But I know when I need to ask for help :slight_smile: I will copy your last post into my vault so that I can check it easier.

I will let you know if non-ascii works! I was curious about that too, but left out the umlaut in ingredienten for now, to make sure it worked.

And yes…this tiny spot in the mighty vast universe is crazy. Or better put, the people on it. Humanity has done a crazy job of ruining the place. Too many fear-based, power-based creatures, brrrr. That is becoming quite obvious now with the whole covid thing. We for sure do not need 60 languages. One is more than enough. English has taken a big place in trying to become that one language and it’s good it’s there. But, over 100 years ago in 1887, L. Zamenhof already thought of that and invented Esperanto. There are still some 2 million people who speak it, nowadays. So easy to learn as a second language!

Mi deziras al vi tre belan tagon, Matiaso!

Hee hee, same to you! (I wish you a very beautiful day, she said.)

OT: In Dutch, is the diaeresis only used to separate vowels in a diphthong? So you could actually leave out this “pronounciation helper” officially? (Say, somehow like most modern Dutch writers don’t use the “ij” digraph anymore?)

1 Like

Super excited to see where this goes ! I would love to see the graph view when lots of recipes are added. I love the breakdown in the uploaded ZIP and im going to give it a try as well.

Data view is just great to open up the fridge, see what is in there and get pointed to the stuff you can make.

For preparing the food, there is the ‘presentation view’ that you can have a look at. You can also throw in images easily to make it nicer.

My recipes are currently stored in Google Keep so I’m going to look for some kind of bulk export.

1 Like

Unfortunately it looks like there are some security issues preventing communicating with Paprika. I’ll keep playing with it, but it doesn’t look like it’s going to be possible.

Ohhh, bummer :smirk: … sorry to hear that Jeremy @valentine.195

The diaeresis is used when you can read the two vowels next to each other as one sound. To prevent this, the diaphragm is used.

USE
The diaeresis is placed with the following 14 letter combinations: ee, ei, eu, ie, aa, ae, ai, au, ui, uu, oe, oi, oo and ou.

Example: poëzie, reünie, koloniën, ruïne

Rule 1 is an exception if words end in the French and Spanish letter combinations: eum, ien, eus and ei
Example: petroleum, opticien

If there are more than two vowel combinations, the vowel after the i will not have a diaeresis – the e and i that follow it will have a diaeresis.
Example: begroeiing, aaien, knieën, mozaïek, geëerd

A diaeresis is placed with numerals
Example: tweeëntwintig, drieëndertig

The diaeresis only occurs in non-compound words
Example: it is na-apen and not naäpen, it is zee-egel instead of zeeëgel

Words that end in an unstressed ie get in the plural: iën.
Example: koloniën, provinciën

Words that end in stressed ie get in the plural: ieën
Example: knieën, industrieën, melodieën

Another exception (besides rule 2) is that there is no diaeresis if there is a suffix. You then write lila-achtig, instead of lilaächtig.

Hi Michael, I don’t remember exactly, but Matthias told me something like that everything that is dynamically generated, will not be part of the graph view. Haven’t tried it yet, because I am still trying to master the Dataview(js) and making changes etc and it is really difficult for me, as I had no prior knowledge of scripting and coding. I am slowly learning by trial and many many errors :stuck_out_tongue: but I am happy to find (lots of) help here!

I have already made a template for the recipe and for the ingredients, and included a placeholder image. I gave up translating the english words in the code to Dutch, because it makes no sense really - I discovered none of those words end up in the actual note as text, they’re just used to calculate stuff.

Hi Matthias :grinning:

A (hopefully small) request/question:

Is there a way to autocalculate the ingredients per portion and make it populate the ingredients section in the YAML?

I would have to calculate that for thousands of recipes. Also, not every recipe states the amount of portions. I don’t know how to manage the ingredients in that situation. Estimate the amount of portions?

Quite time-consuming to calculate that by hand, where pasting in just the amounts mentioned in the recipe would be a no brainer.

portions: 4

ingredients:

  • [“sugar, white”, 20 g]
  • [watermelon, 286 g] # 1 wedge

The idea was to specify the ingredients per portion, and the recipe template already multiplies that by the number of portions you specify in the YAML. Try changing just the YAML portions variable and see what happens! (Closing/opening note might be required due to Dataview’s caching.)

Most recipes given in cookbooks here are for 4 portions. In this case, I just divide by 4 and enter that as the ingredient amount (sometimes ending up with something like 1.25 eggs, but what the heck).

You could of course go and modify the code to do the reverse, i.e. giving ingredients per x portions, and divide.

I understand the idea, and it’s working really well, of course I tried it after you told me the code can do that :slight_smile: :blush:

I wouldn’t know how to change the code, but I will try to see if I understand what the code actually says that it will do. I guess * means multiply, I remember that much from 45 years ago in Math class. And divide was / if I remember correctly.

1 Like

In any case, for later calculations, it makes sense to base things on always the same size (i.e., 100 g, 1 serving, etc.). Otherwise you’ll find that combined calculations, say combined GL or calories for a serving or complete recipe, will turn out almost impossible.

That’s the main reason I used “100 g” for GL and cal, and “1 portion” as a base for the recipes.

I know this can be a lot of work. Maybe if most of your recipes are already in Paprika, you can have that calculate the values and then copy to Obsidian?

Most of my recipes are still txt, docx or pdf based and not in Paprika. Paprika has about 100 or something.

I understand what you are saying about the 100g and 1 portion etc.

I just added the ingredients and the recipe for a Citroen MugCake. I followed the Melon Salad recipe and its ingredients precisely, I think I checked 100 times if it were indeed the same. It should be (and is!), as I ran the note off a template that is based on the Melon Salad recipe and that recipe and those ingredients work.

The only thing that is different, is that I didn’t use grams for the ingredients but tbsp and tsp. Because that is what is in the recipe. At first I added the Dutch equivalent of tbsp and tsp (el and tl) as units, but the code give a looooong error.

So I changed that in both the ingredients notes and the recipe note to tbsp and tsp. Same error.

I used things like 0,5 tbsp and thought, maybe it needs to be 0.5 tbsp. What do you know…it started working! <= these are the things that are not always obvious to me…why doesn’t it take 0,5 ?

After this, I could use my own units too. I have a pdf for you to see how I styled everything. Citroen MugCake

You can probably just drag-n-drop the PDF into the forum edit box.

Traditionally, programming languages are mostly using English terms, and also English number formats. That’s why I didn’t bother and just use them internally. For displaying, numbers could theoretically be converted to the number format of the language the system or Obsidian uses. But again I didn’t bother since it’s just an example to get started.

You could, for instance, in the recipe dataviewjs, replace the line

list.push(amount * dv.current().portions + " " + unit + " " + link);

against

list.push((amount * dv.current().portions).toLocaleString(moment.locale(), {maximumFractionDigits: 1}) + " " + unit + " " + link);

and it would magically output numbers (in the ingredients list) according to whatever language you’ve set Obsidian to:

Auswahl_021

EDIT: Unfortunately this is currently broken in my 0.12.4 installation.

Also, to make sense of all the units and get nutritional values out of them, conversion functions need to be written. Nothing is “automatic”, and a computer will blindly do what it is told. So for things like “piece”, “tsp” or “tbsp”, it would need to know if it’s a fluid or mass measurement, and the conversion values. A rather complicated undertaking.

Looks quite nice already, your mug cake PDF!

Btw, looks like you use an older version of the recipe template, where the ingredients have a large line spacing. I modified that later (somewhere in this thread) to use less line spacing.

1 Like

The ine spacing thing was indeed one of the things I wanted to ask. Obsidian sometimes makes them big too, but then when I close and re-open the note, it’s okay again.

It’s not so much a bother, the dot or the comma in the numbers. It was just that I discovered that this was the mistake I made to break it all (seemingly) :slight_smile: but, I will try to see if I can implement what you wrote above and make them appear as a euopean notation with a dot for thousands and up and a comma for below and for not-whole numbers.