title derivation improved and added to API
This commit is contained in:
@@ -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: <markdown source>,
|
||||
title: "Lorem Ipsum.",
|
||||
longURL: "http://notehub.org/2014/1/3/lorem-ipsum",
|
||||
shortURL: "http://notehub.org/0vrcp",
|
||||
statistics: {
|
||||
|
||||
+13
-6
@@ -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
|
||||
|
||||
@@ -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 %)
|
||||
|
||||
@@ -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])))))
|
||||
|
||||
Reference in New Issue
Block a user