seethroughdev / obsidian-recipe-grabber

MIT License
53 stars 7 forks source link

Splitting ingredient amount and description #3

Closed Hermobi closed 1 year ago

Hermobi commented 1 year ago

Hey, at first I would like to thank you for this genius plugin. It came perfectly timed. I am working on a semi-automated shopping-list with tasks and pimped your recipe template with some dataview to calculate the ingredients for my target amount of servings.

Now comes my question: Is it possible for you to separate the amount of ingredients from the description like this?

 {{#each recipeIngredient}}
- {{thisAmount}} {{thisDescription}}
{{/each}}

Then I can calculate my amounts without any additional changes. My setup would then look like this (short version):

---
servings: {{recipeYield}}
---
ServingsTarget:: 4

### Ingredients
{{#each recipeIngredient}}
-  `= round(sum({{thisAmount}} / this.servings * this.ServingsTarget), 2)` {{thisDescription}}
{{/each}}
  • round to 2 numbers edited

The cherry on the cake would be to split the output of {{recipeYield}} also. So I also just get a number without description.

Thanks in advance. Markus

seethroughdev commented 1 year ago

I'm so glad it helped you! And especially that you were able to make use of the templating feature. I had no idea if anyone would find it useful.

So I remember doing ingredients independently first, and then changing it to the simpler recipeIngredient instead. Because the amount of logic made it pretty hard to deal with. And my worry was users who didn't have those requirements would not want this.

But maybe I can find a way to make both an option? I'm away from my cpu for the next couple of days, but I'll try and give it a look after that.

One last concern that comes to mind is that I found a lot of inconsistency on how the RecipeSchemas were used. So the more logic/view in your list as well as this plugin risks more recipes not working. Just a thought.

Thanks again for using it and the feedback, I'll update you when i get a chance to look through the code again.

Hermobi commented 1 year ago

Thanks for your reply. I tested some bigger German Websites and the ingredients worked fine. Some drop the preparation part. But that can be copied fast. I use some more detailed specifications in my frontmatter that also work fine. The definition is a bit awkward like PT10M, but that can be manually changed easily. prepTime: "{{prepTime}}" cookTime: "{{cookTime}}" totalTime: "{{totalTime}}" servings: {{recipeYield}}

If you like to, we can have a teams chat or use any other platform. I can share you my setup. My combination of Tasks and Dataview enables me to create a full cycle from grabbing the recipe, via calculating the amounts of defined servinges to placing each ingredient on my shoppinglist. That's what I wanted to get. Just started two weeks ago. I am not a programmer, more an integrator with a lot of experience in Webdevelopment.

seethroughdev commented 1 year ago

Okay, I had time to look a little further, and here, recipeIngredient is a string because that's how the spec defines it. So there really is no concept of:

  • {{thisAmount}} {{thisDescription}}

in the schema. Its completely open how someone wants to describe their ingredient. You would have to write a parser for yourself. There are a few out there, but it would definitely go out of the scope of this plugin.

Another thing that might be helpful is to look at https://schema.org/Recipe, as you should be able to use any of those additional details if the content supplies it.

So unfortunately, I don't think i can help with this one, but if you have other things come up I'm happy to see what we can do to improve it.

Hermobi commented 1 year ago

Thanks for taking a look. ChatGPT can separate it very easy. Just tried it. I now use the QuickAdd AI plugin within Obsidian to let it build my calculations. Works fine.

seethroughdev commented 1 year ago

Great idea.