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:
parent
e909a48015
commit
c52d3d1aa6
1 changed files with 27 additions and 26 deletions
|
@ -189,7 +189,7 @@
|
||||||
|
|
||||||
(defn compile-pages
|
(defn compile-pages
|
||||||
"Compiles all the pages into html and spits them out into the public folder"
|
"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)
|
(when-not (empty? pages)
|
||||||
(println (blue "compiling pages"))
|
(println (blue "compiling pages"))
|
||||||
(create-folder (str blog-prefix page-root))
|
(create-folder (str blog-prefix page-root))
|
||||||
|
@ -197,14 +197,14 @@
|
||||||
(println "\t-->" (cyan uri))
|
(println "\t-->" (cyan uri))
|
||||||
(spit (str public uri)
|
(spit (str public uri)
|
||||||
(render-file "templates/html/layouts/page.html"
|
(render-file "templates/html/layouts/page.html"
|
||||||
(merge default-params
|
(merge params
|
||||||
{:servlet-context "../"
|
{:servlet-context "../"
|
||||||
:page page
|
:page page
|
||||||
:uri uri}))))))
|
:uri uri}))))))
|
||||||
|
|
||||||
(defn compile-posts
|
(defn compile-posts
|
||||||
"Compiles all the posts into html and spits them out into the public folder"
|
"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)
|
(when-not (empty? posts)
|
||||||
(println (blue "compiling posts"))
|
(println (blue "compiling posts"))
|
||||||
(create-folder (str blog-prefix post-root))
|
(create-folder (str blog-prefix post-root))
|
||||||
|
@ -212,7 +212,7 @@
|
||||||
(println "\t-->" (cyan (:uri post)))
|
(println "\t-->" (cyan (:uri post)))
|
||||||
(spit (str public (:uri post))
|
(spit (str public (:uri post))
|
||||||
(render-file (str "templates/html/layouts/" (:layout post))
|
(render-file (str "templates/html/layouts/" (:layout post))
|
||||||
(merge default-params
|
(merge params
|
||||||
{:servlet-context "../"
|
{:servlet-context "../"
|
||||||
:post post
|
:post post
|
||||||
:disqus-shortname disqus-shortname
|
:disqus-shortname disqus-shortname
|
||||||
|
@ -220,16 +220,16 @@
|
||||||
|
|
||||||
(defn compile-tags
|
(defn compile-tags
|
||||||
"Compiles all the tag pages into html and spits them out into the public folder"
|
"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)
|
(when-not (empty? posts-by-tag)
|
||||||
(println (blue "compiling tags"))
|
(println (blue "compiling tags"))
|
||||||
(create-folder (str blog-prefix tag-root))
|
(create-folder (str blog-prefix tag-root))
|
||||||
(doseq [[tag posts] posts-by-tag]
|
(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))
|
(println "\t-->" (cyan uri))
|
||||||
(spit (str public uri)
|
(spit (str public uri)
|
||||||
(render-file "templates/html/layouts/tag.html"
|
(render-file "templates/html/layouts/tag.html"
|
||||||
(merge default-params
|
(merge params
|
||||||
{:servlet-context "../"
|
{:servlet-context "../"
|
||||||
:name name
|
:name name
|
||||||
:posts posts
|
:posts posts
|
||||||
|
@ -237,23 +237,23 @@
|
||||||
|
|
||||||
(defn compile-index
|
(defn compile-index
|
||||||
"Compiles the index page into html and spits it out into the public folder"
|
"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"))
|
(println (blue "compiling index"))
|
||||||
(spit (str public blog-prefix "/index.html")
|
(spit (str public blog-prefix "/index.html")
|
||||||
(render-file "templates/html/layouts/home.html"
|
(render-file "templates/html/layouts/home.html"
|
||||||
(merge default-params
|
(merge params
|
||||||
{:home true
|
{:home true
|
||||||
:disqus? disqus?
|
:disqus? disqus?
|
||||||
:post (get-in default-params [:latest-posts 0])
|
:post (get-in params [:latest-posts 0])
|
||||||
:uri (str blog-prefix "/index.html")}))))
|
: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"
|
||||||
[default-params posts {:keys [blog-prefix]}]
|
[{:keys [blog-prefix] :as params} posts]
|
||||||
(println (blue "compiling archives"))
|
(println (blue "compiling archives"))
|
||||||
(spit (str public blog-prefix "/archives.html")
|
(spit (str public blog-prefix "/archives.html")
|
||||||
(render-file "templates/html/layouts/archives.html"
|
(render-file "templates/html/layouts/archives.html"
|
||||||
(merge default-params
|
(merge params
|
||||||
{:archives true
|
{:archives true
|
||||||
:groups (group-for-archive posts)
|
:groups (group-for-archive posts)
|
||||||
:uri (str blog-prefix "/archives.html")}))))
|
:uri (str blog-prefix "/archives.html")}))))
|
||||||
|
@ -294,7 +294,8 @@
|
||||||
[navbar-pages sidebar-pages] (group-pages pages)
|
[navbar-pages sidebar-pages] (group-pages pages)
|
||||||
posts-by-tag (group-by-tags posts)
|
posts-by-tag (group-by-tags posts)
|
||||||
posts (tag-posts posts config)
|
posts (tag-posts posts config)
|
||||||
default-params {:title (:site-title config)
|
params (merge config
|
||||||
|
{:title (:site-title config)
|
||||||
: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
|
||||||
|
@ -302,17 +303,17 @@
|
||||||
:archives-uri (str blog-prefix "/archives.html")
|
:archives-uri (str blog-prefix "/archives.html")
|
||||||
:index-uri (str blog-prefix "/index.html")
|
:index-uri (str blog-prefix "/index.html")
|
||||||
:rss-uri (str blog-prefix "/" rss-name)
|
:rss-uri (str blog-prefix "/" rss-name)
|
||||||
:site-url (if (.endsWith site-url "/") (.substring site-url 0 (dec (count site-url))) site-url)}]
|
:site-url (if (.endsWith site-url "/") (.substring site-url 0 (dec (count site-url))) site-url)})]
|
||||||
|
|
||||||
(wipe-public-folder keep-files)
|
(wipe-public-folder keep-files)
|
||||||
(println (blue "copying resources"))
|
(println (blue "copying resources"))
|
||||||
(copy-resources config)
|
(copy-resources config)
|
||||||
(copy-images-from-markdown-folders config)
|
(copy-images-from-markdown-folders config)
|
||||||
(compile-pages default-params pages config)
|
(compile-pages params pages)
|
||||||
(compile-posts default-params posts config)
|
(compile-posts params posts)
|
||||||
(compile-tags default-params posts-by-tag config)
|
(compile-tags params posts-by-tag)
|
||||||
(compile-index default-params config)
|
(compile-index params)
|
||||||
(compile-archives default-params posts config)
|
(compile-archives params posts)
|
||||||
(println (blue "generating site map"))
|
(println (blue "generating site map"))
|
||||||
(spit (str public blog-prefix "/sitemap.xml") (sitemap/generate site-url ignored-files))
|
(spit (str public blog-prefix "/sitemap.xml") (sitemap/generate site-url ignored-files))
|
||||||
(println (blue "generating main rss"))
|
(println (blue "generating main rss"))
|
||||||
|
|
Loading…
Reference in a new issue