refactoring
This commit is contained in:
@@ -177,3 +177,6 @@ td {
|
|||||||
border-top: 1px dotted @foreground_halftone;
|
border-top: 1px dotted @foreground_halftone;
|
||||||
padding: 0.3em;
|
padding: 0.3em;
|
||||||
}
|
}
|
||||||
|
.middot {
|
||||||
|
padding: 0.5em;
|
||||||
|
}
|
||||||
+1
-1
@@ -43,7 +43,7 @@
|
|||||||
|
|
||||||
(defn- get-path [noteID & description]
|
(defn- get-path [noteID & description]
|
||||||
(if description
|
(if description
|
||||||
(str "/" (storage/get-short-url noteID))
|
(str domain "/" (storage/get-short-url noteID))
|
||||||
(let [[year month day title] (split noteID #" ")]
|
(let [[year month day title] (split noteID #" ")]
|
||||||
(apply str (interpose "/"
|
(apply str (interpose "/"
|
||||||
[domain year month day (ring.util.codec/url-encode title)])))))
|
[domain year month day (ring.util.codec/url-encode title)])))))
|
||||||
|
|||||||
+31
-50
@@ -24,34 +24,22 @@
|
|||||||
(storage/register-publisher "NoteHub"))
|
(storage/register-publisher "NoteHub"))
|
||||||
|
|
||||||
; Creates the main html layout
|
; Creates the main html layout
|
||||||
(defpartial generate-layout
|
(defpartial layout
|
||||||
[params title & content]
|
[title & content]
|
||||||
; for the sake of security: escape all symbols of the param values
|
(html5
|
||||||
(let [params (into {} (for [[k v] params] [k (escape-html v)]))
|
[:head
|
||||||
theme (:theme params "default")
|
[:title (print-str (get-message :name) "—" title)]
|
||||||
header-font (:header-font params)
|
[:meta {:charset "UTF-8"}]
|
||||||
text-font (:text-font params)]
|
[:link {:rel "stylesheet/less" :type "text/css" :href "/style.less"}]
|
||||||
(html5
|
(html
|
||||||
[:head
|
(include-js "/js/less.js")
|
||||||
[:title (print-str (get-message :name) "—" title)]
|
(include-js "/js/md5.js")
|
||||||
[:meta {:charset "UTF-8"}]
|
(include-js "/js/marked.js")
|
||||||
[:link {:rel "stylesheet/less" :type "text/css" :href "/style.less"}]
|
(include-js "/js/main.js")
|
||||||
(html
|
(include-js "/js/themes.js"))
|
||||||
(include-js "/js/less.js")
|
; google analytics code should appear in prod mode only
|
||||||
(include-js "/js/md5.js")
|
(if-not (dev-mode?) (include-js "/js/google-analytics.js"))]
|
||||||
(include-js "/js/marked.js")
|
[:body {:onload "onLoad()"} content]))
|
||||||
(include-js "/js/main.js")
|
|
||||||
(include-js "/js/themes.js"))
|
|
||||||
; google analytics code should appear in prod mode only
|
|
||||||
(if-not (dev-mode?) (include-js "/js/google-analytics.js"))]
|
|
||||||
[:body {:onload "onLoad()"} content])))
|
|
||||||
|
|
||||||
(defn layout
|
|
||||||
"Generates the main html layout"
|
|
||||||
[& args]
|
|
||||||
(if (map? (first args))
|
|
||||||
(apply generate-layout args)
|
|
||||||
(apply generate-layout {} args)))
|
|
||||||
|
|
||||||
; Sets a custom message for each needed HTTP status.
|
; Sets a custom message for each needed HTTP status.
|
||||||
; The message to be assigned is extracted with a dynamically generated key
|
; The message to be assigned is extracted with a dynamically generated key
|
||||||
@@ -70,26 +58,10 @@
|
|||||||
[& args]
|
[& args]
|
||||||
(apply str (interpose "/" (cons "" (map url-encode args)))))
|
(apply str (interpose "/" (cons "" (map url-encode args)))))
|
||||||
|
|
||||||
; Converts given markdown to html and wraps with the main layout
|
|
||||||
(defn- wrap [short-url params md-text]
|
|
||||||
(when md-text
|
|
||||||
(layout params (api/derive-title md-text)
|
|
||||||
[:article.bottom-space.markdown md-text]
|
|
||||||
(let [links (map #(link-to
|
|
||||||
(if (= :short-url %)
|
|
||||||
(url short-url)
|
|
||||||
(str (params :title) "/" (name %)))
|
|
||||||
(get-message %))
|
|
||||||
[:stats :edit :export :short-url])
|
|
||||||
space (apply str (repeat 4 " "))
|
|
||||||
separator (str space "·" space)
|
|
||||||
links (interpose separator links)]
|
|
||||||
[:div#panel (map identity links)]))))
|
|
||||||
|
|
||||||
; input form for the markdown text with a preview area
|
; input form for the markdown text with a preview area
|
||||||
(defpartial input-form [form-url command fields content passwd-msg]
|
(defpartial input-form [form-url command fields content passwd-msg]
|
||||||
(let [css-class (when (= :publish command) :hidden)]
|
(let [css-class (when (= :publish command) :hidden)]
|
||||||
(layout {:js true} (get-message :new-note)
|
(layout (get-message :new-note)
|
||||||
[:article#preview.markdown " "]
|
[:article#preview.markdown " "]
|
||||||
[:div#dashed-line {:class css-class}]
|
[:div#dashed-line {:class css-class}]
|
||||||
[:div.central-element.helvetica {:style "margin-bottom: 3em"}
|
[:div.central-element.helvetica {:style "margin-bottom: 3em"}
|
||||||
@@ -125,11 +97,20 @@
|
|||||||
[:div.centered.helvetica.markdown (get-message :footer)]))
|
[:div.centered.helvetica.markdown (get-message :footer)]))
|
||||||
|
|
||||||
; Displays the note
|
; Displays the note
|
||||||
(defpage "/:year/:month/:day/:title" {:keys [year month day title theme header-font text-font] :as params}
|
(defpage "/:year/:month/:day/:title" {:keys [year month day title]}
|
||||||
(wrap
|
(let [noteID (api/build-key [year month day] title)]
|
||||||
(storage/create-short-url params)
|
(when (storage/note-exists? noteID)
|
||||||
(select-keys params [:title :theme :header-font :text-font])
|
(let [note (api/get-note noteID)]
|
||||||
(:note (api/get-note (api/build-key [year month day] title)))))
|
(layout (:title note)
|
||||||
|
[:article.bottom-space.markdown (:note note)]
|
||||||
|
(let [links (map #(link-to
|
||||||
|
(if (= :short-url %)
|
||||||
|
(:shortURL note)
|
||||||
|
(str (:longURL note) "/" (name %)))
|
||||||
|
(get-message %))
|
||||||
|
[:stats :edit :export :short-url])
|
||||||
|
links (interpose [:span.middot "·"] links)]
|
||||||
|
[:div#panel (map identity links)]))))))
|
||||||
|
|
||||||
; Provides Markdown of the specified note
|
; Provides Markdown of the specified note
|
||||||
(defpage "/:year/:month/:day/:title/export" {:keys [year month day title]}
|
(defpage "/:year/:month/:day/:title/export" {:keys [year month day title]}
|
||||||
|
|||||||
Reference in New Issue
Block a user