Mercurial > aurellem
view org/publish.org @ 16:e1e03c6399f5
fixed descriptive list css
author | Dylan Holmes <ocsenave@gmail.com> |
---|---|
date | Tue, 01 Nov 2011 02:40:21 -0500 |
parents | 12573db75437 |
children | 3186b6b76cde |
line wrap: on
line source
1 #+title: Serving a blog using Clojure2 #+author: Robert McIntyre3 #+MATHJAX: align:"left" mathml:t path:"../MathJax/MathJax.js"4 #+STYLE: <link rel="stylesheet" type="text/css" href="../css/aurellem.css" />5 #+BEGIN_HTML6 <h1>{{{title}}}</h1>7 #+END_HTML10 * Aurellem Export Program11 #+srcname: publish12 #+begin_src clojure :results silent13 (ns aurellem.publish14 (:use rlm.ns-rlm))15 (rlm.ns-rlm/ns-clone rlm.light-base)16 (import org.htmlcleaner.HtmlCleaner)17 (import org.htmlcleaner.TagNode)18 (import java.io.File)19 (import java.net.URL)20 (import org.apache.commons.io.FileUtils)21 (use 'clojure.java.io)22 (use 'rlm.sanitize-file)23 (use 'net.cgrand.enlive-html)24 (use 'rlm.pikasemechu)25 (require 'rlm.push)26 (use 'clojure.contrib.shell-out)28 (declare publish)31 (defvar *exports*32 [(file-str "~/aurellem/src/pokemon/types.html")33 (file-str "~/aurellem/src/pokemon/lpsolve.html")34 (file-str "~/aurellem/src/abomination/no_parens.html")35 (file-str "/home/r/aurellem/src/qm/quandary.html")36 (file-str "/home/r/cortex/cortex.html")37 (file-str "/home/r/cortex/capture-video.html")]38 "The html files which will be exported to the auerllem39 website. Listed in the order they will appear on the site40 to add more entries to the site, add them here.")42 (defvar *other-files*43 [(file-str "/home/r/aurellem/src/MathJax/")44 (file-str "/home/r/aurellem/src/css/aurellem.css")45 (file-str "/home/r/aurellem/src/js/jquery.min.js")46 (file-str "/home/r/aurellem/src/aurellem/err.html")47 (file-str "/home/r/cortex/sources/turing.pdf")48 (file-str "/home/r/cortex/images/brick-wall-standing.jpg")49 (file-str "/home/r/cortex/images/brick-wall-knocked-down.jpg")50 (file-str "/home/r/cortex/images/dominos.jpg")51 (file-str "/home/r/cortex/images/simple-app.jpg")]53 "other files needed by the website, but which are not posts.")55 (defvar *index*56 (file-str "~/aurellem/src/aurellem/index.html")57 "this is the main index.html file for the site. It will be updated58 with new posts")60 (defvar *site*61 (file-str "~/aurellem/site-output")62 "the target output directoty for the site's content")64 (defvar *export-base* (file-str "~/"))66 (defn target-file [#^File file]67 (file-str68 (.replace (.getCanonicalPath file)69 (.getCanonicalPath *export-base*)70 (.getCanonicalPath *site*))))72 (defn title [page]73 (str (.getText (first (tags-by-name (parse page) "title")))))75 (defn link [#^File file]76 (.replace (.getCanonicalPath (target-file file))77 (.getCanonicalPath *site*)78 "."))80 (defn rsync-string [#^java.io.File file]81 (if (.isFile file)82 (.getPath file)83 (str (.getPath file) "/")))85 (defn rsync-local [#^File src #^File dst]86 (let [parent (.getParentFile dst)]87 (if (not (.exists parent))88 ;; rsync won't make parent directories89 (sh "mkdir" "-p" (.getCanonicalPath parent))))90 (sw "rsync" "-avz" "--human-readable" (rsync-string src) (.getCanonicalPath dst)))92 (defn cp [#^File src #^File dst]93 (if (.isDirectory src)94 (FileUtils/copyDirectory src dst)95 (FileUtils/copyFile src dst)))97 (defn copy-site-files98 "copy all the files in *exports* and *other-files* to the site directory99 preserving the folder structure."100 []101 (dorun102 (for [file (concat *other-files* *exports*)]103 (let [source file destination (target-file file)]104 (rsync-local source destination)))))106 (deftemplate fill-list *index* [posts]107 [:div#posts :ul.post_list :li]108 (clone-for [post posts]109 (content {:tag :a110 :attrs {:href (link post)}111 :content [(title post)]})))113 (defn update-index114 "update the index.html post list and write it to the site directory"115 []116 (println "Rebuilding index.html")117 (FileUtils/writeStringToFile118 (file-str "~/aurellem/site-output/index.html")119 ;; reverse the list to get reverse chronological order for the site.120 (apply str (fill-list *exports*))))122 (defn publish-local []123 (rlm.rlm-commands/re)124 (copy-site-files)125 (update-index))127 (defn publish-web []128 (publish-local)129 (rlm.push/push "-u" "-t" "slice"))133 #+end_src137 #+begin_src clojure :results silent :tangle publish.clj :noweb yes :exports none138 <<publish>>139 #+end_src