panel with links added
This commit is contained in:
@@ -12,7 +12,16 @@
|
||||
(defn url
|
||||
"Creates a local url from the given substrings"
|
||||
[& 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
|
||||
(defpartial generate-layout
|
||||
|
||||
@@ -82,11 +82,27 @@
|
||||
helvetica-neue
|
||||
(rule "&:hover"
|
||||
: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"
|
||||
:background background
|
||||
:color foreground
|
||||
:margin 0
|
||||
:padding 0)
|
||||
(rule "#stats"
|
||||
(rule "tr"
|
||||
(rule "& > td:first-child"
|
||||
:text-align :right)))
|
||||
(rule "table,tr,td"
|
||||
:margin 0
|
||||
:border :none)
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
[hiccup.form]
|
||||
[ring.util.codec :only [url-encode]]
|
||||
[hiccup.core]
|
||||
[hiccup.util :only [escape-html]]
|
||||
[noir.response :only [redirect status]]
|
||||
[hiccup.element]
|
||||
[noir.response :only [redirect status content-type]]
|
||||
[noir.core :only [defpage render]]
|
||||
[cheshire.core]
|
||||
[noir.statuses])
|
||||
@@ -40,11 +40,17 @@
|
||||
(status code (get-page code)))
|
||||
|
||||
; 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
|
||||
(let [title (-?> md-text (split #"\n") first (sreplace #"[_\*#]" ""))]
|
||||
(layout params title [:article (md-to-html md-text)]))
|
||||
(status 404 (get-page 404))))
|
||||
(layout params title
|
||||
[:article (md-to-html md-text)]
|
||||
(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
|
||||
"Returns today's date"
|
||||
@@ -101,20 +107,21 @@
|
||||
; Displays the note
|
||||
(defpage "/:year/:month/:day/:title" {:keys [year month day title theme header-font text-font] :as params}
|
||||
(wrap
|
||||
title
|
||||
(select-keys params [:theme :header-font :text-font])
|
||||
(get-note [year month day] title)))
|
||||
|
||||
; Provides Markdown of the specified note
|
||||
(defpage "/:year/:month/:day/:title/export" {:keys [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
|
||||
(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)]
|
||||
(if views
|
||||
(layout (get-message :statistics)
|
||||
[:table.helvetica-neue.central-element
|
||||
[:table#stats.helvetica-neue.central-element
|
||||
[:tr
|
||||
[:td (get-message :published)]
|
||||
[:td (interpose "-" [year month day])]]
|
||||
|
||||
Reference in New Issue
Block a user