Created
August 22, 2012 12:46
-
-
Save bouzuya/3425273 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns clj-ex-mkd.core | |
| (:require [clojure.java.io :as io] | |
| [net.cgrand.enlive-html :as eh]) | |
| (:import (com.petebevin.markdown MarkdownProcessor))) | |
| (defn markdown-to-html | |
| [markdown] | |
| (-> | |
| (MarkdownProcessor.) | |
| (.markdown markdown))) | |
| (defn load-jekyll-post-file | |
| [post-file] | |
| (let [text (slurp post-file) | |
| [_ yaml content] (re-find #"(?m)(?s)^---\s*(.*?)^---\s*^(.*)" text)] | |
| (reduce (fn [m [_ k v]] (assoc m (keyword k) v)) | |
| {:content (markdown-to-html content)} | |
| (re-seq #"(\w+):\s*(.*)\n" yaml)))) | |
| (def LAYOUT_FILE "./template/layouts/post.html") | |
| (def JEKYLL_POST_FILE "./template/posts/2012-02-16-jekyll.markdown") | |
| (eh/deftemplate post-html (io/file LAYOUT_FILE) | |
| [post] | |
| [:title] (eh/content (:title post)) | |
| [:article :header :h1] (eh/content (:title post)) | |
| [:article :div.post-body] (eh/html-content (:content post))) | |
| (defn -main | |
| [& args] | |
| (let [data (load-jekyll-post-file JEKYLL_POST_FILE) | |
| compiler #(apply str (post-html %))] | |
| (print (compiler data)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment