From bccac0acbc16c9155b317aec85a3c0837ed9d9e5 Mon Sep 17 00:00:00 2001 From: Christian Mueller Date: Fri, 3 Jan 2014 15:28:10 +0100 Subject: [PATCH] front page minified --- LANDING.md | 19 ++++ messages | 7 +- src/NoteHub/views/pages.clj | 168 ++++++++++++++++++------------------ 3 files changed, 106 insertions(+), 88 deletions(-) create mode 100644 LANDING.md diff --git a/LANDING.md b/LANDING.md new file mode 100644 index 0000000..ec7f27f --- /dev/null +++ b/LANDING.md @@ -0,0 +1,19 @@ +## News + + - January 2014: NoteHub made more lightweight by dropping of CSS generation & ClojureScript usage + - September 2013: Solarized color theme [added](https://github.com/chmllr/NoteHub/pull/4) (thanks Brandon!) ([Demo](http://notehub.org/2012/6/16/how-notehub-is-built?theme=solarized)) + +## About +[NoteHub](http://notehub.org) is a free and hassle-free anonymous pastebin for markdown pages, intended for anonymous one-off publishing. + +Send your feedback and comments directly to [@gravitydenier](http://twitter.com/gravitydenier) or open an [issue](https://github.com/gravitydenier/NoteHub/issues) on GitHub. + +## Features +- **Color Themes**: specify the color scheme by appending the corresponding parameter to the URL: + - [Dark](http://notehub.org/2012/6/16/how-notehub-is-built?theme=dark) + - [Solarized](http://notehub.org/2012/6/16/how-notehub-is-built?theme=solarized) +- **Fonts**: select a [Google Web Font](http://www.google.com/webfonts/) for headers and for the text by appending parameters to the note [URL](http://notehub.org/2012/6/16/how-notehub-is-built?header-font=Chau+Philomene+One&text-font=Alegreya+Sans+SC). +- **Short URLs**: every page (including theme & font options) has its own short url. +- **Editing**: if you set a password during publishing, you can edit your note any time later. +- **Statistics**: a rudimentary statistics available (date of publishing & view counter). +- **Export**: the original markdown content can be displayed in plain text format. diff --git a/messages b/messages index c82d99f..c60d2e2 100644 --- a/messages +++ b/messages @@ -1,4 +1,5 @@ -title = Free and Hassle-free Hosting for Markdown Pages. +page-title = Publish Markdown for Free +title = Free and Hassle-free Pastebin for Markdown Pages. name = NoteHub new-page = New Page @@ -7,12 +8,11 @@ status-400 = Bad Request. status-403 = Wrong Password. status-500 = OMG, Server Exploded. -created-by = Created by [@gravitydenier](http://twitter.com/gravitydenier) +footer = Created by [@gravitydenier](http://twitter.com/gravitydenier) ♣ Available on [GitHub](https://github.com/chmllr/NoteHub) loading = Loading... set-passwd = Password for editing enter-passwd = Password -preview = Preview publish = Publish update = Save published = Published @@ -22,4 +22,3 @@ stats = statistics export = export edit = edit short-url = short url -new-note = New Markdown Note diff --git a/src/NoteHub/views/pages.clj b/src/NoteHub/views/pages.clj index 366b290..275ffb8 100644 --- a/src/NoteHub/views/pages.clj +++ b/src/NoteHub/views/pages.clj @@ -5,7 +5,7 @@ [NoteHub.settings] [NoteHub.views.common] [clojure.string :rename {replace sreplace} - :only [escape split replace blank? split-lines lower-case]] + :only [escape split replace blank? split-lines lower-case]] [clojure.core.incubator :only [-?>]] [hiccup.form] [hiccup.core] @@ -85,48 +85,48 @@ ; Landing Page (defpage "/" {} - (layout (get-message :title) - [:div#hero - [:h1 (get-message :name)] - [:h2 (get-message :title)] - [:br] - [:a.landing-button {:href "/new" :style "color: white"} (get-message :new-page)]] - [:div#dashed-line] - ; dynamically generates three column, retrieving corresponding messages - [:article.helvetica-neue.bottom-space {:style "font-size: 1em"} - (md-to-html (slurp "README.md"))] - [:div.centered.helvetica-neue (md-to-html (get-message :created-by))])) + (layout (get-message :page-title) + [:div#hero + [:h1 (get-message :name)] + [:h2 (get-message :title)] + [:br] + [:a.landing-button {:href "/new" :style "color: white"} (get-message :new-page)]] + [:div#dashed-line] + ; dynamically generates three column, retrieving corresponding messages + [:article.helvetica-neue.bottom-space {:style "font-size: 1em"} + (md-to-html (slurp "LANDING.md"))] + [:div.centered.helvetica-neue (md-to-html (get-message :footer))])) ; input form for the markdown text with a preview area (defpartial input-form [form-url command fields content passwd-msg] - (let [css-class (when (= :publish command) :hidden)] - (layout {:js true} (get-message :new-note) - [:article#preview " "] - [:div#dashed-line {:class css-class}] - [:div.central-element.helvetica-neue {:style "margin-bottom: 3em"} - (form-to {:autocomplete :off} [:post form-url] - (hidden-field :action command) - (hidden-field :password) - fields - (text-area {:class :max-width} :draft content) - [:fieldset#input-elems {:class css-class} - (text-field {:class "ui-elem" :placeholder (get-message passwd-msg)} - :plain-password) - (submit-button {:class "button ui-elem" - :id :publish-button} (get-message command))])]))) + (let [css-class (when (= :publish command) :hidden)] + (layout {:js true} (get-message :new-note) + [:article#preview " "] + [:div#dashed-line {:class css-class}] + [:div.central-element.helvetica-neue {:style "margin-bottom: 3em"} + (form-to {:autocomplete :off} [:post form-url] + (hidden-field :action command) + (hidden-field :password) + fields + (text-area {:class :max-width} :draft content) + [:fieldset#input-elems {:class css-class} + (text-field {:class "ui-elem" :placeholder (get-message passwd-msg)} + :plain-password) + (submit-button {:class "button ui-elem" + :id :publish-button} (get-message command))])]))) ; Update Note Page (defpage "/:year/:month/:day/:title/edit" {:keys [year month day title]} - (input-form "/update-note" :update - (html (hidden-field :key (build-key [year month day] title))) - (get-note [year month day] title) :enter-passwd)) + (input-form "/update-note" :update + (html (hidden-field :key (build-key [year month day] title))) + (get-note [year month day] title) :enter-passwd)) ; New Note Page (defpage "/new" {} - (input-form "/post-note" :publish - (html (hidden-field :session-key (create-session)) - (hidden-field {:id :session-value} :session-value)) - (get-message :loading) :set-passwd)) + (input-form "/post-note" :publish + (html (hidden-field :session-key (create-session)) + (hidden-field {:id :session-value} :session-value)) + (get-message :loading) :set-passwd)) ; Displays the note (defpage "/:year/:month/:day/:title" {:keys [year month day title theme header-font text-font] :as params} @@ -137,66 +137,66 @@ ; Provides Markdown of the specified note (defpage "/:year/:month/:day/:title/export" {:keys [year month day title]} - (when-let [md-text (get-note [year month day] title)] - (content-type "text/plain; charset=utf-8" md-text))) + (when-let [md-text (get-note [year month day] title)] + (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]} - (when-let [views (get-note-views [year month day] title)] - (layout (get-message :statistics) - [:table#stats.helvetica-neue.central-element - [:tr - [:td (get-message :published)] - [:td (interpose "-" [year month day])]] - [:tr - [:td (get-message :article-views)] - [:td views]]]))) + (when-let [views (get-note-views [year month day] title)] + (layout (get-message :statistics) + [:table#stats.helvetica-neue.central-element + [:tr + [:td (get-message :published)] + [:td (interpose "-" [year month day])]] + [:tr + [:td (get-message :article-views)] + [:td views]]]))) ; Updates a note (defpage [:post "/update-note"] {:keys [key draft password]} - (if (update-note key draft password) - (redirect (apply url (split key #" "))) - (response 403))) + (if (update-note key draft password) + (redirect (apply url (split key #" "))) + (response 403))) ; New Note Posting — the most "complex" function in the entire app ;) (defpage [:post "/post-note"] {:keys [draft password session-key session-value]} - ; first we collect all info needed to evaluate the validity of the note creation request - (let [valid-session (invalidate-session session-key) ; was the note posted from a newly generated form? - valid-draft (not (blank? draft)) ; has the note a meaningful content? - ; is the hash code correct? - valid-hash (try - (= (Short/parseShort session-value) - (get-hash (str draft session-key))) - (catch Exception e nil))] - ; check whether the new note can be added - (if (and valid-session valid-draft valid-hash) - ; if yes, we compute the current date, extract a title string from the text, - ; which will be a part of the url and look whether this title is free today; - ; if not, append "-n", where "n" is the next free number - (let [[year month day] (get-date) - untrimmed-line (filter #(or (= \- %) (Character/isLetterOrDigit %)) - (-> draft split-lines first (sreplace " " "-") lower-case)) - trim (fn [s] (apply str (drop-while #(= \- %) s))) - title-uncut (-> untrimmed-line trim reverse trim reverse) - max-length (get-setting :max-title-length #(Integer/parseInt %) 80) - ; TODO: replace to ccs/take when it gets fixed - proposed-title (apply str (take max-length title-uncut)) - date [year month day] - title (first (drop-while #(note-exists? date %) - (cons proposed-title - (map #(str proposed-title "-" (+ 2 %)) (range)))))] - (do - (set-note date title draft password) - (redirect (url year month day title)))) - (response 400)))) + ; first we collect all info needed to evaluate the validity of the note creation request + (let [valid-session (invalidate-session session-key) ; was the note posted from a newly generated form? + valid-draft (not (blank? draft)) ; has the note a meaningful content? + ; is the hash code correct? + valid-hash (try + (= (Short/parseShort session-value) + (get-hash (str draft session-key))) + (catch Exception e nil))] + ; check whether the new note can be added + (if (and valid-session valid-draft valid-hash) + ; if yes, we compute the current date, extract a title string from the text, + ; which will be a part of the url and look whether this title is free today; + ; if not, append "-n", where "n" is the next free number + (let [[year month day] (get-date) + untrimmed-line (filter #(or (= \- %) (Character/isLetterOrDigit %)) + (-> draft split-lines first (sreplace " " "-") lower-case)) + trim (fn [s] (apply str (drop-while #(= \- %) s))) + title-uncut (-> untrimmed-line trim reverse trim reverse) + max-length (get-setting :max-title-length #(Integer/parseInt %) 80) + ; TODO: replace to ccs/take when it gets fixed + proposed-title (apply str (take max-length title-uncut)) + date [year month day] + title (first (drop-while #(note-exists? date %) + (cons proposed-title + (map #(str proposed-title "-" (+ 2 %)) (range)))))] + (do + (set-note date title draft password) + (redirect (url year month day title)))) + (response 400)))) ; Resolving of a short url (defpage "/:short-url" {:keys [short-url]} - (when-let [params (resolve-url short-url)] - (let [{:keys [year month day title]} params - rest-params (dissoc params :year :month :day :title) - core-url (url year month day title) - long-url (if (empty? rest-params) core-url (util/url core-url rest-params))] - (redirect long-url)))) - + (when-let [params (resolve-url short-url)] + (let [{:keys [year month day title]} params + rest-params (dissoc params :year :month :day :title) + core-url (url year month day title) + long-url (if (empty? rest-params) core-url (util/url core-url rest-params))] + (redirect long-url)))) +