summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-05-01 18:07:55 +0200
committerxengineering <me@xengineering.eu>2023-05-01 18:07:55 +0200
commit358c5e76d67477b26d841985649b9279d7633fc3 (patch)
treec463327722b29a58d3f69dfcd34c806297d4d70c
parentca3c6edebc835eadbaa5c1f432193ad7b036bf86 (diff)
downloadceres-358c5e76d67477b26d841985649b9279d7633fc3.tar
ceres-358c5e76d67477b26d841985649b9279d7633fc3.tar.zst
ceres-358c5e76d67477b26d841985649b9279d7633fc3.zip
Switch to tripel to describe ingredients
It is always the same: - amount float32 - unit string - type string This is good as a starting point. Later the types of ingredients might have to be tracked. In this a string as key is maybe not the best.
-rw-r--r--data/storage/recipes/0/text8
-rw-r--r--data/storage/recipes/1/text2
-rw-r--r--data/templates/recipe.html2
-rw-r--r--recipe.go11
4 files changed, 13 insertions, 10 deletions
diff --git a/data/storage/recipes/0/text b/data/storage/recipes/0/text
index aeee825..b0adef8 100644
--- a/data/storage/recipes/0/text
+++ b/data/storage/recipes/0/text
@@ -6,15 +6,15 @@
{
"text":"Prepare vegetables.",
"ingredients":[
- {"type":"carrot", "amount":"3 pieces"},
- {"type":"tomato", "amount":250}
+ {"amount":3, "unit":"pieces", "type":"carrot"},
+ {"amount":250, "unit":"g", "type":"tomato"}
]
},
{
"text":"Cook those vegetables",
"ingredients":[
- {"type":"water", "amount":null},
- {"type":"salt", "amount":null}
+ {"amount":0, "unit":"", "type":"water"},
+ {"amount":0, "unit":"", "type":"salt"}
]
}
]
diff --git a/data/storage/recipes/1/text b/data/storage/recipes/1/text
index d082bf7..1c4acb8 100644
--- a/data/storage/recipes/1/text
+++ b/data/storage/recipes/1/text
@@ -6,7 +6,7 @@
{
"text":"Bake the frozen pizza!",
"ingredients":[
- {"type":"pizza", "amount":"4 pieces"}
+ {"amount":4, "unit":"pieces", "type":"pizza"}
]
}
]
diff --git a/data/templates/recipe.html b/data/templates/recipe.html
index bec6eb5..a91f025 100644
--- a/data/templates/recipe.html
+++ b/data/templates/recipe.html
@@ -22,7 +22,7 @@
{{range .Recipe.Steps}}
<section>
<p>{{.Text}}</p>
- <p><i>{{range $i, $el := .Ingredients}}{{if $i}}, {{end}}{{$el.Amount}} {{$el.Type}}{{end}}</i></p>
+ <p><i>{{range $i, $el := .Ingredients}}{{if $i}}, {{end}}{{if ne $el.Amount 0.0}}{{$el.Amount}} {{end}}{{if ne $el.Unit ""}}{{$el.Unit}} {{end}}{{$el.Type}}{{end}}</i></p>
</section>
{{end}}
diff --git a/recipe.go b/recipe.go
index b28aebb..b80286a 100644
--- a/recipe.go
+++ b/recipe.go
@@ -15,13 +15,16 @@ type recipe struct {
Url string
Steps []struct {
Text string
- Ingredients []struct {
- Type string
- Amount any
- }
+ Ingredients []ingredient
}
}
+type ingredient struct {
+ Amount float32
+ Unit string
+ Type string
+}
+
func getRecipeText(id string) ([]byte, error) {
var b []byte
textpath := filepath.Join(config.Data, "recipes", id, "text")