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 timerDelay = iosDetected ? 800 : 400;
|
||||
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){
|
||||
return marked(input);
|
||||
@@ -14,6 +35,7 @@ function onLoad () {
|
||||
$action = $("action");
|
||||
$preview = $("preview");
|
||||
$plain_password = $("plain-password");
|
||||
$proposed_title = $("proposed-title");
|
||||
$input_elems = $("input-elems");
|
||||
$dashed_line = $("dashed-line");
|
||||
updatePreview = function(){
|
||||
@@ -24,6 +46,11 @@ function onLoad () {
|
||||
show($dashed_line);
|
||||
show($input_elems);
|
||||
$preview.innerHTML = md2html(content);
|
||||
var firstLines = content.split("\n", 2);
|
||||
if(firstLines_ != firstLines) {
|
||||
firstLines_ = firstLines;
|
||||
updateProposedTitle();
|
||||
}
|
||||
}, delay);
|
||||
};
|
||||
if($action){
|
||||
|
||||
+7
-4
@@ -75,6 +75,12 @@
|
||||
:publisher (storage/get-publisher 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
|
||||
[{:keys [note pid signature password hostURL] :as params}]
|
||||
;(log "post-note: %s" {:pid pid :signature signature :password password :note note})
|
||||
@@ -86,10 +92,7 @@
|
||||
(if (empty? errors)
|
||||
(let [[year month day] (map str (get-date))
|
||||
params (select-keys params [:text-size :header-size :text-font :header-font :theme])
|
||||
raw-title (filter #(or (= \- %) (Character/isLetterOrDigit %))
|
||||
(-> 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))
|
||||
proposed-title (propose-title note)
|
||||
title (first (drop-while #(storage/note-exists? (build-key year month day %))
|
||||
(cons proposed-title
|
||||
(map #(str proposed-title "-" (+ 2 %)) (range)))))
|
||||
|
||||
@@ -59,6 +59,12 @@
|
||||
|
||||
(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]
|
||||
(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)))
|
||||
|
||||
@@ -60,10 +60,14 @@
|
||||
fields
|
||||
(text-area :note content)
|
||||
[:fieldset#input-elems {:class css-class}
|
||||
(text-field {:class "ui-elem" :placeholder (get-message passwd-msg)}
|
||||
:plain-password)
|
||||
(text-field {:class "ui-elem"
|
||||
:placeholder (get-message passwd-msg)}
|
||||
:plain-password) " "
|
||||
(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
|
||||
(layout :no-js {} (get-message :page-title)
|
||||
|
||||
Reference in New Issue
Block a user