Files
reveal-hugo/layouts/partials/layout/javascript.html
T

52 lines
3.0 KiB
HTML

<!-- Printing and PDF exports -->
<!-- use Hugo to create the right path for the print stylesheet, then conditionally include it -->
{{- $reveal_location := $.Param "reveal_hugo.reveal_cdn" | default "reveal-js" -}}
<a href="{{ printf "%s/css/print/" $reveal_location | relURL }}" id="print-location" style="display: none;">
<script type="text/javascript">
var printLocationElement = document.getElementById('print-location');
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = printLocationElement.href + (window.location.search.match(/print-pdf/gi) ? 'pdf.css' : 'paper.css');
document.getElementsByTagName('head')[0].appendChild(link);
</script>
<!-- output Hugo parameters into JavaScript to be used when initializing Reveal.js -->
<script type="application/json" id="reveal-hugo-site-params">{{ jsonify .Site.Params.reveal_hugo | safeJS }}</script>
<script type="application/json" id="reveal-hugo-page-params">{{ jsonify .Page.Params.reveal_hugo | safeJS }}</script>
<!-- load Reveal.js javascripts -->
<script src="{{ printf "%s/lib/js/head.min.js" $reveal_location | relURL }}"></script>
<script src="{{ printf "%s/js/reveal.js" $reveal_location | relURL }}"></script>
<!-- load Reveal.js plugins -->
<script type="text/javascript" src="{{ printf "%s/plugin/markdown/marked.js" $reveal_location | relURL }}"></script>
<script type="text/javascript" src="{{ printf "%s/plugin/markdown/markdown.js" $reveal_location | relURL }}"></script>
<script type="text/javascript" src="{{ printf "%s/plugin/highlight/highlight.js" $reveal_location | relURL }}"></script>
<script type="text/javascript" src="{{ printf "%s/plugin/zoom-js/zoom.js" $reveal_location | relURL }}"></script>
<!-- always use local version of the notes plugin since HTML file it requires isn't on CDN -->
<script type="text/javascript" src="{{ "reveal-js/plugin/notes/notes.js" | relURL }}"></script>
<script type="text/javascript">
// Hugo lowercases all params and Reveal.js needs camelcase
// So params in Hugo must be stored in snakecase and we camelize them here
function camelize(map) {
if (map) {
Object.keys(map).forEach(function(k) {
newK = k.replace(/(\_\w)/g, function(m) { return m[1].toUpperCase() });
if (newK != k) {
map[newK] = map[k];
delete map[k];
}
});
}
return map;
}
// pattern inspired by https://github.com/RealOrangeOne/hugo-theme-revealjs
var revealHugoDefaults = { center: true, controls: true, history: true, progress: true, transition: "slide" };
var revealHugoSiteParams = JSON.parse(document.getElementById('reveal-hugo-site-params').innerHTML);
var revealHugoPageParams = JSON.parse(document.getElementById('reveal-hugo-page-params').innerHTML);
// See all options - https://github.com/hakimel/reveal.js#configuration
var options = Object.assign({},
camelize(revealHugoDefaults),
camelize(revealHugoSiteParams),
camelize(revealHugoPageParams));
Reveal.initialize(options);
hljs.initHighlightingOnLoad();
</script>