Browse Source

switched to JS markdown processing only

master
Christian Mueller 12 years ago
parent
commit
b8e1f25baf
  1. 2
      LANDING.md
  2. 6
      README.md
  3. 6
      project.clj
  4. 15
      resources/public/js/main.js
  5. 3
      src/NoteHub/views/common.clj
  6. 27
      src/NoteHub/views/pages.clj

2
LANDING.md

@ -6,7 +6,7 @@
## About ## About
[NoteHub](http://notehub.org) is a free and hassle-free anonymous pastebin for markdown pages, intended for anonymous one-off publishing. [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. Send your feedback and comments directly to [@gravitydenier](http://twitter.com/gravitydenier) or open an [issue](https://github.com/chmllr/NoteHub/issues) on GitHub.
## Features ## Features
- **Color Themes**: specify the color scheme by appending the corresponding parameter to the URL: - **Color Themes**: specify the color scheme by appending the corresponding parameter to the URL:

6
README.md

@ -1,7 +1,3 @@
## News
- 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 ## About
[NoteHub](http://notehub.org) is a free and hassle-free anonymous hosting for markdown pages. It can be used for publishing of markdown-formatted texts. [NoteHub](http://notehub.org) is a free and hassle-free anonymous hosting for markdown pages. It can be used for publishing of markdown-formatted texts.
@ -10,7 +6,7 @@ NoteHub was an one-app-one-language [experiment](http://notehub.org/2012/6/16/ho
The [source code](https://github.com/chmllr/NoteHub) can be found on GitHub. The [source code](https://github.com/chmllr/NoteHub) can be found on GitHub.
NoteHub's persistence layer is based on the key-value store [redis](http://redis.io). NoteHub's persistence layer is based on the key-value store [redis](http://redis.io).
Currently, NoteHub is hosted for free on [Heroku](http://heroku.com). Currently, NoteHub is hosted for free on [Heroku](http://heroku.com).
Send your feedback and comments directly to [@gravitydenier](http://twitter.com/gravitydenier) or open an [issue](https://github.com/gravitydenier/NoteHub/issues) on GitHub. Send your feedback and comments directly to [@gravitydenier](http://twitter.com/gravitydenier) or open an [issue](https://github.com/chmllr/NoteHub/issues) on GitHub.
## Why? ## Why?
Not every person, who occasionally wants to express some thoughts, needs a blog. Not every person, who occasionally wants to express some thoughts, needs a blog.

6
project.clj

@ -1,11 +1,9 @@
(defproject NoteHub "0.1.0-SNAPSHOT" (defproject NoteHub "2.0.0"
:description "A free and anonymous hosting for markdown pages." :description "A free and anonymous hosting for markdown pages."
:dependencies [[org.clojure/clojure "1.3.0"] :dependencies [[org.clojure/clojure "1.5.1"]
[hiccup "1.0.0"] [hiccup "1.0.0"]
[ring/ring-core "1.1.0"] [ring/ring-core "1.1.0"]
[clj-redis "0.0.12"] [clj-redis "0.0.12"]
[org.pegdown/pegdown "1.1.0"]
[noir "1.3.0-beta1"]] [noir "1.3.0-beta1"]]
:jvm-opts ["-Dfile.encoding=utf-8"] :jvm-opts ["-Dfile.encoding=utf-8"]
:main NoteHub.server) :main NoteHub.server)

15
resources/public/js/main.js

@ -33,11 +33,18 @@ var updatePreview = function(){
}, delay); }, delay);
}; };
if($action.value == "update") updatePreview(); else $draft.value = ""; if($action){
if(iosDetected) $draft.className += " ui-border"; else $draft.focus(); if($action.value == "update") updatePreview(); else $draft.value = "";
$draft.onkeyup = updatePreview; $draft.onkeyup = updatePreview;
$("publish-button").onclick = function(e) { $("publish-button").onclick = function(e) {
if($plain_password.value != "") $password.value = md5($plain_password.value); if($plain_password.value != "") $password.value = md5($plain_password.value);
$plain_password.value = null; $plain_password.value = null;
$("session-value").value = hash($draft.value + $("session-key").value); $("session-value").value = hash($draft.value + $("session-key").value);
}
if(iosDetected) $draft.className += " ui-border"; else $draft.focus();
}
var mdDocs = document.getElementsByClassName("markdown");
for(var i = 0; i < mdDocs.length; i++){
mdDocs[i].innerHTML = marked(mdDocs[i].innerHTML);
} }

3
src/NoteHub/views/common.clj

@ -44,11 +44,10 @@
(if-not (dev-mode?) (include-js "/js/google-analytics.js"))] (if-not (dev-mode?) (include-js "/js/google-analytics.js"))]
[:body content [:body content
; we only need JS during a new note creation, so don't render it otherwise ; we only need JS during a new note creation, so don't render it otherwise
(when (params :js)
(html (html
(include-js "/js/md5.js") (include-js "/js/md5.js")
(include-js "/js/marked.js") (include-js "/js/marked.js")
(include-js "/js/main.js")))]))) (include-js "/js/main.js"))])))
(defn layout (defn layout
"Generates the main html layout" "Generates the main html layout"

27
src/NoteHub/views/pages.clj

@ -14,16 +14,7 @@
[noir.core :only [defpage defpartial]] [noir.core :only [defpage defpartial]]
[noir.statuses]) [noir.statuses])
(:import (:import
[java.util Calendar] [java.util Calendar]))
[org.pegdown PegDownProcessor]))
; Create a new Object of the MD-processor
(def md-processor
(PegDownProcessor.))
; Markdown -> HTML mapper
(defn md-to-html [md-text]
(.markdownToHtml md-processor md-text))
(defn get-hash (defn get-hash
"A simple hash-function, which computes a hash from the text field "A simple hash-function, which computes a hash from the text field
@ -57,7 +48,7 @@
(defn- wrap [short-url params md-text] (defn- wrap [short-url params md-text]
(when md-text (when md-text
(layout params (params :title) (layout params (params :title)
[:article.bottom-space (md-to-html md-text)] [:article.bottom-space.markdown md-text]
(let [links (map #(link-to (let [links (map #(link-to
(if (= :short-url %) (if (= :short-url %)
(url short-url) (url short-url)
@ -78,11 +69,6 @@
; Routes ; Routes
; ====== ; ======
; This function answers to an AJAX request: it gets a session key and a markdown text.
; It returns the html code of the provided markdown and a new session key.
(defpage [:post "/preview"] {:keys [session-key draft]}
(str "{ preview: " (escape (md-to-html draft) {\" "\\\""}) "}"))
; Landing Page ; Landing Page
(defpage "/" {} (defpage "/" {}
(layout (get-message :page-title) (layout (get-message :page-title)
@ -92,16 +78,15 @@
[: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]
; dynamically generates three column, retrieving corresponding messages [:article.helvetica-neue.bottom-space.markdown {:style "font-size: 1em"}
[:article.helvetica-neue.bottom-space {:style "font-size: 1em"} (slurp "LANDING.md")]
(md-to-html (slurp "LANDING.md"))] [:div.centered.helvetica-neue.markdown (get-message :footer)]))
[:div.centered.helvetica-neue (md-to-html (get-message :footer))]))
; 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 {:js true} (get-message :new-note)
[:article#preview " "] [:article#preview.markdown " "]
[:div#dashed-line {:class css-class}] [:div#dashed-line {:class css-class}]
[:div.central-element.helvetica-neue {:style "margin-bottom: 3em"} [:div.central-element.helvetica-neue {:style "margin-bottom: 3em"}
(form-to {:autocomplete :off} [:post form-url] (form-to {:autocomplete :off} [:post form-url]

Loading…
Cancel
Save