summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/response.js83
1 files changed, 83 insertions, 0 deletions
diff --git a/lib/response.js b/lib/response.js
index 486a1f76..6503e0a8 100644
--- a/lib/response.js
+++ b/lib/response.js
@@ -16,6 +16,23 @@ var config = require("../config.js");
var db = require("./db.js");
var Note = require("./note.js");
+//slides
+var md = require('reveal.js/plugin/markdown/markdown');
+var Mustache = require('mustache');
+
+var opts = {
+ userBasePath: process.cwd(),
+ revealBasePath: path.resolve(require.resolve('reveal.js'), '..', '..'),
+ template: fs.readFileSync(path.join('.', 'templates', 'reveal.html')).toString(),
+ templateListing: fs.readFileSync(path.join('.', 'templates', 'listing.html')).toString(),
+ theme: 'css/theme/league.css',
+ highlightTheme: 'zenburn',
+ separator: '^(\r\n?|\n)---(\r\n?|\n)$',
+ verticalSeparator: '^(\r\n?|\n)----(\r\n?|\n)$',
+ revealOptions: {}
+};
+
+
//public
var response = {
errorForbidden: function (res) {
@@ -34,6 +51,7 @@ var response = {
showFeatures: showFeatures,
showNote: showNote,
showPublishNote: showPublishNote,
+ showPublishSlide: showPublishSlide,
showIndex: showIndex,
noteActions: noteActions,
publishNoteActions: publishNoteActions
@@ -231,6 +249,26 @@ function actionPublish(req, res, noteId) {
});
}
+function actionSlide(req, res, noteId) {
+ db.readFromDB(noteId, function (err, data) {
+ if (err) {
+ responseError(res, "404", "Not Found", "oops.");
+ return;
+ }
+ var owner = data.rows[0].owner;
+ var permission = "freely";
+ if (owner && owner != "null") {
+ permission = "editable";
+ }
+ Note.findOrNewNote(noteId, permission, function (err, note) {
+ if (err) {
+ responseError(res, "404", "Not Found", "oops.");
+ return;
+ }
+ res.redirect("/p/" + note.shortid);
+ });
+ });
+}
//pretty api is deprecated
function actionPretty(req, res, noteId) {
db.readFromDB(noteId, function (err, data) {
@@ -327,6 +365,9 @@ function noteActions(req, res, next) {
case "pretty": //pretty deprecated
actionPublish(req, res, noteId);
break;
+ case "slide":
+ actionSlide(req, res, noteId);
+ break;
case "download":
actionDownload(req, res, noteId);
break;
@@ -363,4 +404,46 @@ function publishNoteActions(req, res, next) {
}
}
+
+function showPublishSlide(req, res, next) {
+ var shortid = req.params.shortid;
+ if (shortId.isValid(shortid)) {
+ Note.findNote(shortid, function (err, note) {
+ if (err || !note) {
+ responseError(res, "404", "Not Found", "oops.");
+ return;
+ }
+ //increase note viewcount
+ Note.increaseViewCount(note, function (err, note) {
+ if (err || !note) {
+ responseError(res, "404", "Not Found", "oops.");
+ return;
+ }
+ db.readFromDB(note.id, function (err, data) {
+ if (err) {
+ responseError(res, "404", "Not Found", "oops.");
+ return;
+ }
+ var body = LZString.decompressFromBase64(data.rows[0].content);
+ var text = S(body).escapeHTML().s;
+ render(res, text);
+ });
+ });
+ });
+ } else {
+ responseError(res, "404", "Not Found", "oops.");
+ }
+}
+var render = function(res, markdown) {
+ var slides = md.slidify(markdown, opts);
+
+ res.end(Mustache.to_html(opts.template, {
+ theme: opts.theme,
+ highlightTheme: opts.highlighTheme,
+ slides: slides,
+ options: JSON.stringify(opts.revealOptions, null, 2)
+ }));
+};
+
+
module.exports = response;