diff --git a/src/clj/catalog/routes/home.clj b/src/clj/catalog/routes/home.clj index 403c463..ac53553 100644 --- a/src/clj/catalog/routes/home.clj +++ b/src/clj/catalog/routes/home.clj @@ -19,15 +19,16 @@ [ "" {:middleware [middleware/wrap-csrf middleware/wrap-formats]} - ["/" {:get {:handler (fn [_] (views/home))}}] + ["/" {:get {:handler views/home}}] ["/:year/:issue" {:coercion spec-coercion/coercion :middleware [coercion/coerce-request-middleware multipart/multipart-middleware]} - ["" {:get {:parameters {:path {:year ::year :issue ::issue}} - :handler (fn [{{{:keys [year issue]} :path} :parameters}] - (views/home year issue))}}] + ["" {:name :issue + :get {:parameters {:path {:year ::year :issue ::issue}} + :handler (fn [{{{:keys [year issue]} :path} :parameters :as request}] + (views/home request year issue))}}] ;; Neu im Sortiment ["/neu-im-sortiment.pdf" diff --git a/src/clj/catalog/web/layout.clj b/src/clj/catalog/web/layout.clj index b17b0ad..80fa483 100644 --- a/src/clj/catalog/web/layout.clj +++ b/src/clj/catalog/web/layout.clj @@ -3,6 +3,7 @@ (:require [catalog.issue :as issue] [hiccup.page :refer [html5 include-css include-js]] [ring.util.http-response :as response] + [reitit.core :as reitit] [trptcolin.versioneer.core :as version])) (defn glyphicon @@ -34,6 +35,11 @@ (for [[link label] items] (menu-item link label))]]) +(defn path-for [{::reitit/keys[router]} name args] + (-> router + (reitit/match-by-name name args) + (reitit/match->path))) + (defn navbar "Display the navbar" [year issue] diff --git a/src/clj/catalog/web/views.clj b/src/clj/catalog/web/views.clj index 15b9171..41121dd 100644 --- a/src/clj/catalog/web/views.clj +++ b/src/clj/catalog/web/views.clj @@ -37,11 +37,12 @@ (download-button (download-url year issue file-name))]) (defn home - ([] + ([request] (let [date (time/local-date) [year issue] (issue/issue-for date)] - (response/redirect (format "/%s/%s" year issue)))) - ([year issue] + (response/redirect + (layout/path-for request :issue {:year year :issue issue})))) + ([request year issue] (layout/common year issue [:div.row