mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-20 02:05:21 -04:00
Add Slide Mode
using reveal.js and some part of reveal-md
This commit is contained in:
parent
75ae505a15
commit
f51b7370f0
81 changed files with 14277 additions and 7 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue