From 2ac22152abc89357e8c09945710ecaa44a2f9a0e Mon Sep 17 00:00:00 2001 From: "Stefan Pfeiffer, DL1ELY" Date: Fri, 28 Nov 2014 17:15:23 +0100 Subject: [PATCH] Allows for keeping files in public dir when generating Allows to give a list of files and dirs in config.edn that are not wiped from the resources/public directory on generating This allows for having a persistent .git directory in public that can be used to push the generated files to pages.github.com --- README.md | 3 +++ src/leiningen/new/cryogen/config.edn | 1 + src/leiningen/new/cryogen/md/posts/13-11-2014-docs.md | 2 ++ src/leiningen/new/cryogen/src/cryogen/compiler.clj | 7 ++++--- src/leiningen/new/cryogen/src/cryogen/io.clj | 7 ++++--- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e3e35e6..2cd5704 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ The site configuration file is found at `templates/config.edn`, this file looks :sass-src nil :sass-dest nil :resources ["css" "js" "img"] + :keep-files [".git"] :disqus? false :disqus-shortname ""} ``` @@ -78,6 +79,7 @@ The site configuration file is found at `templates/config.edn`, this file looks into. defaults to "css" - be sure to include this directory in your `resources` section * `resources` - list of folders to be copied over from `templates` to `public` + * `keep-files` - list of folders or files that are not wiped in the `public` directory. For example, this allows to keep a `.git` directory there across recompiles of the site to versionize the generated files * `disqus?` - set to true if you want disqus enabled on your site * `disqus-shortname` - your disqus shortname @@ -187,6 +189,7 @@ folder for a server sugh as Nginx or Apache and your site is now ready for servi * [My personal blog](http://carmenla.me/blog/index.html) * [Yogthos blog](http://yogthos.net/) * [Clojure :in Tunisia](http://www.clojure.tn) +* [dl1ely.github.io](http://dl1ely.github.io) ## License diff --git a/src/leiningen/new/cryogen/config.edn b/src/leiningen/new/cryogen/config.edn index ee551b4..3f68eda 100755 --- a/src/leiningen/new/cryogen/config.edn +++ b/src/leiningen/new/cryogen/config.edn @@ -12,5 +12,6 @@ :sass-src nil :sass-dest nil :resources ["css" "js" "img"] + :keep-files [".git"] :disqus? false :disqus-shortname ""} diff --git a/src/leiningen/new/cryogen/md/posts/13-11-2014-docs.md b/src/leiningen/new/cryogen/md/posts/13-11-2014-docs.md index 2e05889..c737fc7 100644 --- a/src/leiningen/new/cryogen/md/posts/13-11-2014-docs.md +++ b/src/leiningen/new/cryogen/md/posts/13-11-2014-docs.md @@ -56,6 +56,7 @@ The site configuration file is found at `templates/config.edn`, this file looks :sass-src nil :sass-dest nil :resources ["css" "js" "img"] + :keep-files [".git"] :disqus? false :disqus-shortname ""} ``` @@ -75,6 +76,7 @@ The site configuration file is found at `templates/config.edn`, this file looks into. defaults to "css" - be sure to include this directory in your `resources` section * `resources` - list of folders to be copied over from `templates` to `public` + * `keep-files` - list of folders or files that are not wiped in the `public` directory. For example, this allows to keep a `.git` directory there across recompiles of the site to versionize the generated files * `disqus?` - set to true if you want disqus enabled on your site * `disqus-shortname` - your disqus shortname diff --git a/src/leiningen/new/cryogen/src/cryogen/compiler.clj b/src/leiningen/new/cryogen/src/cryogen/compiler.clj index b04192f..af2e6bd 100755 --- a/src/leiningen/new/cryogen/src/cryogen/compiler.clj +++ b/src/leiningen/new/cryogen/src/cryogen/compiler.clj @@ -188,7 +188,8 @@ (update-in [:rss-name] (fnil str "rss.xml")) (update-in [:sass-src] (fnil str "css")) (update-in [:sass-dest] (fnil str "css")) - (update-in [:post-date-format] (fnil str "yyyy-MM-dd")))] + (update-in [:post-date-format] (fnil str "yyyy-MM-dd")) + (update-in [:keep-files] (fnil seq [])))] (merge config {:page-root (root-path :page-root config) @@ -197,7 +198,7 @@ (defn compile-assets [] (println (green "compiling assets...")) - (let [{:keys [site-url blog-prefix rss-name recent-posts sass-src sass-dest] :as config} (read-config) + (let [{:keys [site-url blog-prefix rss-name recent-posts sass-src sass-dest keep-files] :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) @@ -212,7 +213,7 @@ :index-uri (str blog-prefix "/index.html") :rss-uri (str blog-prefix "/" rss-name)}] - (wipe-public-folder) + (wipe-public-folder keep-files) (println (blue "copying resources")) (copy-resources config) (compile-pages default-params pages config) diff --git a/src/leiningen/new/cryogen/src/cryogen/io.clj b/src/leiningen/new/cryogen/src/cryogen/io.clj index 612f113..0735166 100755 --- a/src/leiningen/new/cryogen/src/cryogen/io.clj +++ b/src/leiningen/new/cryogen/src/cryogen/io.clj @@ -21,9 +21,10 @@ (when-not (.exists loc) (.mkdirs loc)))) -(defn wipe-public-folder [] - (doseq [path (.listFiles (file public))] - (fs/delete-dir path))) +(defn wipe-public-folder [keep-files] + (let [filenamefilter (reify java.io.FilenameFilter (accept [this _ filename] (not (some #{filename} keep-files))))] + (doseq [path (.listFiles (file public) filenamefilter)] + (fs/delete-dir path)))) (defn copy-resources [{:keys [blog-prefix resources]}] (doseq [resource resources]