summaryrefslogtreecommitdiff
path: root/src/chef/utils.clj
diff options
context:
space:
mode:
authorTim <contact@bytim.eu>2025-05-31 17:03:51 +0200
committerTim <contact@bytim.eu>2025-05-31 17:03:51 +0200
commitffb5d0b740e3fa23143ad89dab29a44d5b0acd34 (patch)
tree1c4ff1d69bbf81a0a3dfe7c2c2bf1f5cd3e867ad /src/chef/utils.clj
parentea7b0078478ba7925f2db3cb1fa038e8a3d85ab8 (diff)
downloadchef-ffb5d0b740e3fa23143ad89dab29a44d5b0acd34.tar.xz
chef-ffb5d0b740e3fa23143ad89dab29a44d5b0acd34.zip
Add real data to home page + add search logic + add recipe pages
Diffstat (limited to 'src/chef/utils.clj')
-rw-r--r--src/chef/utils.clj31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/chef/utils.clj b/src/chef/utils.clj
index 1ea5136..c2c6bc1 100644
--- a/src/chef/utils.clj
+++ b/src/chef/utils.clj
@@ -21,17 +21,22 @@
(ruresp/status 302)
(ruresp/header "Location" "/auth"))))
+(defn category-parents [category]
+ (loop [parents (list)
+ category category]
+ (let [updated-parents (conj parents category)]
+ (if (not= -1 (:categories/parent category))
+ (recur updated-parents
+ (->> {:select [:*]
+ :from [:categories]
+ :where [:= :id (:categories/parent category)]}
+ sql/format
+ (jdbc/execute! @cdb/db)
+ first))
+ updated-parents))))
+
(defn category-path [category]
- (cstr/join " > "
- (loop [path (list)
- category category]
- (let [new-path (conj path (:categories/name category))]
- (if (some? (:categories/parent category))
- (recur new-path
- (->> {:select [:*]
- :from [:categories]
- :where [:= :id (:categories/parent category)]}
- sql/format
- (jdbc/execute! @cdb/db)
- first))
- new-path)))))
+ (->> category
+ category-parents
+ (map #(:categories/name %))
+ (cstr/join " > ")))