summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTim <contact@bytim.eu>2025-06-07 13:24:07 +0200
committerTim <contact@bytim.eu>2025-06-07 13:24:07 +0200
commit25d30f3c036f47a62ea6ebdc96496d836ebd4ef7 (patch)
treefb4e60b0706874c9d525f2ff64e2c443aa128581 /src
parent294f71fb3c5ca3f0fee62e70c9c6a3427a9afc12 (diff)
downloadchef-25d30f3c036f47a62ea6ebdc96496d836ebd4ef7.tar.xz
chef-25d30f3c036f47a62ea6ebdc96496d836ebd4ef7.zip
Show thumbnail on recipe pageHEADmaster
Diffstat (limited to 'src')
-rw-r--r--src/chef/pages/recipe.clj30
-rw-r--r--src/chef/routes.clj4
2 files changed, 26 insertions, 8 deletions
diff --git a/src/chef/pages/recipe.clj b/src/chef/pages/recipe.clj
index f1c1a21..84f999c 100644
--- a/src/chef/pages/recipe.clj
+++ b/src/chef/pages/recipe.clj
@@ -5,7 +5,8 @@
[hiccup2.core :as html]
[honey.sql :as sql]
[next.jdbc :as jdbc]
- [ring.util.response :as ruresp]))
+ [ring.util.response :as ruresp])
+ (:import java.io.File))
(defn- render [recipe]
(cutils/gen-page (str "chef - " (:recipes/title recipe))
@@ -14,12 +15,15 @@
[:h1 {:style {:display :inline-block
:margin-right "0.5em"}}
(:recipes/title recipe)]
- [:i (cutils/category-path (->> {:select [:*]
- :from [:categories]
- :where [:= :id (:recipes/category recipe)]}
- sql/format
- (jdbc/execute! @cdb/db)
- first))]]
+ [:i (str "(" (cutils/category-path (->> {:select [:*]
+ :from [:categories]
+ :where [:= :id (:recipes/category recipe)]}
+ sql/format
+ (jdbc/execute! @cdb/db)
+ first)) ")")]]
+ (when (some? (cutils/get-thumbnail-file recipe))
+ [:img {:src (str "/recipes/" (:recipes/id recipe) "/thumbnail")
+ :width "50%"}])
[:h2 (str "Zutaten"
(condp = (:recipes/unit recipe)
0 " pro Portion"
@@ -50,3 +54,15 @@
html/html
str
ruresp/response))
+
+(defn thumbnail-handler [req]
+ (if-let [id (get-in req [:path-params :id])]
+ (when-let [thumbnail-file (->> {:select [:*]
+ :from [:recipes]
+ :where [:= :id id]}
+ sql/format
+ (jdbc/execute! @cdb/db)
+ first
+ cutils/get-thumbnail-file)]
+ (ruresp/file-response (.getPath ^File thumbnail-file)))
+ (ruresp/bad-request "Bad request.")))
diff --git a/src/chef/routes.clj b/src/chef/routes.clj
index 03d2e5b..d21cb0d 100644
--- a/src/chef/routes.clj
+++ b/src/chef/routes.clj
@@ -18,7 +18,9 @@
[chef.pages.admin.recipe-editor :as cparecipe-editor]))
(def router [["/" {:get {:handler cphome/handler}}]
- ["/recipes/:id" {:get cprecipe/handler}]
+ ["/recipes/:id"
+ ["/" {:get cprecipe/handler}]
+ ["/thumbnail" {:get cprecipe/thumbnail-handler}]]
["/static/*" (rring/create-resource-handler)]
["/admin"
["/" {:get {:handler cpadmin/handler}}]