ShapeyShifty/src/clj/shapey_shifty/routes/home.clj

36 lines
1.2 KiB
Clojure
Raw Normal View History

2020-01-06 18:57:10 +00:00
(ns shapey-shifty.routes.home
(:require
2020-02-13 00:36:35 +00:00
[shapey-shifty.layout :as layout]
[clojure.java.io :as io]
[shapey-shifty.middleware :as mid]
[ring.util.response]
[shapey-shifty.posts.core :as posts]
[shapey-shifty.posts.posts-io :as post-io]
[shapey-shifty.routes.post-router :as post-router]
[shapey-shifty.authors.author-core :as author]
[ring.util.http-response :as response]))
(def middleware (atom [mid/wrap-csrf mid/wrap-formats]))
2020-01-28 07:14:01 +00:00
2020-01-06 18:57:10 +00:00
(defn home-page [request]
(layout/render request "home.html" {:docs (-> "docs/docs.md" io/resource slurp)}))
2020-01-28 07:14:01 +00:00
(defn post-view [request]
(let [{:keys [path-params query-params body-params]} request
2020-01-29 01:42:18 +00:00
{:keys [year month day n]} path-params
post (post-router/get-post year month day n)]
(layout/render request "post.html" {:post (:properties post)
:card (:author post)})))
2020-01-28 07:14:01 +00:00
2020-01-06 18:57:10 +00:00
(defn about-page [request]
2020-02-13 00:36:35 +00:00
(layout/render request "h_card.html"
{:card (:card (author/load-author (get-in request [:path-params :name])))}))
2020-01-06 18:57:10 +00:00
(defn home-routes []
[""
2020-02-13 00:36:35 +00:00
{:middleware @middleware}
2020-01-06 18:57:10 +00:00
["/" {:get home-page}]
2020-02-13 00:36:35 +00:00
["/about/:name" {:get about-page}]
["/:year/:month/:day/:n" {:get post-view}]])
2020-01-06 18:57:10 +00:00