diff --git a/controller/home.sh b/controller/home.sh index 883218d..b2f603d 100644 --- a/controller/home.sh +++ b/controller/home.sh @@ -9,3 +9,31 @@ home() { content="$(template "templates/home.fragment.templ")" template "templates/layout.html.templ" } + + +route GET "/recipe" recipe +recipe() { + id="$(queryString "id")" + + result="$(getRecipeById "$id")" + + if test -z "$result"; then + "$_404" + return + fi + + htmlContent + endHeaders + + name="$(echo "$result" | head -n 1 | getColumns 1)" + description="$(echo "$result" | head -n 1 | getColumns 2)" + uid="$(echo "$result" | head -n 1 | getColumns 5)" + author="$(echo "$result" | head -n 1 | getColumns 6)" + qts="$(echo "$result" | getColumns 4)" + ingredients="$(echo "$result" | getColumns 3)" + nrIngredients="$(echo "$qts" | wc -l)" + + title="" + content="$(template "templates/recipe.fragment.templ")" + template "templates/layout.html.templ" +} diff --git a/data/recipes.sh b/data/recipes.sh index e84ec54..e005b20 100644 --- a/data/recipes.sh +++ b/data/recipes.sh @@ -15,6 +15,26 @@ getRecipesByUsername() { EOF } +getRecipeById() { + local id="$(echo "$1" | sed 's/[^0-9]//g')" + + query <{{ print "$name" }} +

+ from {{ print "$author" }} +

+ + {{ for i in $(seq $nrIngredients); do }} + + + + + {{ done }} +
+ {{ echo "$qts" | tail -n +$i | head -n 1 }} + + {{ echo "$ingredients" | tail -n +$i | head -n 1 }} +
+

+ {{ print "$description" }} +