Don't create prev/next links pointing to :home? pages

- Also include more metadata in page.prev and page.next params
- And some general code cleanup
master
Carmen La 8 years ago
parent e1cb70dc1d
commit 9cd5016537

@ -1,5 +1,6 @@
(ns cryogen-core.compiler (ns cryogen-core.compiler
(:require [clojure.java.io :as io] (:require [clojure.java.io :as io]
[clojure.pprint :refer [pprint]]
[clojure.string :as s] [clojure.string :as s]
[io.aviso.exception :refer [write-exception]] [io.aviso.exception :refer [write-exception]]
[net.cgrand.enlive-html :as enlive] [net.cgrand.enlive-html :as enlive]
@ -200,13 +201,13 @@
:uri (page-uri (str (name tag) ".html") :tag-root-uri config)}) :uri (page-uri (str (name tag) ".html") :tag-root-uri config)})
(defn add-prev-next (defn add-prev-next
"Adds a :prev and :next key to the page/post data containing the title and uri of the prev/next "Adds a :prev and :next key to the page/post data containing the metadata of the prev/next
post/page if it exists" post/page if it exists"
[pages] [pages]
(map (fn [[prev target next]] (map (fn [[prev target next]]
(assoc target (assoc target
:prev (if prev (select-keys prev [:title :uri]) nil) :prev (if prev (dissoc prev :content) nil)
:next (if next (select-keys next [:title :uri]) nil))) :next (if next (dissoc next :content) nil)))
(partition 3 1 (flatten [nil pages nil])))) (partition 3 1 (flatten [nil pages nil]))))
(defn group-pages (defn group-pages
@ -223,6 +224,10 @@
(cryogen-io/create-file-recursive (cryogen-io/path file-uri "index.html") data) (cryogen-io/create-file-recursive (cryogen-io/path file-uri "index.html") data)
(cryogen-io/create-file file-uri data))) (cryogen-io/create-file file-uri data)))
(defn- print-debug-info [data]
(println "DEBUG:")
(pprint data))
(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"
[{:keys [blog-prefix page-root-uri debug?] :as params} pages] [{:keys [blog-prefix page-root-uri debug?] :as params} pages]
@ -230,9 +235,9 @@
(println (blue "compiling pages")) (println (blue "compiling pages"))
(cryogen-io/create-folder (cryogen-io/path "/" blog-prefix page-root-uri)) (cryogen-io/create-folder (cryogen-io/path "/" blog-prefix page-root-uri))
(doseq [{:keys [uri] :as page} pages] (doseq [{:keys [uri] :as page} pages]
(println "\t-->" (cyan uri)) (println "-->" (cyan uri))
(when debug? (when debug?
(println "\t\tdebug-->" (cyan page))) (print-debug-info page))
(write-html uri (write-html uri
params params
(render-file (str "/html/" (:layout page)) (render-file (str "/html/" (:layout page))
@ -250,9 +255,9 @@
(println (blue "compiling posts")) (println (blue "compiling posts"))
(cryogen-io/create-folder (cryogen-io/path "/" blog-prefix post-root-uri)) (cryogen-io/create-folder (cryogen-io/path "/" blog-prefix post-root-uri))
(doseq [{:keys [uri] :as post} posts] (doseq [{:keys [uri] :as post} posts]
(println "\t-->" (cyan uri)) (println "-->" (cyan uri))
(when debug? (when debug?
(println "\t\tdebug-->" (cyan post))) (print-debug-info post))
(write-html uri (write-html uri
params params
(render-file (str "/html/" (:layout post)) (render-file (str "/html/" (:layout post))
@ -271,7 +276,7 @@
(cryogen-io/create-folder (cryogen-io/path "/" blog-prefix tag-root-uri)) (cryogen-io/create-folder (cryogen-io/path "/" blog-prefix tag-root-uri))
(doseq [[tag posts] posts-by-tag] (doseq [[tag posts] posts-by-tag]
(let [{:keys [name uri]} (tag-info params tag)] (let [{:keys [name uri]} (tag-info params tag)]
(println "\t-->" (cyan uri)) (println "-->" (cyan uri))
(write-html uri (write-html uri
params params
(render-file "/html/tag.html" (render-file "/html/tag.html"
@ -362,20 +367,18 @@
"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"
[{:keys [disqus? debug? home-page] :as params}] [{:keys [disqus? debug? home-page] :as params}]
(println (blue "compiling index")) (println (blue "compiling index"))
(let [uri (page-uri "index.html" params) (let [uri (page-uri "index.html" params)]
meta {:active-page "home"
:home true
:disqus? disqus?
:uri uri
:post home-page
:page home-page}]
(when debug? (when debug?
(println "\t\tdebug-->" (cyan meta))) (print-debug-info meta))
(write-html uri (write-html uri
params params
(render-file (str "/html/" (:layout home-page)) (render-file "/html/home.html"
(merge params (merge params
meta))))) {:active-page "home"
:home true
:disqus? disqus?
:uri uri
:post home-page})))))
(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"
@ -400,7 +403,7 @@
;; if the post author is empty defaults to config's :author ;; if the post author is empty defaults to config's :author
(doseq [{:keys [author posts]} (group-for-author posts author)] (doseq [{:keys [author posts]} (group-for-author posts author)]
(let [uri (page-uri (str author ".html") :author-root-uri params)] (let [uri (page-uri (str author ".html") :author-root-uri params)]
(println "\t-->" (cyan uri)) (println "-->" (cyan uri))
(write-html uri (write-html uri
params params
(render-file "/html/author.html" (render-file "/html/author.html"
@ -470,58 +473,61 @@
(println (green "compiling assets...")) (println (green "compiling assets..."))
(let [{:keys [^String site-url blog-prefix rss-name recent-posts sass-dest keep-files ignored-files previews? author-root-uri theme] (let [{:keys [^String site-url blog-prefix rss-name recent-posts sass-dest keep-files ignored-files previews? author-root-uri theme]
:as config} (read-config) :as config} (read-config)
posts (add-prev-next (read-posts config)) posts (add-prev-next (read-posts config))
pages (add-prev-next (read-pages config)) posts-by-tag (group-by-tags posts)
home-pages (filter #(boolean (:home? %)) pages) posts (tag-posts posts config)
pages-without-home (filter #(boolean (not (:home? %))) pages) latest-posts (->> posts (take recent-posts) vec)
[navbar-pages sidebar-pages] (group-pages pages-without-home) pages (read-pages config)
posts-by-tag (group-by-tags posts) home-page (->> pages
posts (tag-posts posts config) (filter #(boolean (:home? %)))
latest-posts (->> posts (take recent-posts) vec) (first))
params (merge config other-pages (->> pages
{:today (java.util.Date.) (remove #{home-page})
:title (:site-title config) (add-prev-next))
:active-page "home" [navbar-pages
:tags (map (partial tag-info config) (keys posts-by-tag)) sidebar-pages] (group-pages other-pages)
:latest-posts latest-posts params (merge
:navbar-pages navbar-pages config
:sidebar-pages sidebar-pages {:today (java.util.Date.)
:home-page (if (not-empty home-pages) :title (:site-title config)
(first home-pages) :active-page "home"
(merge (first latest-posts) :tags (map (partial tag-info config) (keys posts-by-tag))
{:layout "home.html"})) :latest-posts latest-posts
:archives-uri (page-uri "archives.html" config) :navbar-pages navbar-pages
:index-uri (page-uri "index.html" config) :sidebar-pages sidebar-pages
:tags-uri (page-uri "tags.html" config) :home-page (if home-page
:rss-uri (cryogen-io/path "/" blog-prefix rss-name) home-page
:site-url (if (.endsWith site-url "/") (.substring site-url 0 (dec (count site-url))) site-url) (first latest-posts))
:theme-path (str "file:resources/templates/themes/" theme)})] :archives-uri (page-uri "archives.html" config)
:index-uri (page-uri "index.html" config)
(println (blue "debug info")) :tags-uri (page-uri "tags.html" config)
(println "\t-->" (cyan navbar-pages)) :rss-uri (cryogen-io/path "/" blog-prefix rss-name)
(set-custom-resource-path! (:theme-path params)) :site-url (if (.endsWith site-url "/") (.substring site-url 0 (dec (count site-url))) site-url)})]
(set-custom-resource-path! (str "file:resources/templates/themes/" theme))
(cryogen-io/wipe-public-folder keep-files) (cryogen-io/wipe-public-folder keep-files)
(println (blue "copying theme resources")) (println (blue "copying theme resources"))
(cryogen-io/copy-resources-from-theme config) (cryogen-io/copy-resources-from-theme config)
(println (blue "copying resources")) (println (blue "copying resources"))
(cryogen-io/copy-resources config) (cryogen-io/copy-resources config)
(copy-resources-from-markup-folders config) (copy-resources-from-markup-folders config)
(compile-pages params pages-without-home) (compile-pages params other-pages)
(compile-posts params posts) (compile-posts params posts)
(compile-tags params posts-by-tag) (compile-tags params posts-by-tag)
(compile-tags-page params) (compile-tags-page params)
(when previews? (if previews?
(compile-preview-pages params posts)) (compile-preview-pages params posts)
(when (or (not-empty home-pages) (not previews?))
(compile-index params)) (compile-index params))
(compile-archives params posts) (compile-archives params posts)
(when author-root-uri (when author-root-uri
(println (blue "generating authors views")) (println (blue "generating authors views"))
(compile-authors params posts)) (compile-authors params posts))
(println (blue "generating site map")) (println (blue "generating site map"))
(cryogen-io/create-file (cryogen-io/path "/" blog-prefix "sitemap.xml") (sitemap/generate site-url ignored-files)) (->> (sitemap/generate site-url ignored-files)
(cryogen-io/create-file (cryogen-io/path "/" blog-prefix "sitemap.xml")))
(println (blue "generating main rss")) (println (blue "generating main rss"))
(cryogen-io/create-file (cryogen-io/path "/" blog-prefix rss-name) (rss/make-channel config posts)) (->> (rss/make-channel config posts)
(cryogen-io/create-file (cryogen-io/path "/" blog-prefix rss-name)))
(println (blue "generating filtered rss")) (println (blue "generating filtered rss"))
(rss/make-filtered-channels config posts-by-tag) (rss/make-filtered-channels config posts-by-tag)
(println (blue "compiling sass")) (println (blue "compiling sass"))

Loading…
Cancel
Save