2015-05-04 07:53:29 +00:00
|
|
|
//response
|
|
|
|
//external modules
|
|
|
|
var ejs = require('ejs');
|
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
|
|
|
var markdownpdf = require("markdown-pdf");
|
|
|
|
var LZString = require('lz-string');
|
2015-07-01 16:10:20 +00:00
|
|
|
var S = require('string');
|
|
|
|
var shortId = require('shortid');
|
2016-01-12 14:01:42 +00:00
|
|
|
var metaMarked = require('meta-marked');
|
2016-01-31 21:42:26 +00:00
|
|
|
var querystring = require('querystring');
|
|
|
|
var request = require('request');
|
2015-05-04 07:53:29 +00:00
|
|
|
|
|
|
|
//core
|
2016-04-20 10:03:55 +00:00
|
|
|
var config = require("./config.js");
|
|
|
|
var logger = require("./logger.js");
|
|
|
|
var models = require("./models");
|
2015-05-04 07:53:29 +00:00
|
|
|
|
2015-11-23 12:38:26 +00:00
|
|
|
//slides
|
|
|
|
var md = require('reveal.js/plugin/markdown/markdown');
|
|
|
|
var Mustache = require('mustache');
|
|
|
|
|
2015-11-29 07:04:20 +00:00
|
|
|
//reveal.js
|
2015-11-23 12:38:26 +00:00
|
|
|
var opts = {
|
2016-04-20 10:03:55 +00:00
|
|
|
template: fs.readFileSync(config.slidepath).toString(),
|
2015-11-29 07:04:20 +00:00
|
|
|
theme: 'css/theme/black.css',
|
2015-11-23 12:38:26 +00:00
|
|
|
highlightTheme: 'zenburn',
|
|
|
|
separator: '^(\r\n?|\n)---(\r\n?|\n)$',
|
|
|
|
verticalSeparator: '^(\r\n?|\n)----(\r\n?|\n)$',
|
|
|
|
revealOptions: {}
|
|
|
|
};
|
|
|
|
|
2015-05-04 07:53:29 +00:00
|
|
|
//public
|
|
|
|
var response = {
|
|
|
|
errorForbidden: function (res) {
|
2015-12-30 05:33:36 +00:00
|
|
|
responseError(res, "403", "Forbidden", "oh no.");
|
2015-05-04 07:53:29 +00:00
|
|
|
},
|
|
|
|
errorNotFound: function (res) {
|
2015-05-15 04:58:13 +00:00
|
|
|
responseError(res, "404", "Not Found", "oops.");
|
2015-05-04 07:53:29 +00:00
|
|
|
},
|
|
|
|
errorInternalError: function (res) {
|
2015-05-15 04:58:13 +00:00
|
|
|
responseError(res, "500", "Internal Error", "wtf.");
|
2015-05-04 07:53:29 +00:00
|
|
|
},
|
|
|
|
errorServiceUnavailable: function (res) {
|
2015-05-15 04:58:13 +00:00
|
|
|
res.status(503).send("I'm busy right now, try again later.");
|
2015-05-04 07:53:29 +00:00
|
|
|
},
|
|
|
|
newNote: newNote,
|
|
|
|
showNote: showNote,
|
2015-07-06 05:51:55 +00:00
|
|
|
showPublishNote: showPublishNote,
|
2015-11-23 12:38:26 +00:00
|
|
|
showPublishSlide: showPublishSlide,
|
2016-04-23 10:58:24 +00:00
|
|
|
showIndex: showIndex,
|
2015-07-01 16:10:20 +00:00
|
|
|
noteActions: noteActions,
|
2016-01-31 21:42:26 +00:00
|
|
|
publishNoteActions: publishNoteActions,
|
|
|
|
githubActions: githubActions
|
2015-05-04 07:53:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function responseError(res, code, detail, msg) {
|
|
|
|
res.writeHead(code, {
|
|
|
|
'Content-Type': 'text/html'
|
|
|
|
});
|
2015-07-01 16:10:20 +00:00
|
|
|
var template = config.errorpath;
|
2016-04-20 10:03:55 +00:00
|
|
|
var options = {
|
|
|
|
cache: !config.debug,
|
|
|
|
filename: template
|
|
|
|
};
|
|
|
|
var compiled = ejs.compile(fs.readFileSync(template, 'utf8'), options);
|
|
|
|
var content = compiled({
|
|
|
|
url: config.serverurl,
|
2015-07-01 16:10:20 +00:00
|
|
|
title: code + ' ' + detail + ' ' + msg,
|
2015-05-04 07:53:29 +00:00
|
|
|
cache: !config.debug,
|
2015-07-01 16:10:20 +00:00
|
|
|
filename: template,
|
2015-05-04 07:53:29 +00:00
|
|
|
code: code,
|
|
|
|
detail: detail,
|
2015-09-22 14:39:13 +00:00
|
|
|
msg: msg,
|
2016-05-15 02:54:24 +00:00
|
|
|
useCDN: config.usecdn
|
2015-05-04 07:53:29 +00:00
|
|
|
});
|
|
|
|
res.write(content);
|
|
|
|
res.end();
|
|
|
|
}
|
|
|
|
|
2015-09-22 04:06:13 +00:00
|
|
|
function showIndex(req, res, next) {
|
|
|
|
res.writeHead(200, {
|
|
|
|
'Content-Type': 'text/html'
|
|
|
|
});
|
|
|
|
var template = config.indexpath;
|
2016-04-20 10:03:55 +00:00
|
|
|
var options = {
|
|
|
|
cache: !config.debug,
|
|
|
|
filename: template
|
|
|
|
};
|
|
|
|
var compiled = ejs.compile(fs.readFileSync(template, 'utf8'), options);
|
|
|
|
var content = compiled({
|
|
|
|
url: config.serverurl,
|
|
|
|
useCDN: config.usecdn,
|
|
|
|
facebook: config.facebook,
|
|
|
|
twitter: config.twitter,
|
|
|
|
github: config.github,
|
2016-05-09 22:31:49 +00:00
|
|
|
gitlab: config.gitlab,
|
2016-05-15 02:54:24 +00:00
|
|
|
dropbox: config.dropbox
|
2015-09-22 04:06:13 +00:00
|
|
|
});
|
|
|
|
res.write(content);
|
|
|
|
res.end();
|
|
|
|
}
|
|
|
|
|
2016-04-20 10:03:55 +00:00
|
|
|
function responseHackMD(res, note) {
|
|
|
|
var body = LZString.decompressFromBase64(note.content);
|
|
|
|
var meta = null;
|
|
|
|
try {
|
|
|
|
meta = metaMarked(body).meta;
|
|
|
|
} catch(err) {
|
|
|
|
//na
|
|
|
|
}
|
|
|
|
var title = models.Note.decodeTitle(note.title);
|
|
|
|
title = models.Note.generateWebTitle(title);
|
|
|
|
var template = config.hackmdpath;
|
|
|
|
var options = {
|
|
|
|
cache: !config.debug,
|
|
|
|
filename: template
|
|
|
|
};
|
|
|
|
var compiled = ejs.compile(fs.readFileSync(template, 'utf8'), options);
|
|
|
|
var html = compiled({
|
|
|
|
url: config.serverurl,
|
|
|
|
title: title,
|
|
|
|
useCDN: config.usecdn,
|
|
|
|
robots: (meta && meta.robots) || false, //default allow robots
|
|
|
|
facebook: config.facebook,
|
|
|
|
twitter: config.twitter,
|
|
|
|
github: config.github,
|
2016-05-09 22:31:49 +00:00
|
|
|
gitlab: config.gitlab,
|
2016-05-15 03:02:15 +00:00
|
|
|
<<<<<<< HEAD
|
2016-05-15 02:54:24 +00:00
|
|
|
dropbox: config.dropbox
|
2016-05-15 03:02:15 +00:00
|
|
|
=======
|
2016-04-20 10:03:55 +00:00
|
|
|
dropbox: config.dropbox,
|
2016-05-15 03:02:15 +00:00
|
|
|
>>>>>>> 930afdc33738a487bd9e596c5d35bc9f686eaaa1
|
2015-05-04 07:53:29 +00:00
|
|
|
});
|
2016-04-20 10:03:55 +00:00
|
|
|
var buf = html;
|
|
|
|
res.writeHead(200, {
|
|
|
|
'Content-Type': 'text/html; charset=UTF-8',
|
|
|
|
'Cache-Control': 'private',
|
|
|
|
'Content-Length': buf.length
|
|
|
|
});
|
|
|
|
res.end(buf);
|
2015-05-04 07:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function newNote(req, res, next) {
|
|
|
|
var owner = null;
|
|
|
|
if (req.isAuthenticated()) {
|
2016-04-20 10:03:55 +00:00
|
|
|
owner = req.user.id;
|
2015-05-04 07:53:29 +00:00
|
|
|
}
|
2016-04-20 10:03:55 +00:00
|
|
|
models.Note.create({
|
|
|
|
ownerId: owner
|
|
|
|
}).then(function (note) {
|
|
|
|
return res.redirect(config.serverurl + "/" + LZString.compressToBase64(note.id));
|
|
|
|
}).catch(function (err) {
|
|
|
|
logger.error(err);
|
|
|
|
return response.errorInternalError(res);
|
2015-05-04 07:53:29 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-04-20 10:03:55 +00:00
|
|
|
function checkViewPermission(req, note) {
|
|
|
|
if (note.permission == 'private') {
|
|
|
|
if (!req.isAuthenticated() || note.ownerId != req.user.id)
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
2015-05-04 07:53:29 +00:00
|
|
|
}
|
|
|
|
|
2016-04-20 10:03:55 +00:00
|
|
|
function findNote(req, res, callback, include) {
|
|
|
|
var id = req.params.noteId || req.params.shortid;
|
|
|
|
models.Note.parseNoteId(id, function (err, _id) {
|
|
|
|
models.Note.findOne({
|
|
|
|
where: {
|
|
|
|
id: _id
|
|
|
|
},
|
|
|
|
include: include || null
|
|
|
|
}).then(function (note) {
|
|
|
|
if (!note) {
|
2016-01-17 15:51:27 +00:00
|
|
|
return response.errorNotFound(res);
|
|
|
|
}
|
2016-04-20 10:03:55 +00:00
|
|
|
if (!checkViewPermission(req, note)) {
|
|
|
|
return response.errorForbidden(res);
|
|
|
|
} else {
|
|
|
|
return callback(note);
|
2016-01-17 15:51:27 +00:00
|
|
|
}
|
2016-04-20 10:03:55 +00:00
|
|
|
}).catch(function (err) {
|
|
|
|
logger.error(err);
|
|
|
|
return response.errorInternalError(res);
|
2016-01-17 15:51:27 +00:00
|
|
|
});
|
|
|
|
});
|
2015-05-04 07:53:29 +00:00
|
|
|
}
|
|
|
|
|
2016-04-20 10:03:55 +00:00
|
|
|
function showNote(req, res, next) {
|
|
|
|
findNote(req, res, function (note) {
|
|
|
|
return responseHackMD(res, note);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-07-06 05:51:55 +00:00
|
|
|
function showPublishNote(req, res, next) {
|
2016-04-20 10:03:55 +00:00
|
|
|
var include = [{
|
|
|
|
model: models.User,
|
|
|
|
as: "owner"
|
|
|
|
}, {
|
|
|
|
model: models.User,
|
|
|
|
as: "lastchangeuser"
|
|
|
|
}];
|
|
|
|
findNote(req, res, function (note) {
|
|
|
|
note.increment('viewcount').then(function (note) {
|
|
|
|
if (!note) {
|
2016-01-17 15:51:27 +00:00
|
|
|
return response.errorNotFound(res);
|
2015-07-01 16:10:20 +00:00
|
|
|
}
|
2016-04-20 10:03:55 +00:00
|
|
|
var body = LZString.decompressFromBase64(note.content);
|
|
|
|
var meta = null;
|
|
|
|
try {
|
|
|
|
meta = metaMarked(body).meta;
|
|
|
|
} catch(err) {
|
|
|
|
//na
|
|
|
|
}
|
|
|
|
var createtime = note.createdAt;
|
|
|
|
var updatetime = note.lastchangeAt;
|
|
|
|
var text = S(body).escapeHTML().s;
|
|
|
|
var title = models.Note.decodeTitle(note.title);
|
|
|
|
title = models.Note.generateWebTitle(title);
|
|
|
|
var origin = config.serverurl;
|
|
|
|
var data = {
|
|
|
|
title: title,
|
|
|
|
viewcount: note.viewcount,
|
|
|
|
createtime: createtime,
|
|
|
|
updatetime: updatetime,
|
|
|
|
url: origin,
|
|
|
|
body: text,
|
|
|
|
useCDN: config.usecdn,
|
|
|
|
lastchangeuserprofile: note.lastchangeuser ? models.User.parseProfile(note.lastchangeuser.profile) : null,
|
|
|
|
robots: (meta && meta.robots) || false //default allow robots
|
|
|
|
};
|
|
|
|
return renderPublish(data, res);
|
|
|
|
}).catch(function (err) {
|
|
|
|
logger.error(err);
|
|
|
|
return response.errorInternalError(res);
|
2015-07-01 16:10:20 +00:00
|
|
|
});
|
2016-04-20 10:03:55 +00:00
|
|
|
}, include);
|
2015-07-01 16:10:20 +00:00
|
|
|
}
|
|
|
|
|
2016-01-12 14:01:42 +00:00
|
|
|
function renderPublish(data, res) {
|
|
|
|
var template = config.prettypath;
|
|
|
|
var options = {
|
2016-04-20 10:03:55 +00:00
|
|
|
url: config.serverurl,
|
2016-01-12 14:01:42 +00:00
|
|
|
cache: !config.debug,
|
|
|
|
filename: template
|
|
|
|
};
|
|
|
|
var compiled = ejs.compile(fs.readFileSync(template, 'utf8'), options);
|
|
|
|
var html = compiled(data);
|
|
|
|
var buf = html;
|
|
|
|
res.writeHead(200, {
|
|
|
|
'Content-Type': 'text/html; charset=UTF-8',
|
|
|
|
'Cache-Control': 'private',
|
|
|
|
'Content-Length': buf.length
|
|
|
|
});
|
|
|
|
res.end(buf);
|
|
|
|
}
|
|
|
|
|
2016-04-20 10:03:55 +00:00
|
|
|
function actionPublish(req, res, note) {
|
|
|
|
res.redirect(config.serverurl + "/s/" + (note.alias || note.shortid));
|
2015-07-01 16:10:20 +00:00
|
|
|
}
|
|
|
|
|
2016-04-20 10:03:55 +00:00
|
|
|
function actionSlide(req, res, note) {
|
|
|
|
res.redirect(config.serverurl + "/p/" + (note.alias || note.shortid));
|
2015-11-23 12:38:26 +00:00
|
|
|
}
|
2015-05-04 07:53:29 +00:00
|
|
|
|
2016-04-20 10:03:55 +00:00
|
|
|
function actionDownload(req, res, note) {
|
|
|
|
var body = LZString.decompressFromBase64(note.content);
|
|
|
|
var title = models.Note.decodeTitle(note.title);
|
|
|
|
var filename = title;
|
|
|
|
filename = encodeURIComponent(filename);
|
|
|
|
res.writeHead(200, {
|
|
|
|
'Access-Control-Allow-Origin': '*', //allow CORS as API
|
|
|
|
'Access-Control-Allow-Headers': 'Range',
|
|
|
|
'Access-Control-Expose-Headers': 'Cache-Control, Content-Encoding, Content-Range',
|
|
|
|
'Content-Type': 'text/markdown; charset=UTF-8',
|
|
|
|
'Cache-Control': 'private',
|
|
|
|
'Content-disposition': 'attachment; filename=' + filename + '.md',
|
|
|
|
'Content-Length': body.length,
|
|
|
|
'X-Robots-Tag': 'noindex, nofollow' // prevent crawling
|
2015-05-04 07:53:29 +00:00
|
|
|
});
|
2016-04-20 10:03:55 +00:00
|
|
|
res.end(body);
|
2015-05-04 07:53:29 +00:00
|
|
|
}
|
|
|
|
|
2016-04-20 10:03:55 +00:00
|
|
|
function actionPDF(req, res, note) {
|
|
|
|
var body = LZString.decompressFromBase64(note.content);
|
|
|
|
try {
|
|
|
|
body = metaMarked(body).markdown;
|
|
|
|
} catch(err) {
|
|
|
|
//na
|
|
|
|
}
|
|
|
|
var title = models.Note.decodeTitle(note.title);
|
2015-05-04 07:53:29 +00:00
|
|
|
|
2016-04-20 10:03:55 +00:00
|
|
|
if (!fs.existsSync(config.tmppath)) {
|
|
|
|
fs.mkdirSync(config.tmppath);
|
|
|
|
}
|
|
|
|
var path = config.tmppath + Date.now() + '.pdf';
|
|
|
|
markdownpdf().from.string(body).to(path, function () {
|
|
|
|
var stream = fs.createReadStream(path);
|
|
|
|
var filename = title;
|
|
|
|
// Be careful of special characters
|
|
|
|
filename = encodeURIComponent(filename);
|
|
|
|
// Ideally this should strip them
|
|
|
|
res.setHeader('Content-disposition', 'attachment; filename="' + filename + '.pdf"');
|
|
|
|
res.setHeader('Cache-Control', 'private');
|
|
|
|
res.setHeader('Content-Type', 'application/pdf; charset=UTF-8');
|
|
|
|
res.setHeader('X-Robots-Tag', 'noindex, nofollow'); // prevent crawling
|
|
|
|
stream.pipe(res);
|
|
|
|
fs.unlink(path);
|
2015-05-04 07:53:29 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-04-20 10:03:55 +00:00
|
|
|
function actionGist(req, res, note) {
|
|
|
|
var data = {
|
|
|
|
client_id: config.github.clientID,
|
|
|
|
redirect_uri: config.serverurl + '/auth/github/callback/' + LZString.compressToBase64(note.id) + '/gist',
|
|
|
|
scope: "gist",
|
|
|
|
state: shortId.generate()
|
|
|
|
};
|
|
|
|
var query = querystring.stringify(data);
|
|
|
|
res.redirect("https://github.com/login/oauth/authorize?" + query);
|
2016-01-31 21:42:26 +00:00
|
|
|
}
|
|
|
|
|
2015-05-04 07:53:29 +00:00
|
|
|
function noteActions(req, res, next) {
|
|
|
|
var noteId = req.params.noteId;
|
2016-04-20 10:03:55 +00:00
|
|
|
findNote(req, res, function (note) {
|
|
|
|
var action = req.params.action;
|
|
|
|
switch (action) {
|
|
|
|
case "publish":
|
|
|
|
case "pretty": //pretty deprecated
|
|
|
|
actionPublish(req, res, note);
|
|
|
|
break;
|
|
|
|
case "slide":
|
|
|
|
actionSlide(req, res, note);
|
|
|
|
break;
|
|
|
|
case "download":
|
|
|
|
actionDownload(req, res, note);
|
|
|
|
break;
|
|
|
|
case "pdf":
|
|
|
|
actionPDF(req, res, note);
|
|
|
|
break;
|
|
|
|
case "gist":
|
|
|
|
actionGist(req, res, note);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return res.redirect(config.serverurl + '/' + noteId);
|
|
|
|
break;
|
2015-05-04 07:53:29 +00:00
|
|
|
}
|
2016-01-17 15:51:27 +00:00
|
|
|
});
|
2015-05-04 07:53:29 +00:00
|
|
|
}
|
|
|
|
|
2015-07-06 05:51:55 +00:00
|
|
|
function publishNoteActions(req, res, next) {
|
2016-04-20 10:03:55 +00:00
|
|
|
findNote(req, res, function (note) {
|
|
|
|
var action = req.params.action;
|
|
|
|
switch (action) {
|
|
|
|
case "edit":
|
|
|
|
res.redirect(config.serverurl + '/' + (note.alias ? note.alias : LZString.compressToBase64(note.id)));
|
|
|
|
break;
|
|
|
|
default:
|
2016-04-23 10:58:24 +00:00
|
|
|
res.redirect(config.serverurl + '/s/' + note.shortid);
|
2016-04-20 10:03:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2015-07-01 16:10:20 +00:00
|
|
|
}
|
2016-01-31 21:42:26 +00:00
|
|
|
|
|
|
|
function githubActions(req, res, next) {
|
|
|
|
var noteId = req.params.noteId;
|
2016-04-20 10:03:55 +00:00
|
|
|
findNote(req, res, function (note) {
|
|
|
|
var action = req.params.action;
|
|
|
|
switch (action) {
|
|
|
|
case "gist":
|
|
|
|
githubActionGist(req, res, note);
|
|
|
|
break;
|
|
|
|
default:
|
2016-04-23 10:58:24 +00:00
|
|
|
res.redirect(config.serverurl + '/' + noteId);
|
2016-04-20 10:03:55 +00:00
|
|
|
break;
|
2016-01-31 21:42:26 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-04-20 10:03:55 +00:00
|
|
|
function githubActionGist(req, res, note) {
|
|
|
|
var code = req.query.code;
|
|
|
|
var state = req.query.state;
|
|
|
|
if (!code || !state) {
|
|
|
|
return response.errorForbidden(res);
|
|
|
|
} else {
|
|
|
|
var data = {
|
|
|
|
client_id: config.github.clientID,
|
|
|
|
client_secret: config.github.clientSecret,
|
|
|
|
code: code,
|
|
|
|
state: state
|
2016-01-31 21:42:26 +00:00
|
|
|
}
|
2016-04-20 10:03:55 +00:00
|
|
|
var auth_url = 'https://github.com/login/oauth/access_token';
|
|
|
|
request({
|
|
|
|
url: auth_url,
|
|
|
|
method: "POST",
|
|
|
|
json: data
|
|
|
|
}, function (error, httpResponse, body) {
|
|
|
|
if (!error && httpResponse.statusCode == 200) {
|
|
|
|
var access_token = body.access_token;
|
|
|
|
if (access_token) {
|
|
|
|
var content = LZString.decompressFromBase64(note.content);
|
|
|
|
var title = models.Note.decodeTitle(note.title);
|
|
|
|
var filename = title.replace('/', ' ') + '.md';
|
|
|
|
var gist = {
|
|
|
|
"files": {}
|
|
|
|
};
|
|
|
|
gist.files[filename] = {
|
|
|
|
"content": content
|
|
|
|
};
|
|
|
|
var gist_url = "https://api.github.com/gists";
|
|
|
|
request({
|
|
|
|
url: gist_url,
|
|
|
|
headers: {
|
|
|
|
'User-Agent': 'HackMD',
|
|
|
|
'Authorization': 'token ' + access_token
|
|
|
|
},
|
|
|
|
method: "POST",
|
|
|
|
json: gist
|
|
|
|
}, function (error, httpResponse, body) {
|
|
|
|
if (!error && httpResponse.statusCode == 201) {
|
|
|
|
res.setHeader('referer', '');
|
|
|
|
res.redirect(body.html_url);
|
|
|
|
} else {
|
|
|
|
return response.errorForbidden(res);
|
|
|
|
}
|
|
|
|
});
|
2016-01-31 21:42:26 +00:00
|
|
|
} else {
|
|
|
|
return response.errorForbidden(res);
|
|
|
|
}
|
2016-04-20 10:03:55 +00:00
|
|
|
} else {
|
|
|
|
return response.errorForbidden(res);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2016-01-31 21:42:26 +00:00
|
|
|
}
|
2015-07-01 16:10:20 +00:00
|
|
|
|
2015-11-23 12:38:26 +00:00
|
|
|
function showPublishSlide(req, res, next) {
|
2016-04-20 10:03:55 +00:00
|
|
|
findNote(req, res, function (note) {
|
|
|
|
note.increment('viewcount').then(function (note) {
|
|
|
|
if (!note) {
|
2016-01-17 15:51:27 +00:00
|
|
|
return response.errorNotFound(res);
|
2015-11-23 12:38:26 +00:00
|
|
|
}
|
2016-04-20 10:03:55 +00:00
|
|
|
var body = LZString.decompressFromBase64(note.content);
|
|
|
|
try {
|
|
|
|
body = metaMarked(body).markdown;
|
|
|
|
} catch(err) {
|
|
|
|
//na
|
|
|
|
}
|
|
|
|
var title = models.Note.decodeTitle(note.title);
|
|
|
|
title = models.Note.generateWebTitle(title);
|
|
|
|
var text = S(body).escapeHTML().s;
|
|
|
|
render(res, title, text);
|
|
|
|
}).catch(function (err) {
|
|
|
|
logger.error(err);
|
|
|
|
return response.errorInternalError(res);
|
2015-11-23 12:38:26 +00:00
|
|
|
});
|
2016-04-20 10:03:55 +00:00
|
|
|
});
|
2015-11-23 12:38:26 +00:00
|
|
|
}
|
|
|
|
|
2015-11-29 07:04:20 +00:00
|
|
|
//reveal.js render
|
2015-12-18 15:40:52 +00:00
|
|
|
var render = function (res, title, markdown) {
|
2015-11-29 07:04:20 +00:00
|
|
|
var slides = md.slidify(markdown, opts);
|
|
|
|
|
|
|
|
res.end(Mustache.to_html(opts.template, {
|
2016-04-20 10:03:55 +00:00
|
|
|
url: config.serverurl,
|
2015-12-18 15:40:52 +00:00
|
|
|
title: title,
|
2015-11-29 07:04:20 +00:00
|
|
|
theme: opts.theme,
|
|
|
|
highlightTheme: opts.highlightTheme,
|
|
|
|
slides: slides,
|
|
|
|
options: JSON.stringify(opts.revealOptions, null, 2)
|
|
|
|
}));
|
2015-11-23 12:38:26 +00:00
|
|
|
};
|
|
|
|
|
2016-04-23 10:58:24 +00:00
|
|
|
module.exports = response;
|