markdown enabled
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
<title>NoteHub — Free Pastebin for One-Off Markdown Publishing</title>
|
<title>NoteHub — Free Pastebin for One-Off Markdown Publishing</title>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta content="width=device-width, initial-scale=1.0" name="viewport">
|
<meta content="width=device-width, initial-scale=1.0" name="viewport">
|
||||||
<link href="style.css" rel="stylesheet" type="text/css" />
|
<link href="/style.css" rel="stylesheet" type="text/css" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="hero">
|
<div id="hero">
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
<h2>Free and Hassle-free Pastebin for Markdown Notes.</h2>
|
<h2>Free and Hassle-free Pastebin for Markdown Notes.</h2>
|
||||||
<br>
|
<br>
|
||||||
<a class="landing-button demo" href="2014/3/31/demo-note" style="color: white">See Demo Note</a>
|
<a class="landing-button demo" href="2014/3/31/demo-note" style="color: white">See Demo Note</a>
|
||||||
<a class="landing-button" href="/new" style="color: white">New Page</a>
|
<a class="landing-button" href="/new" style="color: white">New Note</a>
|
||||||
</div>
|
</div>
|
||||||
<div id="dashed-line"></div>
|
<div id="dashed-line"></div>
|
||||||
<article class="helvetica bottom-space" style="font-size: 1em">
|
<article class="helvetica bottom-space" style="font-size: 1em">
|
||||||
|
|||||||
@@ -4,13 +4,11 @@
|
|||||||
<title>NoteHub — %TITLE%</title>
|
<title>NoteHub — %TITLE%</title>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta content="width=device-width, initial-scale=1.0" name="viewport">
|
<meta content="width=device-width, initial-scale=1.0" name="viewport">
|
||||||
<link href="https://fonts.googleapis.com/css?family=PT+Serif:700|Noticia+Text:700&subset=latin,cyrillic"
|
<link href="/style.css" rel="stylesheet" type="text/css" />
|
||||||
rel="stylesheet" type="text/css" />
|
|
||||||
<link href="style.css" rel="stylesheet" type="text/css" />
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<article>
|
<article>
|
||||||
%CONTENT%
|
%CONTENT%
|
||||||
</article>
|
</article>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
var express = require('express');
|
var express = require('express');
|
||||||
var page = require('./src/page');
|
var page = require('./src/page');
|
||||||
var storage = require('./src/storage');
|
var storage = require('./src/storage');
|
||||||
|
var LRU = require("lru-cache");
|
||||||
|
|
||||||
var app = express();
|
var app = express();
|
||||||
|
var CACHE = new LRU(30);
|
||||||
|
|
||||||
app.use(express.static(__dirname + '/resources/public'));
|
app.use(express.static(__dirname + '/resources/public'));
|
||||||
|
|
||||||
@@ -11,8 +14,11 @@ app.get('/new', function (req, res) {
|
|||||||
|
|
||||||
app.get(/(.*)\??.*/, function (req, res) {
|
app.get(/(.*)\??.*/, function (req, res) {
|
||||||
var link = req.params["0"].slice(1);
|
var link = req.params["0"].slice(1);
|
||||||
storage.getNote(link).then(note => {
|
if (CACHE.has(link)) res.send(CACHE.get(link));
|
||||||
res.send("opening note " + note.text)
|
else storage.getNote(link).then(note => {
|
||||||
|
var content = page.build(note);
|
||||||
|
CACHE.set(link, content);
|
||||||
|
res.send(content);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+3
-10
@@ -1,16 +1,9 @@
|
|||||||
var LRU = require("lru-cache"),
|
var marked = require("marked");
|
||||||
marked = require("marked"),
|
var fs = require("fs");
|
||||||
fs = require("fs");
|
|
||||||
|
|
||||||
var CACHE = new LRU(30); // create LRU cache of size 30
|
|
||||||
var template = fs.readFileSync("resources/template.html", "utf-8");
|
var template = fs.readFileSync("resources/template.html", "utf-8");
|
||||||
var buildHTML = (title, content) => template
|
var buildHTML = (title, content) => template
|
||||||
.replace("%TITLE%", title)
|
.replace("%TITLE%", title)
|
||||||
.replace("%CONTENT%", content);
|
.replace("%CONTENT%", content);
|
||||||
|
|
||||||
module.exports.build = id => {
|
module.exports.build = note => buildHTML(note.title, marked(note.text));
|
||||||
if (CACHE.has(id)) return CACHE.get(id);
|
|
||||||
var content = "This is page " + id;
|
|
||||||
CACHE.set(id, content);
|
|
||||||
return content;
|
|
||||||
};
|
|
||||||
|
|||||||
+4
-3
@@ -28,6 +28,7 @@ var Link = sequelize.define('Link', {
|
|||||||
Note.hasMany(Link);
|
Note.hasMany(Link);
|
||||||
Link.belongsTo(Note);
|
Link.belongsTo(Note);
|
||||||
|
|
||||||
module.exports.getNote = linkId => Link.findById(linkId).then(link => {
|
module.exports.getNote = linkId => {
|
||||||
return Note.findById(link.NoteId);
|
console.log("resolving note", linkId);
|
||||||
});
|
return Link.findById(linkId).then(link => Note.findById(link.NoteId));
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user