persistence to redis implemented
This commit is contained in:
@@ -5,6 +5,8 @@
|
|||||||
[cssgen "0.2.6"]
|
[cssgen "0.2.6"]
|
||||||
[jayq "0.1.0-alpha2"]
|
[jayq "0.1.0-alpha2"]
|
||||||
[fetch "0.1.0-alpha2"]
|
[fetch "0.1.0-alpha2"]
|
||||||
|
[clj-redis "0.0.12"]
|
||||||
|
[digest "1.4.0"]
|
||||||
[org.pegdown/pegdown "1.1.0"]
|
[org.pegdown/pegdown "1.1.0"]
|
||||||
[noir "1.3.0-beta1"]]
|
[noir "1.3.0-beta1"]]
|
||||||
:plugins [[lein-cljsbuild "0.1.10"]]
|
:plugins [[lein-cljsbuild "0.1.10"]]
|
||||||
|
|||||||
+1
-1
@@ -29,4 +29,4 @@
|
|||||||
(do
|
(do
|
||||||
(fm/remote (md-to-html (val $draft)) [result]
|
(fm/remote (md-to-html (val $draft)) [result]
|
||||||
(inner $preview result)
|
(inner $preview result)
|
||||||
(scroll-to $preview)))))
|
(scroll-to ($ :#preview-start))))))
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
(ns NoteHub.storage
|
||||||
|
(:refer-clojure :exclude (set get))
|
||||||
|
(:require [clj-redis.client :as redis]))
|
||||||
|
|
||||||
|
(def db (redis/init))
|
||||||
|
|
||||||
|
(defn set [k v]
|
||||||
|
(redis/set db k v))
|
||||||
|
|
||||||
|
(defn get [k]
|
||||||
|
(redis/get db k))
|
||||||
@@ -51,8 +51,9 @@
|
|||||||
:text-align :center
|
:text-align :center
|
||||||
:margin :2em))
|
:margin :2em))
|
||||||
(rule "pre"
|
(rule "pre"
|
||||||
|
:border-radius :3px
|
||||||
:padding :1em
|
:padding :1em
|
||||||
:border [:1px :dashed :gray]
|
:border [:1px :dotted :gray]
|
||||||
:background :#efefef)
|
:background :#efefef)
|
||||||
(rule "*:focus"
|
(rule "*:focus"
|
||||||
:outline [:0px :none :transparent])
|
:outline [:0px :none :transparent])
|
||||||
@@ -66,10 +67,11 @@
|
|||||||
(rule ".hidden"
|
(rule ".hidden"
|
||||||
:display :none)
|
:display :none)
|
||||||
(rule ".button"
|
(rule ".button"
|
||||||
|
:border-radius :3px
|
||||||
helvetica-neue
|
helvetica-neue
|
||||||
:cursor :pointer
|
:cursor :pointer
|
||||||
:border [:1px :solid]
|
:border [:1px :solid]
|
||||||
:opacity 0.7
|
:opacity 0.8
|
||||||
:font-size :1em
|
:font-size :1em
|
||||||
:background :white)
|
:background :white)
|
||||||
(rule ".central-body"
|
(rule ".central-body"
|
||||||
@@ -82,7 +84,7 @@
|
|||||||
:font-size :2em)
|
:font-size :2em)
|
||||||
(rule "#preview-start"
|
(rule "#preview-start"
|
||||||
:border-bottom [:1px :dashed :gray]
|
:border-bottom [:1px :dashed :gray]
|
||||||
:margin-bottom :10em)
|
:margin-bottom :5em)
|
||||||
(rule "h1, h2, h3, h4"
|
(rule "h1, h2, h3, h4"
|
||||||
:font-family (gen-comma-list
|
:font-family (gen-comma-list
|
||||||
"'Noticia Text'" "Georgia"))))
|
"'Noticia Text'" "Georgia"))))
|
||||||
|
|||||||
@@ -1,26 +1,28 @@
|
|||||||
(ns NoteHub.views.pages
|
(ns NoteHub.views.pages
|
||||||
(:require [NoteHub.views.common :as common])
|
(:require [NoteHub.views.common :as common] [digest :as digest])
|
||||||
(:use
|
(:use
|
||||||
|
[NoteHub.storage :rename {get s-get set s-set} :only [set get]]
|
||||||
[noir.response :only [content-type]]
|
[noir.response :only [content-type]]
|
||||||
[clojure.string :rename {replace sreplace} :only [trim split replace]]
|
[clojure.string :rename {replace sreplace} :only [split replace lower-case]]
|
||||||
[noir.core :only [defpage]]
|
[noir.core :only [defpage render]]
|
||||||
[hiccup.form]
|
[hiccup.form]
|
||||||
[noir.fetch.remotes])
|
[noir.fetch.remotes])
|
||||||
(:import [org.pegdown PegDownProcessor]))
|
(:import [org.pegdown PegDownProcessor]))
|
||||||
|
|
||||||
|
(def max-title-length 80)
|
||||||
|
|
||||||
(defpage "/" {}
|
(defpage "/" {}
|
||||||
(common/layout "Free Markdown Hosting"
|
(common/layout "Free Markdown Hosting"
|
||||||
[:div#hero
|
[:div#hero
|
||||||
[:h1 "NoteHub"]
|
[:h1 "NoteHub"]
|
||||||
[:h2 "Free hosting for markdown pages."]
|
[:h2 "Free hosting for markdown pages."]
|
||||||
[:br]
|
[:br]
|
||||||
[:br]
|
|
||||||
[:a.landing-button {:href "/new"} "New Page"]]))
|
[:a.landing-button {:href "/new"} "New Page"]]))
|
||||||
|
|
||||||
(defpage "/new" {}
|
(defpage "/new" {}
|
||||||
(common/layout "New Markdown Note"
|
(common/layout "New Markdown Note"
|
||||||
[:div.central-body
|
[:div.central-body
|
||||||
(form-to [:get "/preview-note"]
|
(form-to [:post "/post-note"]
|
||||||
(text-area {:class "max-width"} :draft)
|
(text-area {:class "max-width"} :draft)
|
||||||
[:div#buttons.hidden
|
[:div#buttons.hidden
|
||||||
(submit-button {:style "float: left" :class "button"} "Publish")
|
(submit-button {:style "float: left" :class "button"} "Publish")
|
||||||
@@ -28,6 +30,24 @@
|
|||||||
[:div#preview-start]
|
[:div#preview-start]
|
||||||
[:article#preview.central-body]))
|
[:article#preview.central-body]))
|
||||||
|
|
||||||
|
(defpage "/:year/:month/:day/:title" {:keys [year month day title]}
|
||||||
|
(let [key (str "note-" (digest/md5 (str year month day title)))]
|
||||||
|
(common/layout "TEST"
|
||||||
|
[:article.central-body
|
||||||
|
(md-to-html (s-get key))])))
|
||||||
|
|
||||||
|
(defpage [:post "/post-note"] {:keys [draft]}
|
||||||
|
(let [[year month day] (split (.format (java.text.SimpleDateFormat. "yyyy-MM-dd") (java.util.Date.)) #"-")
|
||||||
|
untrimmed-line (filter #(or (= \- %) (Character/isLetterOrDigit %))
|
||||||
|
(-> draft (split #"\n") first (sreplace " " "-") lower-case))
|
||||||
|
trim (fn [s] (apply str (drop-while #(= \- %) s)))
|
||||||
|
title-uncut (-> untrimmed-line trim reverse trim reverse)
|
||||||
|
title (apply str (take max-title-length title-uncut))
|
||||||
|
key (str "note-" (digest/md5 (str year month day title)))]
|
||||||
|
(do
|
||||||
|
(s-set key draft)
|
||||||
|
(render "/:year/:month/:day/:title" {:year year :month month :day day :title title}))))
|
||||||
|
|
||||||
; Actions.
|
; Actions.
|
||||||
|
|
||||||
(defremote md-to-html [draft]
|
(defremote md-to-html [draft]
|
||||||
|
|||||||
Reference in New Issue
Block a user