title derivation improved and added to API
This commit is contained in:
@@ -26,12 +26,13 @@ Parameter | Explanation | Type
|
|||||||
`noteID` | Note-ID | **required**
|
`noteID` | Note-ID | **required**
|
||||||
`version` | Used API version | **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:
|
Example:
|
||||||
|
|
||||||
{
|
{
|
||||||
note: <markdown source>,
|
note: <markdown source>,
|
||||||
|
title: "Lorem Ipsum.",
|
||||||
longURL: "http://notehub.org/2014/1/3/lorem-ipsum",
|
longURL: "http://notehub.org/2014/1/3/lorem-ipsum",
|
||||||
shortURL: "http://notehub.org/0vrcp",
|
shortURL: "http://notehub.org/0vrcp",
|
||||||
statistics: {
|
statistics: {
|
||||||
|
|||||||
+13
-6
@@ -25,6 +25,11 @@
|
|||||||
[[year month day] title]
|
[[year month day] title]
|
||||||
(print-str 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
|
(defn get-date
|
||||||
"Returns today's date"
|
"Returns today's date"
|
||||||
[]
|
[]
|
||||||
@@ -54,12 +59,14 @@
|
|||||||
|
|
||||||
(defn get-note [noteID]
|
(defn get-note [noteID]
|
||||||
(if (storage/note-exists? noteID)
|
(if (storage/note-exists? noteID)
|
||||||
{:note (storage/get-note noteID)
|
(let [note (storage/get-note noteID)]
|
||||||
:longURL (get-path noteID)
|
{:note note
|
||||||
:shortURL (get-path noteID :short)
|
:title (derive-title note)
|
||||||
:statistics (storage/get-note-statistics noteID)
|
:longURL (get-path noteID)
|
||||||
:status (create-response true)
|
:shortURL (get-path noteID :short)
|
||||||
:publisher (storage/get-publisher noteID)}
|
:statistics (storage/get-note-statistics noteID)
|
||||||
|
:status (create-response true)
|
||||||
|
:publisher (storage/get-publisher noteID)})
|
||||||
(create-response false "noteID '%s' unknown" noteID)))
|
(create-response false "noteID '%s' unknown" noteID)))
|
||||||
|
|
||||||
(defn post-note
|
(defn post-note
|
||||||
|
|||||||
@@ -73,7 +73,7 @@
|
|||||||
; Converts given markdown to html and wraps with the main layout
|
; Converts given markdown to html and wraps with the main layout
|
||||||
(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 (api/derive-title md-text)
|
||||||
[:article.bottom-space.markdown md-text]
|
[:article.bottom-space.markdown md-text]
|
||||||
(let [links (map #(link-to
|
(let [links (map #(link-to
|
||||||
(if (= :short-url %)
|
(if (= :short-url %)
|
||||||
|
|||||||
@@ -6,11 +6,11 @@
|
|||||||
[noir.util.test]
|
[noir.util.test]
|
||||||
[clojure.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 pid "somePlugin")
|
||||||
(def pid2 "somePlugin2")
|
(def pid2 "somePlugin2")
|
||||||
(def note-title (str (apply print-str (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-this-is-a-test-note"))
|
(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))))
|
(defn substring? [a b] (not (= nil (re-matches (re-pattern (str "(?s).*" a ".*")) b))))
|
||||||
|
|
||||||
(defmacro isnt [arg] `(is (not ~arg)))
|
(defmacro isnt [arg] `(is (not ~arg)))
|
||||||
@@ -46,6 +46,7 @@
|
|||||||
(is (= (:longURL post-response) (:longURL get-response) note-url))
|
(is (= (:longURL post-response) (:longURL get-response) note-url))
|
||||||
(is (= (:shortURL post-response) (:shortURL get-response)))
|
(is (= (:shortURL post-response) (:shortURL get-response)))
|
||||||
(is (= (:publisher get-response) pid))
|
(is (= (:publisher get-response) pid))
|
||||||
|
(is (= (:title get-response) (derive-title note)))
|
||||||
(is (= "1" (get-in get-response [:statistics :views])))
|
(is (= "1" (get-in get-response [:statistics :views])))
|
||||||
(isnt (get-in get-response [:statistics :edited]))
|
(isnt (get-in get-response [:statistics :edited]))
|
||||||
(is (= "2" (get-in (get-note (:noteID post-response)) [:statistics :views])))))
|
(is (= "2" (get-in (get-note (:noteID post-response)) [:statistics :views])))))
|
||||||
|
|||||||
Reference in New Issue
Block a user