note title in the storage collision addressed
This commit is contained in:
@@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
(def note "note")
|
(def note "note")
|
||||||
|
|
||||||
|
(def draft "draft")
|
||||||
|
|
||||||
(defn- build-key [[year month day] key]
|
(defn- build-key [[year month day] key]
|
||||||
(print-str year month day key))
|
(print-str year month day key))
|
||||||
|
|
||||||
@@ -13,3 +15,15 @@
|
|||||||
|
|
||||||
(defn get-note [date key]
|
(defn get-note [date key]
|
||||||
(redis/hget db note (build-key date key)))
|
(redis/hget db note (build-key date key)))
|
||||||
|
|
||||||
|
(defn create-draft [key]
|
||||||
|
(redis/hget db draft key))
|
||||||
|
|
||||||
|
(defn delete-draft [key]
|
||||||
|
(redis/hdel db draft key))
|
||||||
|
|
||||||
|
(defn draft-exists? [key]
|
||||||
|
(redis/hexists db draft key))
|
||||||
|
|
||||||
|
(defn note-exists? [date key]
|
||||||
|
(redis/hexists db note (build-key date key)))
|
||||||
|
|||||||
@@ -9,7 +9,9 @@
|
|||||||
[noir.core :only [defpage render]]
|
[noir.core :only [defpage render]]
|
||||||
[noir.statuses]
|
[noir.statuses]
|
||||||
[noir.fetch.remotes])
|
[noir.fetch.remotes])
|
||||||
(:import [org.pegdown PegDownProcessor]))
|
(:import
|
||||||
|
[java.util Calendar]
|
||||||
|
[org.pegdown PegDownProcessor]))
|
||||||
|
|
||||||
; Fix a maximal title length used in the link
|
; Fix a maximal title length used in the link
|
||||||
(def max-title-length 80)
|
(def max-title-length 80)
|
||||||
@@ -52,8 +54,7 @@
|
|||||||
; Note URL
|
; Note URL
|
||||||
(defpage "/:year/:month/:day/:title" {:keys [year month day title]}
|
(defpage "/:year/:month/:day/:title" {:keys [year month day title]}
|
||||||
(let [date [year month day]
|
(let [date [year month day]
|
||||||
key (hash (conj date title))
|
post (get-note date title)
|
||||||
post (get-note date key)
|
|
||||||
title (-?> post (split #"\n") first (sreplace #"[_\*#]" ""))]
|
title (-?> post (split #"\n") first (sreplace #"[_\*#]" ""))]
|
||||||
(if post
|
(if post
|
||||||
(common/layout title
|
(common/layout title
|
||||||
@@ -63,18 +64,15 @@
|
|||||||
|
|
||||||
; New Note Posting
|
; New Note Posting
|
||||||
(defpage [:post "/post-note"] {:keys [draft]}
|
(defpage [:post "/post-note"] {:keys [draft]}
|
||||||
(let [[year month day] (split
|
(let [[year month day] (map #(.get (Calendar/getInstance) %) [Calendar/YEAR Calendar/MONTH Calendar/DAY_OF_MONTH])
|
||||||
(.format
|
|
||||||
(java.text.SimpleDateFormat. "yyyy-MM-dd")
|
|
||||||
(java.util.Date.)) #"-")
|
|
||||||
untrimmed-line (filter #(or (= \- %) (Character/isLetterOrDigit %))
|
untrimmed-line (filter #(or (= \- %) (Character/isLetterOrDigit %))
|
||||||
(-> draft (split #"\n") first (sreplace " " "-") lower-case))
|
(-> draft (split #"\n") first (sreplace " " "-") lower-case))
|
||||||
trim (fn [s] (apply str (drop-while #(= \- %) s)))
|
trim (fn [s] (apply str (drop-while #(= \- %) s)))
|
||||||
title-uncut (-> untrimmed-line trim reverse trim reverse)
|
title-uncut (-> untrimmed-line trim reverse trim reverse)
|
||||||
title (apply str (take max-title-length title-uncut))
|
proposed-title (apply str (take max-title-length title-uncut))
|
||||||
; TODO: deal with collisions!
|
|
||||||
date [year month day]
|
date [year month day]
|
||||||
key (hash (conj date title))]
|
title (first (drop-while #(note-exists? date %) (cons proposed-title
|
||||||
|
(map #(str proposed-title "-" (+ 2 %)) (range)))))]
|
||||||
(do
|
(do
|
||||||
(set-note date key draft)
|
(set-note date title draft)
|
||||||
(redirect (apply str (interpose "/" ["" year month day title]))))))
|
(redirect (apply str (interpose "/" ["" year month day title]))))))
|
||||||
|
|||||||
Reference in New Issue
Block a user