Skip to content

Instantly share code, notes, and snippets.

@Tyler-Anderson
Created September 19, 2013 00:07
Show Gist options
  • Save Tyler-Anderson/6617511 to your computer and use it in GitHub Desktop.
Save Tyler-Anderson/6617511 to your computer and use it in GitHub Desktop.
(ns intaglio.core
(:require [net.cgrand.enlive-html :as html]
[cheshire.core :refer :all]
[markdown.core :as md])
(:import
(java.util Date UUID)
(java.io.StringReader)))
(use 'clojure.pprint)
(def config-atom (atom (parse-string (slurp "config.json") true)))
(defn log-config []
(spit "config-log.json" (generate-string @config-atom) :append true))
(defn write-config []
(spit "config.json" (generate-string @config-atom))
(log-config))
(def test-post (parse-string (slurp "testparse.json" ) true))
(defn inc-post []
(swap! config-atom update-in [:total-posts] inc))
(defn write-post [post]
(inc-post)
(def file-name (str (@config-atom :directory) "/entry-" (@config-atom :total-posts) ".md"))
(spit file-name (post :markdown))
(write-config)
file-name)
(defn format-post [post]
(dissoc (assoc post
:file (write-post post)
:date (Date. )
:timestamp (System/currentTimeMillis)
:uuid (str (java.util.UUID/randomUUID))
:edited (Date. )) :markdown))
(defn append-posts-file [formatted-post]
(spit (@config-atom :posts-file)
(generate-string
(conj (parse-string (slurp (@config-atom :posts-file)))
{:entry-num (@config-atom :total-posts)
:entry formatted-post}) {:date-format "MM-dd-yyyy-H-m"})))
(defn post-html [{file :file}]
(md/md-to-html-string (slurp file)))
(post-html {:file "posts/entry-9.md"})
(pprint (partition-all (@config-atom :per-page)
(reverse (sort-by :entry-num (parse-string (slurp "posts.json") true)))))
(append-posts-file (format-post test-post))
(html/deftemplate main-template "templates/skeleton.html"
[]
[:id#master] (html/content ()))
(html/defsnippet post-snippet "templates/post.html"
[:div.row]
[post-md]
[:div] (html/content post-md))
(defn html->enlive
[html]
(html/html-resource (StringReader. html)))
(spit "test.html" (str (html/emit* (post-snippet (slurp "posts/somepost.html")))))
(def postys (html/html-resource "templates/post.html"))
(pprint postys)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment