Browse Source

markdown enabled

master
Christian Müller 10 years ago
parent
commit
36c166d10b
  1. 4
      resources/public/index.html
  2. 6
      resources/template.html
  3. 10
      server.js
  4. 13
      src/page.js
  5. 7
      src/storage.js

4
resources/public/index.html

@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
<title>NoteHub &mdash; 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 @@ @@ -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">

6
resources/template.html

@ -4,13 +4,11 @@ @@ -4,13 +4,11 @@
<title>NoteHub &mdash; %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&amp;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>
%CONTENT%
</article>
</body>
</html>
</html>

10
server.js

@ -1,7 +1,10 @@ @@ -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) { @@ -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);
});
});

13
src/page.js

@ -1,16 +1,9 @@ @@ -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));

7
src/storage.js

@ -28,6 +28,7 @@ var Link = sequelize.define('Link', { @@ -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));
}

Loading…
Cancel
Save