|
|
|
@ -37,7 +37,7 @@ |
|
|
|
(include-js "/js/main.js") |
|
|
|
(include-js "/js/main.js") |
|
|
|
(include-js "/js/themes.js")) |
|
|
|
(include-js "/js/themes.js")) |
|
|
|
; google analytics code should appear in prod mode only |
|
|
|
; google analytics code should appear in prod mode only |
|
|
|
(if-not (get-setting :dev-mode?) (include-js "/js/google-analytics.js"))] |
|
|
|
(if-not (get-setting :dev-mode) (include-js "/js/google-analytics.js"))] |
|
|
|
[:body {:onload "onLoad()"} content])) |
|
|
|
[:body {:onload "onLoad()"} content])) |
|
|
|
|
|
|
|
|
|
|
|
; Sets a custom message for each needed HTTP status. |
|
|
|
; Sets a custom message for each needed HTTP status. |
|
|
|
@ -48,8 +48,9 @@ |
|
|
|
(layout message |
|
|
|
(layout message |
|
|
|
[:article [:h1 message]])))) |
|
|
|
[:article [:h1 message]])))) |
|
|
|
|
|
|
|
|
|
|
|
; shortcut for rendering an HTTP status |
|
|
|
(defn- response |
|
|
|
(defn- response [code] |
|
|
|
"shortcut for rendering an HTTP status" |
|
|
|
|
|
|
|
[code] |
|
|
|
(status code (get-page code))) |
|
|
|
(status code (get-page code))) |
|
|
|
|
|
|
|
|
|
|
|
(defn url |
|
|
|
(defn url |
|
|
|
@ -61,7 +62,7 @@ |
|
|
|
(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 (get-message :new-note) |
|
|
|
(layout (get-message :new-note) |
|
|
|
[:article#preview.markdown " "] |
|
|
|
[:article#preview ""] |
|
|
|
[: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"} |
|
|
|
(form-to {:autocomplete :off} [:post form-url] |
|
|
|
(form-to {:autocomplete :off} [:post form-url] |
|
|
|
@ -79,10 +80,17 @@ |
|
|
|
(defn generate-session [] |
|
|
|
(defn generate-session [] |
|
|
|
(encrypt (str (rand-int Integer/MAX_VALUE)))) |
|
|
|
(encrypt (str (rand-int Integer/MAX_VALUE)))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defn md-node |
|
|
|
|
|
|
|
"Returns an HTML element with a textarea inside |
|
|
|
|
|
|
|
containing the markdown text (to keep all chars unescaped)" |
|
|
|
|
|
|
|
([cls input] (md-node cls {} input)) |
|
|
|
|
|
|
|
([cls opts input] |
|
|
|
|
|
|
|
[(keyword (str (name cls) ".markdown")) opts |
|
|
|
|
|
|
|
[:textarea input]])) |
|
|
|
|
|
|
|
|
|
|
|
; Routes |
|
|
|
; Routes |
|
|
|
; ====== |
|
|
|
; ====== |
|
|
|
|
|
|
|
|
|
|
|
; Landing Page |
|
|
|
|
|
|
|
(defpage "/" {} |
|
|
|
(defpage "/" {} |
|
|
|
(layout (get-message :page-title) |
|
|
|
(layout (get-message :page-title) |
|
|
|
[:div#hero |
|
|
|
[:div#hero |
|
|
|
@ -91,17 +99,17 @@ |
|
|
|
[:br] |
|
|
|
[:br] |
|
|
|
[:a.landing-button {:href "/new" :style "color: white"} (get-message :new-page)]] |
|
|
|
[:a.landing-button {:href "/new" :style "color: white"} (get-message :new-page)]] |
|
|
|
[:div#dashed-line] |
|
|
|
[:div#dashed-line] |
|
|
|
[:article.helvetica.bottom-space.markdown {:style "font-size: 1em"} |
|
|
|
(md-node :article.helvetica.bottom-space |
|
|
|
(slurp "LANDING.md")] |
|
|
|
{:style "font-size: 1em"} |
|
|
|
[:div.centered.helvetica.markdown (get-message :footer)])) |
|
|
|
(slurp "LANDING.md")) |
|
|
|
|
|
|
|
(md-node :div.centered.helvetica (get-message :footer)))) |
|
|
|
|
|
|
|
|
|
|
|
; Displays the note |
|
|
|
|
|
|
|
(defpage "/:year/:month/:day/:title" {:keys [year month day title] :as params} |
|
|
|
(defpage "/:year/:month/:day/:title" {:keys [year month day title] :as params} |
|
|
|
(let [noteID (api/build-key [year month day] title)] |
|
|
|
(let [noteID (api/build-key [year month day] title)] |
|
|
|
(when (storage/note-exists? noteID) |
|
|
|
(when (storage/note-exists? noteID) |
|
|
|
(let [note (api/get-note noteID)] |
|
|
|
(let [note (api/get-note noteID)] |
|
|
|
(layout (:title note) |
|
|
|
(layout (:title note) |
|
|
|
[:article.bottom-space.markdown (:note note)] |
|
|
|
(md-node :article.bottom-space (:note note)) |
|
|
|
(let [links (map #(link-to |
|
|
|
(let [links (map #(link-to |
|
|
|
(if (= :short-url %) |
|
|
|
(if (= :short-url %) |
|
|
|
(url (storage/create-short-url params)) |
|
|
|
(url (storage/create-short-url params)) |
|
|
|
@ -111,12 +119,10 @@ |
|
|
|
links (interpose [:span.middot "·"] links)] |
|
|
|
links (interpose [:span.middot "·"] links)] |
|
|
|
[:div#panel (map identity links)])))))) |
|
|
|
[:div#panel (map identity links)])))))) |
|
|
|
|
|
|
|
|
|
|
|
; 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]} |
|
|
|
(when-let [md-text (:note (api/get-note (api/build-key [year month day] title)))] |
|
|
|
(when-let [md-text (:note (api/get-note (api/build-key [year month day] title)))] |
|
|
|
(content-type "text/plain; charset=utf-8" md-text))) |
|
|
|
(content-type "text/plain; charset=utf-8" md-text))) |
|
|
|
|
|
|
|
|
|
|
|
; Provides the number of views of the specified note |
|
|
|
|
|
|
|
(defpage "/:year/:month/:day/:title/stats" {:keys [year month day title]} |
|
|
|
(defpage "/:year/:month/:day/:title/stats" {:keys [year month day title]} |
|
|
|
(when-let [stats (:statistics (api/get-note (api/build-key [year month day] title)))] |
|
|
|
(when-let [stats (:statistics (api/get-note (api/build-key [year month day] title)))] |
|
|
|
(layout (get-message :statistics) |
|
|
|
(layout (get-message :statistics) |
|
|
|
@ -126,7 +132,6 @@ |
|
|
|
[:tr [:td (str (get-message %) ":")] [:td (% stats)]]) |
|
|
|
[:tr [:td (str (get-message %) ":")] [:td (% stats)]]) |
|
|
|
[:published :edited :publisher :views])]))) |
|
|
|
[:published :edited :publisher :views])]))) |
|
|
|
|
|
|
|
|
|
|
|
; Resolving of a short url |
|
|
|
|
|
|
|
(defpage "/:short-url" {:keys [short-url]} |
|
|
|
(defpage "/:short-url" {:keys [short-url]} |
|
|
|
(when-let [params (storage/resolve-url short-url)] |
|
|
|
(when-let [params (storage/resolve-url short-url)] |
|
|
|
(let [{:keys [year month day title]} params |
|
|
|
(let [{:keys [year month day title]} params |
|
|
|
@ -135,21 +140,18 @@ |
|
|
|
long-url (if (empty? rest-params) core-url (util/url core-url rest-params))] |
|
|
|
long-url (if (empty? rest-params) core-url (util/url core-url rest-params))] |
|
|
|
(redirect long-url)))) |
|
|
|
(redirect long-url)))) |
|
|
|
|
|
|
|
|
|
|
|
; New Note Page |
|
|
|
|
|
|
|
(defpage "/new" {} |
|
|
|
|
|
|
|
(input-form "/post-note" :publish |
|
|
|
|
|
|
|
(html (hidden-field :session (storage/create-session)) |
|
|
|
|
|
|
|
(hidden-field {:id :signature} :signature)) |
|
|
|
|
|
|
|
(get-message :loading) :set-passwd)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; Update Note Page |
|
|
|
|
|
|
|
(defpage "/:year/:month/:day/:title/edit" {:keys [year month day title]} |
|
|
|
(defpage "/:year/:month/:day/:title/edit" {:keys [year month day title]} |
|
|
|
(let [noteID (api/build-key [year month day] title)] |
|
|
|
(let [noteID (api/build-key [year month day] title)] |
|
|
|
(input-form "/update-note" :update |
|
|
|
(input-form "/update-note" :update |
|
|
|
(html (hidden-field :noteID noteID)) |
|
|
|
(html (hidden-field :noteID noteID)) |
|
|
|
(:note (api/get-note noteID)) :enter-passwd))) |
|
|
|
(:note (api/get-note noteID)) :enter-passwd))) |
|
|
|
|
|
|
|
|
|
|
|
; Creates New Note from Web |
|
|
|
(defpage "/new" {} |
|
|
|
|
|
|
|
(input-form "/post-note" :publish |
|
|
|
|
|
|
|
(html (hidden-field :session (storage/create-session)) |
|
|
|
|
|
|
|
(hidden-field {:id :signature} :signature)) |
|
|
|
|
|
|
|
(get-message :loading) :set-passwd)) |
|
|
|
|
|
|
|
|
|
|
|
(defpage [:post "/post-note"] {:keys [session note signature password version]} |
|
|
|
(defpage [:post "/post-note"] {:keys [session note signature password version]} |
|
|
|
(if (= signature (api/get-signature session note)) |
|
|
|
(if (= signature (api/get-signature session note)) |
|
|
|
(let [pid "NoteHub" |
|
|
|
(let [pid "NoteHub" |
|
|
|
@ -164,7 +166,6 @@ |
|
|
|
(response 500))) |
|
|
|
(response 500))) |
|
|
|
(response 400))) |
|
|
|
(response 400))) |
|
|
|
|
|
|
|
|
|
|
|
; Updates a note |
|
|
|
|
|
|
|
(defpage [:post "/update-note"] {:keys [noteID note password version]} |
|
|
|
(defpage [:post "/update-note"] {:keys [noteID note password version]} |
|
|
|
(let [pid "NoteHub" |
|
|
|
(let [pid "NoteHub" |
|
|
|
psk (storage/get-psk pid)] |
|
|
|
psk (storage/get-psk pid)] |
|
|
|
@ -181,7 +182,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
(defpage "/api" args |
|
|
|
(defpage "/api" args |
|
|
|
(layout (get-message :api-title) |
|
|
|
(layout (get-message :api-title) |
|
|
|
[:article.markdown (slurp "API.md")])) |
|
|
|
(md-node :article (slurp "API.md")))) |
|
|
|
|
|
|
|
|
|
|
|
(defpage [:get "/api/note"] {:keys [version noteID]} |
|
|
|
(defpage [:get "/api/note"] {:keys [version noteID]} |
|
|
|
(generate-string (api/get-note noteID))) |
|
|
|
(generate-string (api/get-note noteID))) |
|
|
|
|