Skip to content

Another reveal.js plugin for Jekyll

dev

I use Jekyll to create my course websites and reveal.js to create my lecture slides. Both of them are awesome, and allow me to focus on writing (hopefully) great content, and the formatting/presentation stuff stays out of the way until I git push the updates to the server.

There are a few ways of making these two tools (Jekyll and reveal.js) play nicely together: see here and here for example. However, most of these require you to put each slide in a new .md file, which is a pain.

What I want to do is to write one .md file per presentation, and have the level 1 and level 2 headings (i.e. # and ##) determine the slide splits (this is pretty much how pandoc does it).

I wrote a simple Jekyll plugin to make this happen—which has just a couple of moving parts

Because the source for this

whole blog is on GH, then you can just head there and see it for yourself if you’re the sort of person who prefers reading code to prose. Think of this blog post as a “companion piece”.

0. download the reveal.js source

It’s step 0 because it’s super easy—just head to GitHub, download & unzip the latest release. You can put it wherever you like in your main site folder; I usually put it in assets/.

1. the revealify filter

First, put this code into a revealify.rb file in your Jekyll _plugins directory.

2. add a reveal layout

You’ll need a new layout as well: create a reveal.html file in your Jekyll _layouts directory and make sure that the body tag has this in it (you’ll need to make sure it’s got the right paths & other stuff for your setup). The key part is that first 0 line—that takes the content of your page (the jekyll .md file with layout: reveal in the frontmatter) and passes it through the “revealify” filter plugin we made earlier.

The configuration stuff here is just the example config from reveal.js, so feel free to tweak to suit your own presentation.

html
<!-- this is where the reveailfy filter gets applied -->
{{ content | revealify }}

<!-- load the reveal.js css & js (assuming you've put it in assets/)-->
<link rel="stylesheet" href="/assets/reveal.js-3.8.0/css/reveal.css" />
<link rel="stylesheet" href="/assets/reveal.js-3.8.0/css/theme/white.css" />
<!-- Script removed during migration -->

<!-- configure the presentation, (you can tweak options to suit) -->
<!-- Script removed during migration -->

The full layout file will depend

on how the rest of your site works (where you’ve put the reveal.js-x.x.x folder, etc.) so I haven’t included the full file here (you can see it on GitHub, though). Also remember that you can see the full list of reveal configuration options in the README. :::

3. write your slides as markdown content

Finally, write your content as a regular jekyll post which uses the reveal layout, e.g.

md
---
title: "Week 1: intro"
layout: reveal
---

## Intro

- welcome to the course
- we're gonna learn all the things

## Timeline

- first, we'll sit in boring lectures...
- ... then, there will be a huge exam!

fun times.

Then, you get all the niceties of the jekyll watch cycle; livereload, auto-compilation of scss assets, etc.

And if you need to do something interesting with the formatting or layout of your content, then you can just drop straight into writing HTML (as you can always do in a markdown file).

4. write amazing content

This is the hard part. But at least if you’ve got a nice workflow for actually turning your content into nice looking slides then you’ve got a head start 😃