Browse Source

title added to the article page + redirect after creation

master
Christian Mueller 14 years ago
parent
commit
fdd9527786
  1. 1
      .gitignore
  2. 13
      src/NoteHub/views/common.clj
  3. 21
      src/NoteHub/views/pages.clj

1
.gitignore vendored

@ -1,3 +1,4 @@ @@ -1,3 +1,4 @@
dump.rdb
resources/
pom.xml
*jar

13
src/NoteHub/views/common.clj

@ -6,6 +6,9 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ @@ -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"

21
src/NoteHub/views/pages.clj

@ -2,7 +2,7 @@ @@ -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 @@ @@ -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 @@ @@ -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))

Loading…
Cancel
Save