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