Pass all config to templates

This allows people to use any parameter from their config as well as the
params that were already being used.
This commit is contained in:
William Roe 2015-02-23 18:14:31 +00:00
parent e909a48015
commit c52d3d1aa6

View file

@ -189,7 +189,7 @@
(defn compile-pages
"Compiles all the pages into html and spits them out into the public folder"
[default-params pages {:keys [blog-prefix page-root]}]
[{:keys [blog-prefix page-root] :as params} pages]
(when-not (empty? pages)
(println (blue "compiling pages"))
(create-folder (str blog-prefix page-root))
@ -197,14 +197,14 @@
(println "\t-->" (cyan uri))
(spit (str public uri)
(render-file "templates/html/layouts/page.html"
(merge default-params
(merge params
{:servlet-context "../"
:page page
:uri uri}))))))
(defn compile-posts
"Compiles all the posts into html and spits them out into the public folder"
[default-params posts {:keys [blog-prefix post-root disqus-shortname]}]
[{:keys [blog-prefix post-root disqus-shortname] :as params} posts]
(when-not (empty? posts)
(println (blue "compiling posts"))
(create-folder (str blog-prefix post-root))
@ -212,7 +212,7 @@
(println "\t-->" (cyan (:uri post)))
(spit (str public (:uri post))
(render-file (str "templates/html/layouts/" (:layout post))
(merge default-params
(merge params
{:servlet-context "../"
:post post
:disqus-shortname disqus-shortname
@ -220,16 +220,16 @@
(defn compile-tags
"Compiles all the tag pages into html and spits them out into the public folder"
[default-params posts-by-tag {:keys [blog-prefix tag-root] :as config}]
[{:keys [blog-prefix tag-root] :as params} posts-by-tag]
(when-not (empty? posts-by-tag)
(println (blue "compiling tags"))
(create-folder (str blog-prefix tag-root))
(doseq [[tag posts] posts-by-tag]
(let [{:keys [name uri]} (tag-info config tag)]
(let [{:keys [name uri]} (tag-info params tag)]
(println "\t-->" (cyan uri))
(spit (str public uri)
(render-file "templates/html/layouts/tag.html"
(merge default-params
(merge params
{:servlet-context "../"
:name name
:posts posts
@ -237,23 +237,23 @@
(defn compile-index
"Compiles the index page into html and spits it out into the public folder"
[default-params {:keys [blog-prefix disqus?]}]
[{:keys [blog-prefix disqus?] :as params}]
(println (blue "compiling index"))
(spit (str public blog-prefix "/index.html")
(render-file "templates/html/layouts/home.html"
(merge default-params
(merge params
{:home true
:disqus? disqus?
:post (get-in default-params [:latest-posts 0])
:post (get-in params [:latest-posts 0])
:uri (str blog-prefix "/index.html")}))))
(defn compile-archives
"Compiles the archives page into html and spits it out into the public folder"
[default-params posts {:keys [blog-prefix]}]
[{:keys [blog-prefix] :as params} posts]
(println (blue "compiling archives"))
(spit (str public blog-prefix "/archives.html")
(render-file "templates/html/layouts/archives.html"
(merge default-params
(merge params
{:archives true
:groups (group-for-archive posts)
:uri (str blog-prefix "/archives.html")}))))
@ -294,25 +294,26 @@
[navbar-pages sidebar-pages] (group-pages pages)
posts-by-tag (group-by-tags posts)
posts (tag-posts posts config)
default-params {:title (:site-title config)
:tags (map (partial tag-info config) (keys posts-by-tag))
:latest-posts (->> posts (take recent-posts) vec)
:navbar-pages navbar-pages
:sidebar-pages sidebar-pages
:archives-uri (str blog-prefix "/archives.html")
:index-uri (str blog-prefix "/index.html")
:rss-uri (str blog-prefix "/" rss-name)
:site-url (if (.endsWith site-url "/") (.substring site-url 0 (dec (count site-url))) site-url)}]
params (merge config
{:title (:site-title config)
:tags (map (partial tag-info config) (keys posts-by-tag))
:latest-posts (->> posts (take recent-posts) vec)
:navbar-pages navbar-pages
:sidebar-pages sidebar-pages
:archives-uri (str blog-prefix "/archives.html")
:index-uri (str blog-prefix "/index.html")
:rss-uri (str blog-prefix "/" rss-name)
:site-url (if (.endsWith site-url "/") (.substring site-url 0 (dec (count site-url))) site-url)})]
(wipe-public-folder keep-files)
(println (blue "copying resources"))
(copy-resources config)
(copy-images-from-markdown-folders config)
(compile-pages default-params pages config)
(compile-posts default-params posts config)
(compile-tags default-params posts-by-tag config)
(compile-index default-params config)
(compile-archives default-params posts config)
(compile-pages params pages)
(compile-posts params posts)
(compile-tags params posts-by-tag)
(compile-index params)
(compile-archives params posts)
(println (blue "generating site map"))
(spit (str public blog-prefix "/sitemap.xml") (sitemap/generate site-url ignored-files))
(println (blue "generating main rss"))