You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.3 KiB
41 lines
1.3 KiB
|
10 years ago
|
var marked = require("marked");
|
||
|
|
var fs = require("fs");
|
||
|
11 years ago
|
|
||
|
10 years ago
|
var pageTemplate = fs.readFileSync("resources/template.html", "utf-8");
|
||
|
10 years ago
|
var footerTemplate = fs.readFileSync("resources/footer.html", "utf-8");
|
||
|
10 years ago
|
var editTemplate = fs.readFileSync("resources/edit.html", "utf-8");
|
||
|
10 years ago
|
|
||
|
|
var deriveTitle = text => text
|
||
|
|
.split(/[\n\r]/)[0].slice(0,25)
|
||
|
|
.replace(/[^a-zA-Z0-9\s]/g, "");
|
||
|
|
|
||
|
10 years ago
|
var buildPage = (title, content, footer) => pageTemplate
|
||
|
10 years ago
|
.replace("%TITLE%", title)
|
||
|
10 years ago
|
.replace("%CONTENT%", content)
|
||
|
|
.replace("%FOOTER%", footer);
|
||
|
|
|
||
|
|
module.exports.buildPage = buildPage;
|
||
|
11 years ago
|
|
||
|
10 years ago
|
module.exports.buildStats = note => buildPage(deriveTitle(note.text),
|
||
|
|
`<h2>Statistics</h2>
|
||
|
|
<table>
|
||
|
|
<tr><td>Published</td><td>${note.published}</td></tr>
|
||
|
|
<tr><td>Edited</td><td>${note.edited || "N/A"}</td></tr>
|
||
|
|
<tr><td>Views</td><td>${note.views}</td></tr>
|
||
|
|
</table>`,
|
||
|
|
"");
|
||
|
|
|
||
|
|
module.exports.buildNote = note => buildPage(deriveTitle(note.text),
|
||
|
10 years ago
|
marked(note.text),
|
||
|
|
footerTemplate.replace(/%LINK%/g, note.id));
|
||
|
10 years ago
|
|
||
|
10 years ago
|
module.exports.newNotePage = session => editTemplate
|
||
|
10 years ago
|
.replace("%ACTION%", "POST")
|
||
|
10 years ago
|
.replace("%SESSION%", session)
|
||
|
|
.replace("%CONTENT%", "Loading...");
|
||
|
|
|
||
|
|
module.exports.editNotePage = (session, note) => editTemplate
|
||
|
10 years ago
|
.replace("%ACTION%", "UPDATE")
|
||
|
10 years ago
|
.replace("%SESSION%", session)
|
||
|
10 years ago
|
.replace("%ID%", note.id)
|
||
|
10 years ago
|
.replace("%CONTENT%", note.text);
|