From 60b395e0470d8e284b22c8f55d3f30761809744d Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Fri, 30 Dec 2016 23:43:13 +0100 Subject: [PATCH 1/5] added ability to select one page as home-page (add :home? true as meta) instead of newest post. --- .gitignore | 1 + project.clj | 6 ++++-- src/cryogen_core/compiler.clj | 35 +++++++++++++++++++++++++---------- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index d44b519..4c7af5b 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ pom.xml.asc .DS* /.idea/ /cryogen-core.iml +/bin/ diff --git a/project.clj b/project.clj index 1265b13..da3d908 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject cryogen-core "0.1.46" +(defproject org.domaindrivenarchitecture/cryogen-core "0.1.47-SNAPSHOT" :description "Cryogen's compiler" :url "https://github.com/cryogen-project/cryogen-core" :license {:name "Eclipse Public License" @@ -14,4 +14,6 @@ [selmer "1.10.2"] [pandect "0.6.1"] [hawk "0.2.11"] - [clj-tagsoup "0.3.0" :exclusions [org.clojure/clojure]]]) + [clj-tagsoup "0.3.0" :exclusions [org.clojure/clojure]]] + :deploy-repositories [["snapshots" :clojars] + ["releases" :clojars]]) diff --git a/src/cryogen_core/compiler.clj b/src/cryogen_core/compiler.clj index e23f9b6..bdbf9a2 100644 --- a/src/cryogen_core/compiler.clj +++ b/src/cryogen_core/compiler.clj @@ -231,11 +231,13 @@ (create-folder (path "/" blog-prefix page-root-uri)) (doseq [{:keys [uri] :as page} pages] (println "\t-->" (cyan uri)) + (println "\t-->" (cyan page)) (write-html uri params (render-file (str "/html/" (:layout page)) (merge params {:active-page "pages" + :home false :servlet-context (path "/" blog-prefix "/") :page page :uri uri})))))) @@ -248,6 +250,7 @@ (create-folder (path "/" blog-prefix post-root-uri)) (doseq [post posts] (println "\t-->" (cyan (:uri post))) + (println "\t-->" (cyan post)) (write-html (:uri post) params (render-file (str "/html/" (:layout post)) @@ -350,16 +353,21 @@ "Compiles the index page into html and spits it out into the public folder" [{:keys [disqus?] :as params}] (println (blue "compiling index")) - (let [uri (page-uri "index.html" params)] + (let [uri (page-uri "index.html" params) + home-page (-> params :home-page) + meta {:active-page "home" + :home true + :disqus? disqus? + :uri uri + :post home-page + :page home-page}] + (println "\t-->" (cyan meta)) + (println "\t-->" (cyan (first (-> params :latest-posts)))) (write-html uri params - (render-file "/html/home.html" + (render-file (str "/html/" (:layout home-page)) (merge params - {:active-page "home" - :home true - :disqus? disqus? - :post (get-in params [:latest-posts 0]) - :uri uri}))))) + meta))))) (defn compile-archives "Compiles the archives page into html and spits it out into the public folder" @@ -455,17 +463,24 @@ (let [{:keys [^String site-url blog-prefix rss-name recent-posts sass-src sass-dest sass-path compass-path keep-files ignored-files previews? author-root-uri] :as config} (read-config) posts (add-prev-next (read-posts config)) pages (add-prev-next (read-pages config)) - [navbar-pages sidebar-pages] (group-pages pages) + home-pages (filter #(boolean (:home? %)) pages) + pages-without-home (filter #(boolean (not (:home? %))) pages) + [navbar-pages sidebar-pages] (group-pages pages-without-home) posts-by-tag (group-by-tags posts) posts (tag-posts posts config) + latest-posts (->> posts (take recent-posts) vec) params (merge config {:today (java.util.Date.) :title (:site-title config) :active-page "home" :tags (map (partial tag-info config) (keys posts-by-tag)) - :latest-posts (->> posts (take recent-posts) vec) + :latest-posts latest-posts :navbar-pages navbar-pages :sidebar-pages sidebar-pages + :home-page (if (not-empty home-pages) + (first home-pages) + (merge (first latest-posts) + {:layout "home.html"})) :archives-uri (page-uri "archives.html" config) :index-uri (page-uri "index.html" config) :tags-uri (page-uri "tags.html" config) @@ -480,7 +495,7 @@ (println (blue "copying resources")) (copy-resources config) (copy-resources-from-markup-folders config) - (compile-pages params pages) + (compile-pages params pages-without-home) (compile-posts params posts) (compile-tags params posts-by-tag) (compile-tags-page params) From 0e882e6637faa97d52f6599d4b44aa16d71330f9 Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Sat, 31 Dec 2016 10:44:14 +0100 Subject: [PATCH 2/5] gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 4c7af5b..127496b 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ pom.xml.asc /.idea/ /cryogen-core.iml /bin/ +/.classpath +/.project From e796a5adc5e37b9c4c19a52b87e79763cda5a2d3 Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Sat, 31 Dec 2016 11:20:09 +0100 Subject: [PATCH 3/5] added debug switch & improved home vs. preview handling --- src/cryogen_core/compiler.clj | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/cryogen_core/compiler.clj b/src/cryogen_core/compiler.clj index bdbf9a2..2606c1e 100644 --- a/src/cryogen_core/compiler.clj +++ b/src/cryogen_core/compiler.clj @@ -225,13 +225,14 @@ (defn compile-pages "Compiles all the pages into html and spits them out into the public folder" - [{:keys [blog-prefix page-root-uri] :as params} pages] + [{:keys [blog-prefix page-root-uri debug?] :as params} pages] (when-not (empty? pages) (println (blue "compiling pages")) (create-folder (path "/" blog-prefix page-root-uri)) (doseq [{:keys [uri] :as page} pages] (println "\t-->" (cyan uri)) - (println "\t-->" (cyan page)) + (when debug? + (println "\t-->" (cyan page))) (write-html uri params (render-file (str "/html/" (:layout page)) @@ -354,6 +355,7 @@ [{:keys [disqus?] :as params}] (println (blue "compiling index")) (let [uri (page-uri "index.html" params) + debug? (-> params :debug?) home-page (-> params :home-page) meta {:active-page "home" :home true @@ -361,8 +363,8 @@ :uri uri :post home-page :page home-page}] - (println "\t-->" (cyan meta)) - (println "\t-->" (cyan (first (-> params :latest-posts)))) + (when debug? + (println "\t-->" (cyan meta))) (write-html uri params (render-file (str "/html/" (:layout home-page)) @@ -460,7 +462,7 @@ "Generates all the html and copies over resources specified in the config" [] (println (green "compiling assets...")) - (let [{:keys [^String site-url blog-prefix rss-name recent-posts sass-src sass-dest sass-path compass-path keep-files ignored-files previews? author-root-uri] :as config} (read-config) + (let [{:keys [^String site-url blog-prefix rss-name recent-posts sass-src sass-dest sass-path compass-path keep-files ignored-files previews? clean-urls? debug? author-root-uri] :as config} (read-config) posts (add-prev-next (read-posts config)) pages (add-prev-next (read-pages config)) home-pages (filter #(boolean (:home? %)) pages) @@ -499,8 +501,9 @@ (compile-posts params posts) (compile-tags params posts-by-tag) (compile-tags-page params) - (if previews? - (compile-preview-pages params posts) + (when previews? + (compile-preview-pages params posts)) + (when (or (not-empty home-pages) (not previews?)) (compile-index params)) (compile-archives params posts) (when author-root-uri From 173472e9df0364be0952c2f948609bd34b638d3c Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Sat, 31 Dec 2016 11:26:37 +0100 Subject: [PATCH 4/5] prepare pull request --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index da3d908..db647a9 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject org.domaindrivenarchitecture/cryogen-core "0.1.47-SNAPSHOT" +(defproject cryogen-core "0.1.47-SNAPSHOT" :description "Cryogen's compiler" :url "https://github.com/cryogen-project/cryogen-core" :license {:name "Eclipse Public License" From 773ee269b9221d6ac68fd8c9abb8e83a2ebde030 Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Sat, 31 Dec 2016 15:48:52 +0100 Subject: [PATCH 5/5] add some more debug options --- src/cryogen_core/compiler.clj | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cryogen_core/compiler.clj b/src/cryogen_core/compiler.clj index 2606c1e..7858efc 100644 --- a/src/cryogen_core/compiler.clj +++ b/src/cryogen_core/compiler.clj @@ -245,13 +245,15 @@ (defn compile-posts "Compiles all the posts into html and spits them out into the public folder" - [{:keys [blog-prefix post-root-uri disqus-shortname] :as params} posts] + [{:keys [blog-prefix post-root-uri disqus-shortname debug?] :as params} posts] (when-not (empty? posts) (println (blue "compiling posts")) (create-folder (path "/" blog-prefix post-root-uri)) (doseq [post posts] (println "\t-->" (cyan (:uri post))) - (println "\t-->" (cyan post)) + (println "\t-->" (cyan debug?)) + (when debug? + (println "\t-->" (cyan post))) (write-html (:uri post) params (render-file (str "/html/" (:layout post)) @@ -490,6 +492,8 @@ :site-url (if (.endsWith site-url "/") (.substring site-url 0 (dec (count site-url))) site-url) :theme-path (str "file:resources/templates/themes/" (:theme config))})] + (println (blue "debug info")) + (println "\t-->" (cyan navbar)) (set-custom-resource-path! (:theme-path params)) (wipe-public-folder keep-files) (println (blue "copying theme resources"))