Add active-page key to config map

For certain pages a key with a boolean value is added to the config map which can then be used in templates to determine if it is the page being rendered. Not all pages have this key and boolean value. Instead of adding additional keys for every page a new generic key, 'active-page', has been added and its value is the page name, ex: 'home', 'archives', 'tags', etc. The default value is 'home'. This key can then be used in any template to check the page which is currently being rendered.
This commit is contained in:
Chris 2015-08-17 07:30:23 -07:00
parent 42faca4b82
commit 8eb0e9ff29

View file

@ -198,7 +198,8 @@
(spit (str public uri) (spit (str public uri)
(render-file (str "/html/" (:layout page)) (render-file (str "/html/" (:layout page))
(merge params (merge params
{:servlet-context "../" {:active-page "pages"
:servlet-context "../"
:page page :page page
:uri uri})))))) :uri uri}))))))
@ -213,7 +214,8 @@
(spit (str public (:uri post)) (spit (str public (:uri post))
(render-file (str "/html/" (:layout post)) (render-file (str "/html/" (:layout post))
(merge params (merge params
{:servlet-context "../" {:active-page "posts"
:servlet-context "../"
:post post :post post
:disqus-shortname disqus-shortname :disqus-shortname disqus-shortname
:uri (:uri post)})))))) :uri (:uri post)}))))))
@ -230,7 +232,8 @@
(spit (str public uri) (spit (str public uri)
(render-file "/html/tag.html" (render-file "/html/tag.html"
(merge params (merge params
{:servlet-context "../" {:active-page "tags"
:servlet-context "../"
:name name :name name
:posts posts :posts posts
:uri uri}))))))) :uri uri})))))))
@ -240,7 +243,8 @@
(spit (str public blog-prefix "/tags.html") (spit (str public blog-prefix "/tags.html")
(render-file "/html/tags.html" (render-file "/html/tags.html"
(merge params (merge params
{:uri (str blog-prefix "/tags.html")})))) {:active-page "tags"
:uri (str blog-prefix "/tags.html")}))))
(defn create-preview (defn create-preview
"Creates a single post preview" "Creates a single post preview"
@ -282,7 +286,8 @@
(spit (if (= 1 index) (str public blog-prefix "/index.html") (str public blog-prefix "/p/" index)) (spit (if (= 1 index) (str public blog-prefix "/index.html") (str public blog-prefix "/p/" index))
(render-file "/html/previews.html" (render-file "/html/previews.html"
(merge params (merge params
{:servlet-context (if (= 1 index) "" "../") {:active-page "preview"
:servlet-context (if (= 1 index) "" "../")
:posts posts :posts posts
:prev-uri prev :prev-uri prev
:next-uri next}))))))) :next-uri next})))))))
@ -294,7 +299,8 @@
(spit (str public blog-prefix "/index.html") (spit (str public blog-prefix "/index.html")
(render-file "/html/home.html" (render-file "/html/home.html"
(merge params (merge params
{:home true {:active-page "home"
:home true
:disqus? disqus? :disqus? disqus?
:post (get-in params [:latest-posts 0]) :post (get-in params [:latest-posts 0])
:uri (str blog-prefix "/index.html")})))) :uri (str blog-prefix "/index.html")}))))
@ -306,7 +312,8 @@
(spit (str public blog-prefix "/archives.html") (spit (str public blog-prefix "/archives.html")
(render-file "/html/archives.html" (render-file "/html/archives.html"
(merge params (merge params
{:archives true {:active-page "archives"
:archives true
:groups (group-for-archive posts) :groups (group-for-archive posts)
:uri (str blog-prefix "/archives.html")})))) :uri (str blog-prefix "/archives.html")}))))
@ -360,6 +367,7 @@
posts (tag-posts posts config) posts (tag-posts posts config)
params (merge config params (merge config
{:title (:site-title config) {:title (:site-title config)
:active-page "home"
:tags (map (partial tag-info config) (keys posts-by-tag)) :tags (map (partial tag-info config) (keys posts-by-tag))
:latest-posts (->> posts (take recent-posts) vec) :latest-posts (->> posts (take recent-posts) vec)
:navbar-pages navbar-pages :navbar-pages navbar-pages