diff --git a/messages.json b/messages.json
deleted file mode 100644
index bc7364f..0000000
--- a/messages.json
+++ /dev/null
@@ -1,27 +0,0 @@
-{
- "page-title": "Free Pastebin for One-Off Markdown Publishing",
- "title": "Free and Hassle-free Pastebin for Markdown Notes.",
- "name": "NoteHub",
- "new-page": "New Page",
- "status-404": "Not Found",
- "status-400": "Bad Request",
- "status-403": "Forbidden",
- "status-500": "Internal Server Error",
- "footer": "Source code on [GitHub](https://github.com/chmllr/NoteHub) · Hosted on [Heroku](http://heroku.com) · DB on [RedisLabs](http://redislabs.com) · SSL by [CloudFlare](http://cloudflare.com)
Created by [@chmllr](https://github.com/chmllr)",
- "loading": "Loading...",
- "set-passwd": "Password for editing",
- "enter-passwd": "Password",
- "publish": "Publish",
- "update": "Save",
- "published": "Published",
- "publisher": "Publisher",
- "edited": "Edited",
- "views": "Article Views",
- "statistics": "Statistics",
- "stats": "statistics",
- "export": "export",
- "notehub": "⌂ notehub",
- "edit": "edit",
- "short-url": "short url",
- "api-title": "API"
-}
\ No newline at end of file
diff --git a/package.json b/package.json
index 07d3198..bce9858 100644
--- a/package.json
+++ b/package.json
@@ -26,6 +26,7 @@
"express": "^4.13.3",
"lru-cache": "^2.6.5",
"marked": "^0.3.5",
+ "md5": "^2.0.0",
"sequelize": "^3.8.0",
"sqlite3": "^3.1.0"
}
diff --git a/resources/new.html b/resources/new.html
new file mode 100644
index 0000000..eca2b64
--- /dev/null
+++ b/resources/new.html
@@ -0,0 +1,33 @@
+
+
+
+
+ NoteHub — New Page
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/resources/public/js/publishing.js b/resources/public/js/publishing.js
index b674a72..ac2abf6 100644
--- a/resources/public/js/publishing.js
+++ b/resources/public/js/publishing.js
@@ -1,41 +1,45 @@
-var $ = function(id){ return document.getElementById(id); }
+var $ = function(id) {
+ return document.getElementById(id);
+}
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 show = function(elem) {
+ elem.style.display = "block"
+}
var $note, $action, $preview, $plain_password, $input_elems, $dashed_line, $proposed_title, updatePreview;
var backendTimer;
-function md2html(input){
+function md2html(input) {
return marked(input);
}
-function onLoad () {
+function onLoad() {
$note = $("note");
- $action = $("action");
+ $action = document.getElementsByTagName("form")[0].method;
$preview = $("preview");
$plain_password = $("plain-password");
$proposed_title = $("proposed-title");
$input_elems = $("input-elems");
$dashed_line = $("dashed-line");
- updatePreview = function(){
+ updatePreview = function() {
clearTimeout(timer);
var content = $note.value;
var delay = Math.min(timerDelay, timerDelay * (content.length / 400));
- timer = setTimeout(function(){
+ timer = setTimeout(function() {
show($dashed_line);
show($input_elems);
$preview.innerHTML = md2html(content);
}, delay);
};
- if($action){
- if($action.value == "update") updatePreview(); else $note.value = "";
- $note.onkeyup = updatePreview;
- $("publish-button").onclick = function(e) {
- if($plain_password.value != "") $("password").value = md5($plain_password.value);
- $plain_password.value = null;
- $("signature").value = md5($("session").value + $note.value);
- }
- if(iosDetected) $note.className += " ui-border"; else $note.focus();
+ if ($action.value == "update") updatePreview();
+ else $note.value = "";
+ $note.onkeyup = updatePreview;
+ $("publish-button").onclick = function(e) {
+ if ($plain_password.value != "") $("password").value = md5($plain_password.value);
+ $plain_password.value = null;
+ $("signature").value = md5($("session").value + $note.value);
}
+ if (iosDetected) $note.className += " ui-border";
+ else $note.focus();
}
diff --git a/resources/template.html b/resources/template.html
index 06048a6..c6c16b1 100644
--- a/resources/template.html
+++ b/resources/template.html
@@ -2,8 +2,8 @@
NoteHub — %TITLE%
-
-
+
+
diff --git a/server.js b/server.js
index 980849e..905a393 100644
--- a/server.js
+++ b/server.js
@@ -1,15 +1,26 @@
var express = require('express');
var page = require('./src/page');
var storage = require('./src/storage');
+var md5 = require('md5');
var LRU = require("lru-cache");
var app = express();
var CACHE = new LRU(30);
+var getTimeStamp = () => {
+ var timestamp = new Date().getTime();
+ timestamp = Math.floor(timestamp / 10000000);
+ return (timestamp).toString(16)
+}
+
app.use(express.static(__dirname + '/resources/public'));
app.get('/new', function (req, res) {
- res.send("opening new note mask")
+ res.send(page.newNotePage(getTimeStamp() + md5(Math.random())));
+});
+
+app.post('/note', function (req, res) {
+ console.log(req.params);
});
app.get("/:year/:month/:day/:title", function (req, res) {
@@ -22,7 +33,7 @@ app.get(/\/([a-zA-Z0-9]*)/, function (req, res) {
var link = req.params["0"].toLowerCase();
if (CACHE.has(link)) res.send(CACHE.get(link));
else storage.getNote(link).then(note => {
- var content = page.build(note);
+ var content = page.buildNote(note);
CACHE.set(link, content);
res.send(content);
});
diff --git a/src/page.js b/src/page.js
index e18a2bb..c346a76 100644
--- a/src/page.js
+++ b/src/page.js
@@ -1,10 +1,15 @@
var marked = require("marked");
var fs = require("fs");
-var template = fs.readFileSync("resources/template.html", "utf-8");
-var buildHTML = (id, title, content) => template
+var pageTemplate = fs.readFileSync("resources/template.html", "utf-8");
+var newNoteTemplate = fs.readFileSync("resources/new.html", "utf-8");
+var buildPage = (id, title, content) => pageTemplate
.replace("%TITLE%", title)
.replace(/%LINK%/g, id)
.replace("%CONTENT%", content);
-module.exports.build = note => buildHTML(note.id, note.title, marked(note.text));
+module.exports.buildNote = note => buildPage(note.id, note.title, marked(note.text));
+
+module.exports.newNotePage = session => newNoteTemplate
+ .replace("%METHOD%", "POST")
+ .replace("%SESSION%", session);