diff --git a/API.md b/API.md index 19f554f..786361f 100644 --- a/API.md +++ b/API.md @@ -26,12 +26,13 @@ Parameter | Explanation | Type `noteID` | Note-ID | **required** `version` | Used API version | **required** -will return a JSON object containing following self explaining fields: `note`, `longURL`, `shortURL`, `statistics`, `status`. +will return a JSON object containing following self explaining fields: `note`, `title`, `longURL`, `shortURL`, `statistics`, `status`, `publisher`. Example: { note: , + title: "Lorem Ipsum.", longURL: "http://notehub.org/2014/1/3/lorem-ipsum", shortURL: "http://notehub.org/0vrcp", statistics: { diff --git a/src/NoteHub/api.clj b/src/NoteHub/api.clj index 8a322f4..463c863 100644 --- a/src/NoteHub/api.clj +++ b/src/NoteHub/api.clj @@ -25,6 +25,11 @@ [[year month day] title] (print-str year month day title)) +(defn derive-title [md-text] + (apply str + (remove #{\# \_ \*} + (first (split-lines md-text))))) + (defn get-date "Returns today's date" [] @@ -54,12 +59,14 @@ (defn get-note [noteID] (if (storage/note-exists? noteID) - {:note (storage/get-note noteID) - :longURL (get-path noteID) - :shortURL (get-path noteID :short) - :statistics (storage/get-note-statistics noteID) - :status (create-response true) - :publisher (storage/get-publisher noteID)} + (let [note (storage/get-note noteID)] + {:note note + :title (derive-title note) + :longURL (get-path noteID) + :shortURL (get-path noteID :short) + :statistics (storage/get-note-statistics noteID) + :status (create-response true) + :publisher (storage/get-publisher noteID)}) (create-response false "noteID '%s' unknown" noteID))) (defn post-note diff --git a/src/NoteHub/views/pages.clj b/src/NoteHub/views/pages.clj index 8683dd1..ba4e192 100644 --- a/src/NoteHub/views/pages.clj +++ b/src/NoteHub/views/pages.clj @@ -73,7 +73,7 @@ ; Converts given markdown to html and wraps with the main layout (defn- wrap [short-url params md-text] (when md-text - (layout params (params :title) + (layout params (api/derive-title md-text) [:article.bottom-space.markdown md-text] (let [links (map #(link-to (if (= :short-url %) diff --git a/test/NoteHub/test/api.clj b/test/NoteHub/test/api.clj index 28caad2..10aab4a 100644 --- a/test/NoteHub/test/api.clj +++ b/test/NoteHub/test/api.clj @@ -6,11 +6,11 @@ [noir.util.test] [clojure.test])) -(def note "hello world! This is a _test_ note!") +(def note "hello world!\nThis is a _test_ note!") (def pid "somePlugin") (def pid2 "somePlugin2") -(def note-title (str (apply print-str (get-date)) " hello-world-this-is-a-test-note")) -(def note-url (str (apply str domain "/" (interpose "/" (get-date))) "/hello-world-this-is-a-test-note")) +(def note-title (str (apply print-str (get-date)) " hello-world")) +(def note-url (str (apply str domain "/" (interpose "/" (get-date))) "/hello-world")) (defn substring? [a b] (not (= nil (re-matches (re-pattern (str "(?s).*" a ".*")) b)))) (defmacro isnt [arg] `(is (not ~arg))) @@ -46,6 +46,7 @@ (is (= (:longURL post-response) (:longURL get-response) note-url)) (is (= (:shortURL post-response) (:shortURL get-response))) (is (= (:publisher get-response) pid)) + (is (= (:title get-response) (derive-title note))) (is (= "1" (get-in get-response [:statistics :views]))) (isnt (get-in get-response [:statistics :edited])) (is (= "2" (get-in (get-note (:noteID post-response)) [:statistics :views])))))