Remove need for a data file in the theme

This removes an extra step in params lookup and works around a bug in Hugo introduced after 0.37 that causes theme data files not to be found in certain circumstances.
This commit is contained in:
dzello 2018-08-07 17:43:24 +02:00
parent 31dca11944
commit 51623a07af
3 changed files with 22 additions and 24 deletions

View File

@ -290,11 +290,11 @@ You can use all the additional slide shortcode attributes. They will be applied
Customize the Reveal.js presentation by setting these values in `config.toml` or the front matter of any presentation's `_index.md` file.
- `params.reveal_hugo.theme`: The Reveal.js theme used, defaults to "black"
- `params.reveal_hugo.custom_theme`: The path to a locally hosted Reveal.js theme
- `params.reveal_hugo.highlight_theme`: The [highlight.js](https://highlightjs.org/) theme used, defaults to "default"
- `params.reveal_hugo.reveal_cdn`: The location to load Reveal.js files from, defaults to `https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.6.0`
- `params.reveal_hugo.highlight_cdn`: The location to load highlight.js files from, defaults to `https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0`
- `reveal_hugo.theme`: The Reveal.js theme used, defaults to "black"
- `reveal_hugo.custom_theme`: The path to a locally hosted Reveal.js theme
- `reveal_hugo.highlight_theme`: The [highlight.js](https://highlightjs.org/) theme used, defaults to "default"
- `reveal_hugo.reveal_cdn`: The location to load Reveal.js files from, defaults to `https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.6.0`
- `reveal_hugo.highlight_cdn`: The location to load highlight.js files from, defaults to `https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0`
This is how parameters will look in your `config.toml`:
@ -312,7 +312,17 @@ theme = "moon"
Include any other attributes in those sections that you'd like to be fed as arguments to `Reveal.initialize` in **snakecase**, so `slide_number` instead of `slideNumber`. Params are converted from snakecase to camelcase before passing to Reveal.js. This is necessary to maintain the proper case of the parameters.
See the [extensive list of Reveal.js configuration options](https://github.com/hakimel/reveal.js/#configuration) here. Several defaults used by this theme are located in `data/reveal_hugo.toml`.
Here's an example of configuring Reveal.js parameters alongside a theme and highlight.js theme:
```TOML
[reveal_hugo]
theme = "moon"
highlight_theme = "solarized-dark"
slide_number = true
transition = "zoom"
```
See the [extensive list of Reveal.js configuration options](https://github.com/hakimel/reveal.js/#configuration) here.
## Adding HTML to the layout
@ -328,7 +338,7 @@ If your Hugo site already has a theme but you'd like to create a presentation fr
cd my-hugo-site
git clone git@github.com:dzello/reveal-hugo.git themes/reveal-hugo
cd themes/reveal-hugo
cp -r data layouts static ../../
cp -r layouts static ../../
```
Files and directories are named such that they shouldn't conflict with your existing content. Of course, you should double check before copying, especially the shortcodes which can't be put under a directory.

View File

@ -1,11 +0,0 @@
[defaults]
theme = 'black'
highlight_theme = 'default'
controls = true
progress = true
history = true
center = true
transition = 'slide' # none/fade/slide/convex/concave/zoom
reveal_cdn = "https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.6.0"
highlight_cdn = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0"

View File

@ -1,6 +1,6 @@
<!doctype html>
{{- $reveal_cdn := or .Page.Params.reveal_hugo.reveal_cdn .Site.Params.reveal_hugo.reveal_cdn .Site.Data.reveal_hugo.defaults.reveal_cdn "https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.6.0" -}}
{{- $highlight_cdn := or .Page.Params.reveal_hugo.highlight_cdn .Site.Params.reveal_hugo.highlight_cdn .Site.Data.reveal_hugo.defaults.highlight_cdn "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0" -}}
{{- $reveal_cdn := or .Page.Params.reveal_hugo.reveal_cdn .Site.Params.reveal_hugo.reveal_cdn "https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.6.0" -}}
{{- $highlight_cdn := or .Page.Params.reveal_hugo.highlight_cdn .Site.Params.reveal_hugo.highlight_cdn "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0" -}}
<html lang="en">
<head>
<meta charset="utf-8">
@ -38,9 +38,8 @@
</head>
<body>
{{- block "main" . -}}{{- end -}}
<script type="application/json" id="reveal-hugo-page-params">{{ jsonify .Page.Params.reveal_hugo | safeJS }}</script>
<script type="application/json" id="reveal-hugo-site-params">{{ jsonify .Site.Params.reveal_hugo | safeJS }}</script>
<script type="application/json" id="reveal-hugo-defaults">{{ jsonify .Site.Data.reveal_hugo.defaults | safeJS }}</script>
<script type="application/json" id="reveal-hugo-page-params">{{ jsonify .Page.Params.reveal_hugo | safeJS }}</script>
<script type="text/javascript">
window.revealHugoDependencies = {
dependencies: [
@ -71,9 +70,9 @@
return map;
}
// pattern inspired by https://github.com/RealOrangeOne/hugo-theme-revealjs
var revealHugoPageParams = JSON.parse(document.getElementById('reveal-hugo-page-params').innerHTML);
var revealHugoDefaults = { center: true, controls: true, history: true, progress: true, transition: "slide" };
var revealHugoSiteParams = JSON.parse(document.getElementById('reveal-hugo-site-params').innerHTML);
var revealHugoDefaults = JSON.parse(document.getElementById('reveal-hugo-defaults').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),