summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCheng-Han, Wu2016-05-29 17:54:24 +0800
committerCheng-Han, Wu2016-05-29 17:54:24 +0800
commit16990e35a209704aa7538bb3231085c11da05b06 (patch)
tree0e7a6ed0534559b4ee5cab6bb5e214776b3d9825
parentc73c32d12759a44c46b18548e7d1ef3fc1678473 (diff)
Update slide template using ejs instead of mustache to reduce similar package dependency
Diffstat (limited to '')
-rw-r--r--lib/config.js2
-rw-r--r--lib/response.js19
-rw-r--r--package.json1
-rw-r--r--public/views/slide.ejs85
-rw-r--r--public/views/slide.hbs83
5 files changed, 101 insertions, 89 deletions
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 @@
+<!doctype html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <meta name="apple-mobile-web-app-capable" content="yes">
+ <meta name="apple-mobile-web-app-status-bar-style" content="black">
+ <meta name="mobile-web-app-capable" content="yes">
+ <title><%- title %></title>
+ <link rel="icon" type="image/png" href="<%- url %>/favicon.png">
+ <link rel="apple-touch-icon" href="<%- url %>/apple-touch-icon.png">
+
+ <link rel="stylesheet" href="<%- url %>/vendor/reveal.js/css/reveal.css">
+ <link rel="stylesheet" href="<%- url %>/vendor/reveal.js/<%- theme %>" id="theme">
+ <!-- For syntax highlighting -->
+ <link rel="stylesheet" href="<%- url %>/vendor/reveal.js/lib/css/<%- highlightTheme %>.css">
+ <link rel="stylesheet" href="<%- url %>/css/site.css">
+ <link rel="stylesheet" href="<%- url %>/css/slide.css">
+
+ <!-- If the query includes 'print-pdf', use the PDF print sheet -->
+ <script>
+ document.write( '<link rel="stylesheet" href="<%- url %>/vendor/reveal.js/css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' );
+ </script>
+ <script src="<%- url %>/vendor/jquery/dist/jquery.min.js"></script>
+ <script src="<%- url %>/vendor/velocity/velocity.min.js"></script>
+ </head>
+ <body>
+
+ <div class="reveal">
+ <div class="slides"><%- slides %></div>
+ </div>
+
+ <script src="<%- url %>/vendor/reveal.js/lib/js/head.min.js"></script>
+ <script src="<%- url %>/vendor/reveal.js/js/reveal.js"></script>
+ <script src="<%- url %>/vendor/string.min.js"></script>
+ <script src="<%- url %>/vendor/xss/dist/xss.min.js"></script>
+ <script src="<%- url %>/js/render.js"></script>
+
+ <script>
+ if (typeof mixpanel !== 'undefined') mixpanel.track("enter slide");
+
+ var body = $(".slides").html();
+ $(".slides").html(S(body).unescapeHTML().s);
+
+ function extend() {
+ var target = {};
+ for (var i = 0; i < arguments.length; i++) {
+ var source = arguments[i];
+ for (var key in source) {
+ if (source.hasOwnProperty(key)) {
+ target[key] = source[key];
+ }
+ }
+ }
+ return target;
+ }
+
+ // Optional libraries used to extend on reveal.js
+ var deps = [
+ { src: '<%- url %>/vendor/reveal.js/lib/js/classList.js', condition: function() { return !document.body.classList; } },
+ { src: '<%- url %>/vendor/reveal.js/plugin/markdown/marked.js', condition: function() { return !!document.querySelector('[data-markdown]'); } },
+ { src: '<%- url %>/js/reveal-markdown.js', condition: function() { return !!document.querySelector('[data-markdown]'); } },
+ { src: '<%- url %>/vendor/reveal.js/plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
+ { src: '<%- url %>/vendor/reveal.js/plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } },
+ { src: '<%- url %>/vendor/reveal.js/plugin/math/math.js', async: true }
+ ];
+
+ // default options to init reveal.js
+ var defaultOptions = {
+ controls: true,
+ progress: true,
+ history: true,
+ center: true,
+ transition: 'slide',
+ dependencies: deps
+ };
+
+ // options from URL query string
+ var queryOptions = Reveal.getQueryHash() || {};
+
+ var options = <%- options %>;
+ options = extend(defaultOptions, options, queryOptions);
+ Reveal.initialize(options);
+ </script>
+ </body>
+</html>
diff --git a/public/views/slide.hbs b/public/views/slide.hbs
deleted file mode 100644
index e2e2e9ae..00000000
--- a/public/views/slide.hbs
+++ /dev/null
@@ -1,83 +0,0 @@
-<!doctype html>
-<html lang="en">
- <head>
- <meta charset="utf-8">
- <meta name="apple-mobile-web-app-capable" content="yes">
- <meta name="apple-mobile-web-app-status-bar-style" content="black">
- <meta name="mobile-web-app-capable" content="yes">
- <title>{{title}}</title>
- <link rel="icon" type="image/png" href="{{{url}}}/favicon.png">
- <link rel="apple-touch-icon" href="{{{url}}}/apple-touch-icon.png">
-
- <link rel="stylesheet" href="{{{url}}}/vendor/reveal.js/css/reveal.css">
- <link rel="stylesheet" href="{{{url}}}/vendor/reveal.js/{{{theme}}}" id="theme">
- <!-- For syntax highlighting -->
- <link rel="stylesheet" href="{{{url}}}/vendor/reveal.js/lib/css/{{{highlightTheme}}}.css">
- <link rel="stylesheet" href="{{{url}}}/css/site.css">
- <link rel="stylesheet" href="{{{url}}}/css/slide.css">
-
- <!-- If the query includes 'print-pdf', use the PDF print sheet -->
- <script>
- document.write( '<link rel="stylesheet" href="{{{url}}}/vendor/reveal.js/css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' );
- </script>
- <script src="{{{url}}}/vendor/jquery/dist/jquery.min.js"></script>
- <script src="{{{url}}}/vendor/velocity/velocity.min.js"></script>
- </head>
- <body>
-
- <div class="reveal">
- <div class="slides">{{{slides}}}</div>
- </div>
-
- <script src="{{{url}}}/vendor/reveal.js/lib/js/head.min.js"></script>
- <script src="{{{url}}}/vendor/reveal.js/js/reveal.js"></script>
- <script src="{{{url}}}/vendor/string.min.js"></script>
- <script src="{{{url}}}/vendor/xss/dist/xss.min.js"></script>
- <script src="{{{url}}}/js/render.js"></script>
-
- <script>
- var body = $(".slides").html();
- $(".slides").html(S(body).unescapeHTML().s);
-
- function extend() {
- var target = {};
- for (var i = 0; i < arguments.length; i++) {
- var source = arguments[i];
- for (var key in source) {
- if (source.hasOwnProperty(key)) {
- target[key] = source[key];
- }
- }
- }
- return target;
- }
-
- // Optional libraries used to extend on reveal.js
- var deps = [
- { src: '{{{url}}}/vendor/reveal.js/lib/js/classList.js', condition: function() { return !document.body.classList; } },
- { src: '{{{url}}}/vendor/reveal.js/plugin/markdown/marked.js', condition: function() { return !!document.querySelector('[data-markdown]'); } },
- { src: '{{{url}}}/js/reveal-markdown.js', condition: function() { return !!document.querySelector('[data-markdown]'); } },
- { src: '{{{url}}}/vendor/reveal.js/plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
- { src: '{{{url}}}/vendor/reveal.js/plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } },
- { src: '{{{url}}}/vendor/reveal.js/plugin/math/math.js', async: true }
- ];
-
- // default options to init reveal.js
- var defaultOptions = {
- controls: true,
- progress: true,
- history: true,
- center: true,
- transition: 'slide',
- dependencies: deps
- };
-
- // options from URL query string
- var queryOptions = Reveal.getQueryHash() || {};
-
- var options = {{{options}}};
- options = extend(defaultOptions, options, queryOptions);
- Reveal.initialize(options);
- </script>
- </body>
-</html>