summaryrefslogtreecommitdiff
path: root/lib/response.js
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/response.js50
1 files changed, 28 insertions, 22 deletions
diff --git a/lib/response.js b/lib/response.js
index 5d7fc0a1..133d7a37 100644
--- a/lib/response.js
+++ b/lib/response.js
@@ -21,7 +21,7 @@ var models = require("./models");
var md = require('reveal.js/plugin/markdown/markdown');
//reveal.js
-var opts = {
+var slideOptions = {
template: fs.readFileSync(config.slidepath).toString(),
theme: 'css/theme/black.css',
highlightTheme: 'zenburn',
@@ -107,7 +107,7 @@ function responseHackMD(res, note) {
var body = LZString.decompressFromBase64(note.content);
var meta = null;
try {
- meta = metaMarked(body).meta;
+ meta = models.Note.parseMeta(metaMarked(body).meta);
} catch(err) {
//na
}
@@ -121,7 +121,7 @@ function responseHackMD(res, note) {
var compiled = ejs.compile(fs.readFileSync(template, 'utf8'), options);
var html = compiled({
url: config.serverurl,
- title: title,
+ title: meta.title || title,
useCDN: config.usecdn,
facebook: config.facebook,
twitter: config.twitter,
@@ -212,7 +212,7 @@ function showPublishNote(req, res, next) {
var body = LZString.decompressFromBase64(note.content);
var meta = null;
try {
- meta = metaMarked(body).meta;
+ meta = models.Note.parseMeta(metaMarked(body).meta);
} catch(err) {
//na
}
@@ -223,7 +223,8 @@ function showPublishNote(req, res, next) {
title = models.Note.generateWebTitle(title);
var origin = config.serverurl;
var data = {
- title: title,
+ title: meta.title || title,
+ description: meta.description,
viewcount: note.viewcount,
createtime: createtime,
updatetime: updatetime,
@@ -231,7 +232,8 @@ function showPublishNote(req, res, next) {
body: text,
useCDN: config.usecdn,
lastchangeuserprofile: note.lastchangeuser ? models.User.parseProfile(note.lastchangeuser.profile) : null,
- robots: (meta && meta.robots) || false //default allow robots
+ robots: meta.robots || false, //default allow robots
+ GA: meta.GA
};
return renderPublish(data, res);
}).catch(function (err) {
@@ -527,14 +529,28 @@ function showPublishSlide(req, res, next) {
}
var body = LZString.decompressFromBase64(note.content);
try {
- body = metaMarked(body).markdown;
+ var obj = metaMarked(body);
+ body = obj.markdown;
+ meta = models.Note.parseMeta(obj.meta);
} catch(err) {
//na
}
+ var text = S(body).escapeHTML().s;
var title = models.Note.decodeTitle(note.title);
title = models.Note.generateWebTitle(title);
- var text = S(body).escapeHTML().s;
- render(res, title, text);
+ var slides = md.slidify(text, slideOptions);
+ var origin = config.serverurl;
+ var data = {
+ url: origin,
+ title: meta.title || title,
+ description: meta.description,
+ theme: slideOptions.theme,
+ highlightTheme: slideOptions.highlightTheme,
+ slides: slides,
+ options: JSON.stringify(slideOptions.revealOptions, null, 2),
+ GA: meta.GA
+ };
+ return renderPublishSlide(data, res);
}).catch(function (err) {
logger.error(err);
return response.errorInternalError(res);
@@ -542,24 +558,14 @@ function showPublishSlide(req, res, next) {
});
}
-//reveal.js render
-var render = function (res, title, markdown) {
- var slides = md.slidify(markdown, opts);
-
+function renderPublishSlide(data, res) {
var template = config.slidepath;
var options = {
cache: !config.debug,
filename: template
};
var compiled = ejs.compile(fs.readFileSync(template, 'utf8'), options);
- var html = compiled({
- url: config.serverurl,
- title: title,
- theme: opts.theme,
- highlightTheme: opts.highlightTheme,
- slides: slides,
- options: JSON.stringify(opts.revealOptions, null, 2)
- });
+ var html = compiled(data);
var buf = html;
res.writeHead(200, {
'Content-Type': 'text/html; charset=UTF-8',
@@ -567,6 +573,6 @@ var render = function (res, title, markdown) {
'Content-Length': buf.length
});
res.end(buf);
-};
+}
module.exports = response;