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,10 +299,11 @@
(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"
:disqus? disqus? :home true
:post (get-in params [:latest-posts 0]) :disqus? disqus?
:uri (str blog-prefix "/index.html")})))) :post (get-in params [:latest-posts 0])
:uri (str blog-prefix "/index.html")}))))
(defn compile-archives (defn compile-archives
"Compiles the archives page into html and spits it out into the public folder" "Compiles the archives page into html and spits it out into the public folder"
@ -306,9 +312,10 @@
(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"
:groups (group-for-archive posts) :archives true
:uri (str blog-prefix "/archives.html")})))) :groups (group-for-archive posts)
:uri (str blog-prefix "/archives.html")}))))
(defn tag-posts (defn tag-posts
"Converts the tags in each post into links" "Converts the tags in each post into links"
@ -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