expected note title feature added
This commit is contained in:
@@ -3,7 +3,28 @@ var iosDetected = navigator.userAgent.match("(iPad|iPod|iPhone)");
|
|||||||
var timer = null;
|
var timer = null;
|
||||||
var timerDelay = iosDetected ? 800 : 400;
|
var timerDelay = iosDetected ? 800 : 400;
|
||||||
var show = function(elem) { elem.style.display = "block" }
|
var show = function(elem) { elem.style.display = "block" }
|
||||||
var $note, $action, $preview, $plain_password, $input_elems, $dashed_line, updatePreview;
|
var $note, $action, $preview, $plain_password, $input_elems, $dashed_line, $proposed_title, updatePreview;
|
||||||
|
var firstLines_;
|
||||||
|
var backendTimer;
|
||||||
|
|
||||||
|
function updateProposedTitle() {
|
||||||
|
clearTimeout(backendTimer);
|
||||||
|
backendTimer = setTimeout(function () {
|
||||||
|
var http = new XMLHttpRequest();
|
||||||
|
var url = "/propose-title";
|
||||||
|
http.open("POST", url, true);
|
||||||
|
http.onreadystatechange = function() {
|
||||||
|
if(http.readyState == 4 && http.status == 200) {
|
||||||
|
var now = new Date();
|
||||||
|
$proposed_title.innerHTML =
|
||||||
|
"Expected URL: https://www.notehub.org/" +
|
||||||
|
now.getFullYear() + "/" + (now.getMonth()+1) + "/" + now.getDate() + "/" +
|
||||||
|
http.responseText;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
http.send($note.value);
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
|
||||||
function md2html(input){
|
function md2html(input){
|
||||||
return marked(input);
|
return marked(input);
|
||||||
@@ -14,6 +35,7 @@ function onLoad () {
|
|||||||
$action = $("action");
|
$action = $("action");
|
||||||
$preview = $("preview");
|
$preview = $("preview");
|
||||||
$plain_password = $("plain-password");
|
$plain_password = $("plain-password");
|
||||||
|
$proposed_title = $("proposed-title");
|
||||||
$input_elems = $("input-elems");
|
$input_elems = $("input-elems");
|
||||||
$dashed_line = $("dashed-line");
|
$dashed_line = $("dashed-line");
|
||||||
updatePreview = function(){
|
updatePreview = function(){
|
||||||
@@ -24,6 +46,11 @@ function onLoad () {
|
|||||||
show($dashed_line);
|
show($dashed_line);
|
||||||
show($input_elems);
|
show($input_elems);
|
||||||
$preview.innerHTML = md2html(content);
|
$preview.innerHTML = md2html(content);
|
||||||
|
var firstLines = content.split("\n", 2);
|
||||||
|
if(firstLines_ != firstLines) {
|
||||||
|
firstLines_ = firstLines;
|
||||||
|
updateProposedTitle();
|
||||||
|
}
|
||||||
}, delay);
|
}, delay);
|
||||||
};
|
};
|
||||||
if($action){
|
if($action){
|
||||||
|
|||||||
+7
-4
@@ -75,6 +75,12 @@
|
|||||||
:publisher (storage/get-publisher noteID)})
|
:publisher (storage/get-publisher noteID)})
|
||||||
{:status (create-response false "noteID '%s' unknown" noteID)}))
|
{:status (create-response false "noteID '%s' unknown" noteID)}))
|
||||||
|
|
||||||
|
(defn propose-title [note]
|
||||||
|
(let [raw-title (filter #(or (= \- %) (Character/isLetterOrDigit %))
|
||||||
|
(-> note derive-title trim (sreplace " " "-") lower-case))
|
||||||
|
max-length (get-setting :max-title-length #(Integer/parseInt %) 80)]
|
||||||
|
(apply str (take max-length raw-title))))
|
||||||
|
|
||||||
(defn post-note
|
(defn post-note
|
||||||
[{:keys [note pid signature password hostURL] :as params}]
|
[{:keys [note pid signature password hostURL] :as params}]
|
||||||
;(log "post-note: %s" {:pid pid :signature signature :password password :note note})
|
;(log "post-note: %s" {:pid pid :signature signature :password password :note note})
|
||||||
@@ -86,10 +92,7 @@
|
|||||||
(if (empty? errors)
|
(if (empty? errors)
|
||||||
(let [[year month day] (map str (get-date))
|
(let [[year month day] (map str (get-date))
|
||||||
params (select-keys params [:text-size :header-size :text-font :header-font :theme])
|
params (select-keys params [:text-size :header-size :text-font :header-font :theme])
|
||||||
raw-title (filter #(or (= \- %) (Character/isLetterOrDigit %))
|
proposed-title (propose-title note)
|
||||||
(-> note derive-title trim (sreplace " " "-") lower-case))
|
|
||||||
max-length (get-setting :max-title-length #(Integer/parseInt %) 80)
|
|
||||||
proposed-title (apply str (take max-length raw-title))
|
|
||||||
title (first (drop-while #(storage/note-exists? (build-key year month day %))
|
title (first (drop-while #(storage/note-exists? (build-key year month day %))
|
||||||
(cons proposed-title
|
(cons proposed-title
|
||||||
(map #(str proposed-title "-" (+ 2 %)) (range)))))
|
(map #(str proposed-title "-" (+ 2 %)) (range)))))
|
||||||
|
|||||||
@@ -59,6 +59,12 @@
|
|||||||
|
|
||||||
(GET "/" [] landing-page)
|
(GET "/" [] landing-page)
|
||||||
|
|
||||||
|
(POST "/propose-title" {body :body}
|
||||||
|
(let [note (slurp body)]
|
||||||
|
(return-content-type
|
||||||
|
"text/plain; charset=utf-8"
|
||||||
|
(api/propose-title note))))
|
||||||
|
|
||||||
(GET "/:year/:month/:day/:title/export" [year month day title]
|
(GET "/:year/:month/:day/:title/export" [year month day title]
|
||||||
(when-let [md-text (:note (api/get-note {:noteID (api/build-key year month day title)}))]
|
(when-let [md-text (:note (api/get-note {:noteID (api/build-key year month day title)}))]
|
||||||
(return-content-type "text/plain; charset=utf-8" md-text)))
|
(return-content-type "text/plain; charset=utf-8" md-text)))
|
||||||
|
|||||||
@@ -60,10 +60,14 @@
|
|||||||
fields
|
fields
|
||||||
(text-area :note content)
|
(text-area :note content)
|
||||||
[:fieldset#input-elems {:class css-class}
|
[:fieldset#input-elems {:class css-class}
|
||||||
(text-field {:class "ui-elem" :placeholder (get-message passwd-msg)}
|
(text-field {:class "ui-elem"
|
||||||
:plain-password)
|
:placeholder (get-message passwd-msg)}
|
||||||
|
:plain-password) " "
|
||||||
(submit-button {:class "button ui-elem"
|
(submit-button {:class "button ui-elem"
|
||||||
:id :publish-button} (get-message command))])])))
|
:id :publish-button} (get-message command))
|
||||||
|
[:br]
|
||||||
|
[:br]
|
||||||
|
[:div#proposed-title {:style "color: #aaa; font-size: 0.8em"}]])])))
|
||||||
|
|
||||||
(def landing-page
|
(def landing-page
|
||||||
(layout :no-js {} (get-message :page-title)
|
(layout :no-js {} (get-message :page-title)
|
||||||
|
|||||||
Reference in New Issue
Block a user