summaryrefslogtreecommitdiff
path: root/src/chef/utils.clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/chef/utils.clj')
-rw-r--r--src/chef/utils.clj27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/chef/utils.clj b/src/chef/utils.clj
index c2c6bc1..e2725ce 100644
--- a/src/chef/utils.clj
+++ b/src/chef/utils.clj
@@ -3,7 +3,8 @@
[honey.sql :as sql]
[next.jdbc :as jdbc]
[ring.util.response :as ruresp]
- [clojure.string :as cstr]))
+ [clojure.string :as cstr])
+ (:import java.io.File))
(defn gen-page [title & content]
[:html
@@ -11,7 +12,8 @@
[:meta {:name "viewport" :content "width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"}]
[:title title]
[:link {:rel :stylesheet :href "/static/style.css"}]
- [:meta {:http-equiv "content-type" :content "text/html; charset=utf-8"}]]
+ [:meta {:http-equiv "content-type" :content "text/html; charset=utf-8"}]
+ [:meta {:name "robots" :content "noindex,nofollow"}]]
(apply conj [:body] content [[:script {:src "/static/htmx.js"}]])])
(defmacro auth-only [request & body]
@@ -40,3 +42,24 @@
category-parents
(map #(:categories/name %))
(cstr/join " > ")))
+
+(defn parse-ingredients [s]
+ (->> s
+ (re-seq #"([A-z0-9 ]*)=([0-9]*) ?([A-z]*)")
+ (map #(hash-map :description (nth % 1)
+ :amount (Integer/parseInt (nth % 2))
+ :unit (nth % 3)))))
+
+(defn valid-ingredients? [s]
+ (and (string? s)
+ (->> s
+ (re-matches #"(([A-z0-9 ]*)=([0-9]*) ?([A-z]*)\n?)*")
+ some?)))
+
+(defn get-thumbnail-file [recipe]
+ (let [thumbnails-folder (File. "./thumbnails/")]
+ (->> thumbnails-folder
+ .listFiles
+ (filter #(cstr/starts-with? (.getName ^File %)
+ (str (:recipes/id recipe) ".")))
+ first)))