Update slide template using ejs instead of mustache to reduce similar package dependency

This commit is contained in:
Cheng-Han, Wu 2016-05-29 17:54:24 +08:00
parent c73c32d127
commit 16990e35a2
5 changed files with 101 additions and 89 deletions

View file

@ -38,7 +38,7 @@ var indexpath = config.indexpath || './public/views/index.ejs';
var hackmdpath = config.hackmdpath || './public/views/hackmd.ejs'; var hackmdpath = config.hackmdpath || './public/views/hackmd.ejs';
var errorpath = config.errorpath || './public/views/error.ejs'; var errorpath = config.errorpath || './public/views/error.ejs';
var prettypath = config.prettypath || './public/views/pretty.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 // session
var sessionname = config.sessionname || 'connect.sid'; var sessionname = config.sessionname || 'connect.sid';

View file

@ -18,7 +18,6 @@ var models = require("./models");
//slides //slides
var md = require('reveal.js/plugin/markdown/markdown'); var md = require('reveal.js/plugin/markdown/markdown');
var Mustache = require('mustache');
//reveal.js //reveal.js
var opts = { var opts = {
@ -244,7 +243,6 @@ function showPublishNote(req, res, next) {
function renderPublish(data, res) { function renderPublish(data, res) {
var template = config.prettypath; var template = config.prettypath;
var options = { var options = {
url: config.serverurl,
cache: !config.debug, cache: !config.debug,
filename: template filename: template
}; };
@ -512,14 +510,27 @@ function showPublishSlide(req, res, next) {
var render = function (res, title, markdown) { var render = function (res, title, markdown) {
var slides = md.slidify(markdown, opts); 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, url: config.serverurl,
title: title, title: title,
theme: opts.theme, theme: opts.theme,
highlightTheme: opts.highlightTheme, highlightTheme: opts.highlightTheme,
slides: slides, slides: slides,
options: JSON.stringify(opts.revealOptions, null, 2) 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; module.exports = response;

View file

@ -30,7 +30,6 @@
"method-override": "^2.3.5", "method-override": "^2.3.5",
"moment": "^2.12.0", "moment": "^2.12.0",
"morgan": "^1.7.0", "morgan": "^1.7.0",
"mustache": "2.2.1",
"mysql": "^2.10.2", "mysql": "^2.10.2",
"node-uuid": "^1.4.7", "node-uuid": "^1.4.7",
"passport": "^0.3.2", "passport": "^0.3.2",

85
public/views/slide.ejs Normal file
View file

@ -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>

View file

@ -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>