# HG changeset patch # User Robert McIntyre # Date 1318915298 25200 # Node ID 12573db754376c7e8d3cbfeeb7c9f37f8bbb0e44 # Parent c1a872bbc9f954253c00387e24649c2606bb3f5f added cute error page by dylan. Going to fix index page diff -r c1a872bbc9f9 -r 12573db75437 .hgignore --- a/.hgignore Sun Oct 16 06:51:55 2011 -0700 +++ b/.hgignore Mon Oct 17 22:21:38 2011 -0700 @@ -1,3 +1,4 @@ syntax: glob src* -html* \ No newline at end of file +html/export.html +html/level-0.html \ No newline at end of file diff -r c1a872bbc9f9 -r 12573db75437 html/err.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/html/err.html Mon Oct 17 22:21:38 2011 -0700 @@ -0,0 +1,131 @@ + + + error-daemon@aurellem: + + + + + + + + testsetahslkfashdljkasdfhkljasdhflskadfhlksadfhlkasdfhlkajsdfhlkasdfhlaksdfhlkjadfhalkjsdfhkalsdfhlkj + TESERHKSJLDFHKSJLDF + + + diff -r c1a872bbc9f9 -r 12573db75437 org/index.org --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org/index.org Mon Oct 17 22:21:38 2011 -0700 @@ -0,0 +1,22 @@ +#+title: Our Blog Entries +#+STYLE: +#+INCLUDE: ../templates/level-0.org + +#+begin_HTML + +
+ +
+ +#+end_HTML + + diff -r c1a872bbc9f9 -r 12573db75437 org/level-0.org --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org/level-0.org Mon Oct 17 22:21:38 2011 -0700 @@ -0,0 +1,24 @@ +#+BEGIN_HTML +
+
+ +
+ +

aurellem

+ +
+ +

{{{title}}}

+
Written by {{{author}}}
+ +#+END_HTML + + + diff -r c1a872bbc9f9 -r 12573db75437 org/publish.org --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org/publish.org Mon Oct 17 22:21:38 2011 -0700 @@ -0,0 +1,140 @@ +#+title: Serving a blog using Clojure +#+author: Robert McIntyre +#+MATHJAX: align:"left" mathml:t path:"../MathJax/MathJax.js" +#+STYLE: +#+BEGIN_HTML +

{{{title}}}

+#+END_HTML + + +* Aurellem Export Program +#+srcname: publish +#+begin_src clojure :results silent +(ns aurellem.publish + (:use rlm.ns-rlm)) +(rlm.ns-rlm/ns-clone rlm.light-base) +(import org.htmlcleaner.HtmlCleaner) +(import org.htmlcleaner.TagNode) +(import java.io.File) +(import java.net.URL) +(import org.apache.commons.io.FileUtils) +(use 'clojure.java.io) +(use 'rlm.sanitize-file) +(use 'net.cgrand.enlive-html) +(use 'rlm.pikasemechu) +(require 'rlm.push) +(use 'clojure.contrib.shell-out) + +(declare publish) + + +(defvar *exports* + [(file-str "~/aurellem/src/pokemon/types.html") + (file-str "~/aurellem/src/pokemon/lpsolve.html") + (file-str "~/aurellem/src/abomination/no_parens.html") + (file-str "/home/r/aurellem/src/qm/quandary.html") + (file-str "/home/r/cortex/cortex.html") + (file-str "/home/r/cortex/capture-video.html")] + "The html files which will be exported to the auerllem + website. Listed in the order they will appear on the site + to add more entries to the site, add them here.") + +(defvar *other-files* + [(file-str "/home/r/aurellem/src/MathJax/") + (file-str "/home/r/aurellem/src/css/aurellem.css") + (file-str "/home/r/aurellem/src/js/jquery.min.js") + (file-str "/home/r/aurellem/src/aurellem/err.html") + (file-str "/home/r/cortex/sources/turing.pdf") + (file-str "/home/r/cortex/images/brick-wall-standing.jpg") + (file-str "/home/r/cortex/images/brick-wall-knocked-down.jpg") + (file-str "/home/r/cortex/images/dominos.jpg") + (file-str "/home/r/cortex/images/simple-app.jpg")] + + "other files needed by the website, but which are not posts.") + +(defvar *index* + (file-str "~/aurellem/src/aurellem/index.html") + "this is the main index.html file for the site. It will be updated + with new posts") + +(defvar *site* + (file-str "~/aurellem/site-output") + "the target output directoty for the site's content") + +(defvar *export-base* (file-str "~/")) + +(defn target-file [#^File file] + (file-str + (.replace (.getCanonicalPath file) + (.getCanonicalPath *export-base*) + (.getCanonicalPath *site*)))) + +(defn title [page] + (str (.getText (first (tags-by-name (parse page) "title"))))) + +(defn link [#^File file] + (.replace (.getCanonicalPath (target-file file)) + (.getCanonicalPath *site*) + ".")) + +(defn rsync-string [#^java.io.File file] + (if (.isFile file) + (.getPath file) + (str (.getPath file) "/"))) + +(defn rsync-local [#^File src #^File dst] + (let [parent (.getParentFile dst)] + (if (not (.exists parent)) + ;; rsync won't make parent directories + (sh "mkdir" "-p" (.getCanonicalPath parent)))) + (sw "rsync" "-avz" "--human-readable" (rsync-string src) (.getCanonicalPath dst))) + +(defn cp [#^File src #^File dst] + (if (.isDirectory src) + (FileUtils/copyDirectory src dst) + (FileUtils/copyFile src dst))) + +(defn copy-site-files + "copy all the files in *exports* and *other-files* to the site directory + preserving the folder structure." + [] + (dorun + (for [file (concat *other-files* *exports*)] + (let [source file destination (target-file file)] + (rsync-local source destination))))) + +(deftemplate fill-list *index* [posts] + [:div#posts :ul.post_list :li] + (clone-for [post posts] + (content {:tag :a + :attrs {:href (link post)} + :content [(title post)]}))) + +(defn update-index + "update the index.html post list and write it to the site directory" + [] + (println "Rebuilding index.html") + (FileUtils/writeStringToFile + (file-str "~/aurellem/site-output/index.html") + ;; reverse the list to get reverse chronological order for the site. + (apply str (fill-list *exports*)))) + +(defn publish-local [] + (rlm.rlm-commands/re) + (copy-site-files) + (update-index)) + +(defn publish-web [] + (publish-local) + (rlm.push/push "-u" "-t" "slice")) + + + +#+end_src + + + +#+begin_src clojure :results silent :tangle publish.clj :noweb yes :exports none +<> +#+end_src +