From f87a5285ff974e18b84da9f5a5dc017ba1cc74a1 Mon Sep 17 00:00:00 2001 From: Carmen La Date: Sat, 15 Jun 2019 17:36:09 -0400 Subject: [PATCH] (closes #118) relax config schema --- project.clj | 2 +- src/cryogen_core/compiler.clj | 18 ++++++++---------- src/cryogen_core/config.clj | 6 +++++- src/cryogen_core/io.clj | 9 ++++----- src/cryogen_core/schemas.clj | 19 ++++++++++--------- 5 files changed, 28 insertions(+), 26 deletions(-) diff --git a/project.clj b/project.clj index ddb0f4e..bfc47dc 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject cryogen-core "0.2.0" +(defproject cryogen-core "0.2.1" :description "Cryogen's compiler" :url "https://github.com/cryogen-project/cryogen-core" :license {:name "Eclipse Public License" diff --git a/src/cryogen_core/compiler.clj b/src/cryogen_core/compiler.clj index 2fce6ab..1db813c 100644 --- a/src/cryogen_core/compiler.clj +++ b/src/cryogen_core/compiler.clj @@ -129,7 +129,7 @@ (let [date (if (:date page-meta) (.parse (java.text.SimpleDateFormat. (:post-date-format config)) (:date page-meta)) (parse-post-date file-name (:post-date-format config))) - archive-fmt (java.text.SimpleDateFormat. (:archive-group-format config "yyyy MMMM") (Locale/getDefault)) + archive-fmt (java.text.SimpleDateFormat. (:archive-group-format config) (Locale/getDefault)) formatted-group (.format archive-fmt date)] {:date date :formatted-archive-group formatted-group @@ -268,7 +268,7 @@ (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 debug?] :as params} posts] + [{:keys [blog-prefix post-root-uri debug?] :as params} posts] (when-not (empty? posts) (println (blue "compiling posts")) (cryogen-io/create-folder (cryogen-io/path "/" blog-prefix post-root-uri)) @@ -280,11 +280,10 @@ params (render-file (str "/html/" (:layout post)) (merge params - {:active-page "posts" - :selmer/context (cryogen-io/path "/" blog-prefix "/") - :post post - :disqus-shortname disqus-shortname - :uri uri})))))) + {:active-page "posts" + :selmer/context (cryogen-io/path "/" blog-prefix "/") + :post post + :uri uri})))))) (defn compile-tags "Compiles all the tag pages into html and spits them out into the public folder" @@ -383,7 +382,7 @@ (defn compile-index "Compiles the index page into html and spits it out into the public folder" - [{:keys [blog-prefix disqus? debug? home-page] :as params}] + [{:keys [blog-prefix debug? home-page] :as params}] (println (blue "compiling index")) (let [uri (page-uri "index.html" params)] (when debug? @@ -394,7 +393,6 @@ (merge params {:active-page "home" :home true - :disqus? disqus? :selmer/context (cryogen-io/path "/" blog-prefix "/") :uri uri :post home-page @@ -530,7 +528,7 @@ (println (blue "generating main rss")) (->> (rss/make-channel config posts) (cryogen-io/create-file (cryogen-io/path "/" blog-prefix rss-name))) - (println (blue "generating filtered rss")) + (if (:rss-filters config) (println (blue "generating filtered rss"))) (rss/make-filtered-channels config posts-by-tag)))) (defn compile-assets-timed diff --git a/src/cryogen_core/config.clj b/src/cryogen_core/config.clj index 40832fc..3c98a93 100644 --- a/src/cryogen_core/config.clj +++ b/src/cryogen_core/config.clj @@ -24,10 +24,14 @@ (s/validate schemas/Config config) (let [config (-> config (update-in [:tag-root-uri] (fnil identity "")) + (update-in [:public-dest] (fnil identity "public")) + (update-in [:recent-posts] (fnil identity 3)) + (update-in [:archive-group-format] (fnil identity "yyyy MMMM")) (update-in [:sass-src] (fnil identity ["css"])) (update-in [:sass-path] (fnil identity "sass")) (update-in [:compass-path] (fnil identity "compass")) - (update-in [:public-dest] (fnil identity "public")) + (update-in [:posts-per-page] (fnil identity 5)) + (update-in [:blocks-per-preview] (fnil identity 2)) (assoc :page-root-uri (root-uri :page-root-uri config) :post-root-uri (root-uri :post-root-uri config))) check-overlap (fn [dirs] diff --git a/src/cryogen_core/io.clj b/src/cryogen_core/io.clj index bde18bf..92d60f4 100644 --- a/src/cryogen_core/io.clj +++ b/src/cryogen_core/io.clj @@ -18,11 +18,10 @@ (string/join "/") (#(string/replace % #"/+" "/")))) -(defn re-filter [bool-fn re & other-res] - (let [res (conj other-res re)] - (reify java.io.FilenameFilter - (accept [this _ name] - (bool-fn (some #(re-find % name) res)))))) +(defn re-filter [bool-fn & res] + (reify java.io.FilenameFilter + (accept [this _ name] + (bool-fn (some #(re-find % name) res))))) (def match-re-filter (partial re-filter some?)) (def reject-re-filter (partial re-filter nil?)) diff --git a/src/cryogen_core/schemas.clj b/src/cryogen_core/schemas.clj index 1cda2c7..f2eb0c7 100644 --- a/src/cryogen_core/schemas.clj +++ b/src/cryogen_core/schemas.clj @@ -36,29 +36,30 @@ (s/optional-key :page-root-uri) (s/maybe s/Str) (s/optional-key :tag-root-uri) s/Str (s/optional-key :author-root-uri) s/Str + (s/optional-key :public-dest) s/Str :blog-prefix s/Str :rss-name s/Str - :rss-filters [s/Str] - :recent-posts s/Int + (s/optional-key :rss-filters) [s/Str] + (s/optional-key :recent-posts) s/Int :post-date-format s/Str (s/optional-key :archive-group-format) s/Str (s/optional-key :sass-src) [s/Str] (s/optional-key :sass-path) s/Str (s/optional-key :compass-path) s/Str :theme s/Str - :resources [s/Str] - :keep-files [s/Str] - :disqus? s/Bool + (s/optional-key :resources) [s/Str] + (s/optional-key :keep-files) [s/Str] + (s/optional-key :disqus?) s/Bool (s/optional-key :disqus-shortname) s/Str - :ignored-files [s/Regex] - :previews? s/Bool + (s/optional-key :ignored-files) [s/Regex] + (s/optional-key :previews?) s/Bool (s/optional-key :posts-per-page) s/Int (s/optional-key :blocks-per-preview) s/Int :clean-urls (s/enum :trailing-slash :no-trailing-slash :dirty) (s/optional-key :collapse-subdirs?) s/Bool - :hide-future-posts? s/Bool + (s/optional-key :hide-future-posts?) s/Bool (s/optional-key :klipse) Klipse - :debug? s/Bool + (s/optional-key :debug?) s/Bool s/Keyword s/Any})