panel with links added
This commit is contained in:
@@ -23,4 +23,7 @@ publish = Publish
|
|||||||
published = Published
|
published = Published
|
||||||
article-views = Article Views
|
article-views = Article Views
|
||||||
statistics = Statistics
|
statistics = Statistics
|
||||||
|
stats = statistics
|
||||||
|
export = export
|
||||||
|
short-url = short url
|
||||||
new-note = New Markdown Note
|
new-note = New Markdown Note
|
||||||
|
|||||||
@@ -12,7 +12,16 @@
|
|||||||
(defn url
|
(defn url
|
||||||
"Creates a local url from the given substrings"
|
"Creates a local url from the given substrings"
|
||||||
[& args]
|
[& args]
|
||||||
(apply str (interpose "/" (cons "" args))))
|
(let [params (last args)
|
||||||
|
params (if (map? params)
|
||||||
|
(apply str
|
||||||
|
(interpose "&"
|
||||||
|
(map #(let [[k v] %] (str k "=" v))
|
||||||
|
(map #(map name %) params)))))
|
||||||
|
args (if params (butlast args) args)
|
||||||
|
params (if params (str "?" params) "")
|
||||||
|
[leading-slash args] (if (= :local (first args)) ["" (rest args)] ["/" args])]
|
||||||
|
(str (apply str leading-slash (interpose "/" args)) (apply str params))))
|
||||||
|
|
||||||
; Creates the main html layout
|
; Creates the main html layout
|
||||||
(defpartial generate-layout
|
(defpartial generate-layout
|
||||||
|
|||||||
@@ -82,11 +82,27 @@
|
|||||||
helvetica-neue
|
helvetica-neue
|
||||||
(rule "&:hover"
|
(rule "&:hover"
|
||||||
:background :#0b2))
|
:background :#0b2))
|
||||||
|
(rule "#panel"
|
||||||
|
helvetica-neue
|
||||||
|
:position :fixed
|
||||||
|
:width (% 100)
|
||||||
|
:border-top [:1px :solid foreground-halftone]
|
||||||
|
:background background-halftone
|
||||||
|
:padding :0.2em
|
||||||
|
:bottom :0px
|
||||||
|
:font-size :0.4em
|
||||||
|
:text-align :center
|
||||||
|
(rule "a"
|
||||||
|
:border :none))
|
||||||
(rule "html, body"
|
(rule "html, body"
|
||||||
:background background
|
:background background
|
||||||
:color foreground
|
:color foreground
|
||||||
:margin 0
|
:margin 0
|
||||||
:padding 0)
|
:padding 0)
|
||||||
|
(rule "#stats"
|
||||||
|
(rule "tr"
|
||||||
|
(rule "& > td:first-child"
|
||||||
|
:text-align :right)))
|
||||||
(rule "table,tr,td"
|
(rule "table,tr,td"
|
||||||
:margin 0
|
:margin 0
|
||||||
:border :none)
|
:border :none)
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
[hiccup.form]
|
[hiccup.form]
|
||||||
[ring.util.codec :only [url-encode]]
|
[ring.util.codec :only [url-encode]]
|
||||||
[hiccup.core]
|
[hiccup.core]
|
||||||
[hiccup.util :only [escape-html]]
|
[hiccup.element]
|
||||||
[noir.response :only [redirect status]]
|
[noir.response :only [redirect status content-type]]
|
||||||
[noir.core :only [defpage render]]
|
[noir.core :only [defpage render]]
|
||||||
[cheshire.core]
|
[cheshire.core]
|
||||||
[noir.statuses])
|
[noir.statuses])
|
||||||
@@ -40,11 +40,17 @@
|
|||||||
(status code (get-page code)))
|
(status code (get-page code)))
|
||||||
|
|
||||||
; Converts given markdown to html and wraps with the main layout
|
; Converts given markdown to html and wraps with the main layout
|
||||||
(defn- wrap [params md-text]
|
(defn- wrap [title params md-text]
|
||||||
(if md-text
|
(if md-text
|
||||||
(let [title (-?> md-text (split #"\n") first (sreplace #"[_\*#]" ""))]
|
(layout params title
|
||||||
(layout params title [:article (md-to-html md-text)]))
|
[:article (md-to-html md-text)]
|
||||||
(status 404 (get-page 404))))
|
(let [links (map #(link-to (url :local (str title "/" (name %)) params) (get-message %))
|
||||||
|
[:stats :export :short-url])
|
||||||
|
space (apply str (repeat 4 " "))
|
||||||
|
separator (str space "·" space)
|
||||||
|
links (interpose separator links)]
|
||||||
|
[:div#panel (map identity links)]))
|
||||||
|
(status 404 (get-page 404))))
|
||||||
|
|
||||||
(defn get-date
|
(defn get-date
|
||||||
"Returns today's date"
|
"Returns today's date"
|
||||||
@@ -101,20 +107,21 @@
|
|||||||
; 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 theme header-font text-font] :as params}
|
||||||
(wrap
|
(wrap
|
||||||
|
title
|
||||||
(select-keys params [:theme :header-font :text-font])
|
(select-keys params [:theme :header-font :text-font])
|
||||||
(get-note [year month day] title)))
|
(get-note [year month day] title)))
|
||||||
|
|
||||||
; 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]}
|
||||||
(let [md-text (get-note [year month day] title)]
|
(let [md-text (get-note [year month day] title)]
|
||||||
(if md-text md-text (response 404))))
|
(if md-text (content-type "text/plain; charset=utf-8" md-text) (response 404))))
|
||||||
|
|
||||||
; Provides the number of views of the specified note
|
; Provides the number of views of the specified note
|
||||||
(defpage "/:year/:month/:day/:title/stat" {:keys [year month day title]}
|
(defpage "/:year/:month/:day/:title/stats" {:keys [year month day title]}
|
||||||
(let [views (get-note-views [year month day] title)]
|
(let [views (get-note-views [year month day] title)]
|
||||||
(if views
|
(if views
|
||||||
(layout (get-message :statistics)
|
(layout (get-message :statistics)
|
||||||
[:table.helvetica-neue.central-element
|
[:table#stats.helvetica-neue.central-element
|
||||||
[:tr
|
[:tr
|
||||||
[:td (get-message :published)]
|
[:td (get-message :published)]
|
||||||
[:td (interpose "-" [year month day])]]
|
[:td (interpose "-" [year month day])]]
|
||||||
|
|||||||
@@ -20,6 +20,14 @@
|
|||||||
|
|
||||||
(is (= (url 2010 05 06 "test-title" "export") "/2010/5/6/test-title/export"))
|
(is (= (url 2010 05 06 "test-title" "export") "/2010/5/6/test-title/export"))
|
||||||
|
|
||||||
|
(is (= (url 2010 05 06 "test-title" "export" {"theme" "dark"}) "/2010/5/6/test-title/export?theme=dark"))
|
||||||
|
|
||||||
|
(is (= (url 2010 05 06 "test-title" "export" {:theme "dark"}) "/2010/5/6/test-title/export?theme=dark"))
|
||||||
|
|
||||||
|
(is (= (url 2010 05 06 "test-title" "export" {:theme :dark}) "/2010/5/6/test-title/export?theme=dark"))
|
||||||
|
|
||||||
|
(is (= (url :local 2010 05 06 "test-title" "export" {:theme :dark}) "2010/5/6/test-title/export?theme=dark"))
|
||||||
|
|
||||||
(deftest testing-fixture
|
(deftest testing-fixture
|
||||||
(testing "Was a not created?"
|
(testing "Was a not created?"
|
||||||
(is (= (get-note date test-title) test-note))
|
(is (= (get-note date test-title) test-note))
|
||||||
|
|||||||
Reference in New Issue
Block a user