From 16990e35a209704aa7538bb3231085c11da05b06 Mon Sep 17 00:00:00 2001 From: Cheng-Han, Wu Date: Sun, 29 May 2016 17:54:24 +0800 Subject: Update slide template using ejs instead of mustache to reduce similar package dependency --- lib/config.js | 2 +- lib/response.js | 19 ++++++++--- package.json | 1 - public/views/slide.ejs | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ public/views/slide.hbs | 83 ------------------------------------------------ 5 files changed, 101 insertions(+), 89 deletions(-) create mode 100644 public/views/slide.ejs delete mode 100644 public/views/slide.hbs diff --git a/lib/config.js b/lib/config.js index 1f824d0a..9f11c5b5 100644 --- a/lib/config.js +++ b/lib/config.js @@ -38,7 +38,7 @@ var indexpath = config.indexpath || './public/views/index.ejs'; var hackmdpath = config.hackmdpath || './public/views/hackmd.ejs'; var errorpath = config.errorpath || './public/views/error.ejs'; var prettypath = config.prettypath || './public/views/pretty.ejs'; -var slidepath = config.slidepath || './public/views/slide.hbs'; +var slidepath = config.slidepath || './public/views/slide.ejs'; // session var sessionname = config.sessionname || 'connect.sid'; diff --git a/lib/response.js b/lib/response.js index 062bc5db..873dfe4e 100644 --- a/lib/response.js +++ b/lib/response.js @@ -18,7 +18,6 @@ var models = require("./models"); //slides var md = require('reveal.js/plugin/markdown/markdown'); -var Mustache = require('mustache'); //reveal.js var opts = { @@ -244,7 +243,6 @@ function showPublishNote(req, res, next) { function renderPublish(data, res) { var template = config.prettypath; var options = { - url: config.serverurl, cache: !config.debug, filename: template }; @@ -512,14 +510,27 @@ function showPublishSlide(req, res, next) { var render = function (res, title, markdown) { var slides = md.slidify(markdown, opts); - res.end(Mustache.to_html(opts.template, { + 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 buf = html; + res.writeHead(200, { + 'Content-Type': 'text/html; charset=UTF-8', + 'Cache-Control': 'private', + 'Content-Length': buf.length + }); + res.end(buf); }; module.exports = response; diff --git a/package.json b/package.json index 702d02c3..f49f1013 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,6 @@ "method-override": "^2.3.5", "moment": "^2.12.0", "morgan": "^1.7.0", - "mustache": "2.2.1", "mysql": "^2.10.2", "node-uuid": "^1.4.7", "passport": "^0.3.2", diff --git a/public/views/slide.ejs b/public/views/slide.ejs new file mode 100644 index 00000000..3a329261 --- /dev/null +++ b/public/views/slide.ejs @@ -0,0 +1,85 @@ + + +
+ + + + +