diff options
author | Tim <contact@bytim.eu> | 2025-05-31 17:03:51 +0200 |
---|---|---|
committer | Tim <contact@bytim.eu> | 2025-05-31 17:03:51 +0200 |
commit | ffb5d0b740e3fa23143ad89dab29a44d5b0acd34 (patch) | |
tree | 1c4ff1d69bbf81a0a3dfe7c2c2bf1f5cd3e867ad /src/chef/utils.clj | |
parent | ea7b0078478ba7925f2db3cb1fa038e8a3d85ab8 (diff) | |
download | chef-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.clj | 31 |
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 " > "))) |