From fdd9527786cbb652acebc0e5b39e54647b80a4bc Mon Sep 17 00:00:00 2001 From: Christian Mueller Date: Mon, 28 May 2012 22:18:16 +0200 Subject: [PATCH] title added to the article page + redirect after creation --- .gitignore | 1 + src/NoteHub/views/common.clj | 13 ++++++------- src/NoteHub/views/pages.clj | 21 +++++++++++++-------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index e8375ac..139c51d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +dump.rdb resources/ pom.xml *jar diff --git a/src/NoteHub/views/common.clj b/src/NoteHub/views/common.clj index bcd9b6a..0b5415e 100644 --- a/src/NoteHub/views/common.clj +++ b/src/NoteHub/views/common.clj @@ -6,6 +6,9 @@ [hiccup.element :only [javascript-tag]])) (defn gen-comma-list [& fonts] (apply str (interpose "," fonts))) +(def page-width + (mixin + :width :900px)) (def helvetica-neue (mixin :font-weight 300 @@ -17,8 +20,6 @@ (def global-css (css - (rule ".centerized" - :text-align :center) (rule ".landing-button" :box-shadow [0 :2px :5px :#aaa] :text-decoration :none @@ -41,9 +42,6 @@ :text-align :center (rule "h2" helvetica-neue)) - (rule ".article-font" - :font-family :Georgia - :font-size :1.3em) (rule "article" :font-family :Georgia :font-size :1.2em @@ -58,10 +56,11 @@ (rule "*:focus" :outline [:0px :none :transparent]) (rule "textarea" - :width "900px" + page-width :font-family :Courier :font-size :1.2em :border :none + ; TODO: make this dynamic :height :600px :margin-bottom :2em) (rule ".hidden" @@ -75,7 +74,7 @@ :font-size :1em :background :white) (rule ".central-body" - :width "900px" + page-width :margin-top :5em :margin-bottom :10em :margin-left "auto" diff --git a/src/NoteHub/views/pages.clj b/src/NoteHub/views/pages.clj index e4450fa..f048b13 100644 --- a/src/NoteHub/views/pages.clj +++ b/src/NoteHub/views/pages.clj @@ -2,7 +2,7 @@ (:require [NoteHub.views.common :as common] [digest :as digest]) (:use [NoteHub.storage :rename {get s-get set s-set} :only [set get]] - [noir.response :only [content-type]] + [noir.response :only [redirect]] [clojure.string :rename {replace sreplace} :only [split replace lower-case]] [noir.core :only [defpage render]] [hiccup.form] @@ -30,11 +30,17 @@ [:div#preview-start] [:article#preview.central-body])) +(defn get-storage-key [year month day title] + (str "note-" (digest/md5 (str year month day title)))) + (defpage "/:year/:month/:day/:title" {:keys [year month day title]} - (let [key (str "note-" (digest/md5 (str year month day title)))] - (common/layout "TEST" + (let [key (get-storage-key year month day title) + post (s-get key) + title (sreplace (-> post (split #"\n") first) #"[_\*#]" "")] + (common/layout title [:article.central-body - (md-to-html (s-get key))]))) + ; TODO: deal with 404! + (md-to-html post)]))) (defpage [:post "/post-note"] {:keys [draft]} (let [[year month day] (split (.format (java.text.SimpleDateFormat. "yyyy-MM-dd") (java.util.Date.)) #"-") @@ -43,12 +49,11 @@ 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)))] + ; TODO: deal with collisions! + key (get-storage-key year month day title)] (do (s-set key draft) - (render "/:year/:month/:day/:title" {:year year :month month :day day :title title})))) - -; Actions. + (redirect (apply str (interpose "/" ["" year month day title])))))) (defremote md-to-html [draft] (.markdownToHtml (PegDownProcessor.) draft))