Skip to content

Instantly share code, notes, and snippets.

@jonashackt
Last active October 7, 2023 20:21
Show Gist options
  • Save jonashackt/85f9df62986db4e70396e3c494e26b76 to your computer and use it in GitHub Desktop.
Save jonashackt/85f9df62986db4e70396e3c494e26b76 to your computer and use it in GitHub Desktop.
Reveal.js presentation Markdown Pandoc GitHub Pages

Reveal.js presentation with Markdown

Workflow

  1. Create GitHub repo & write Markdown into README.md (all the time, as you do research)

  2. Create gh-pages Branch & Markdown for presentation

  3. Use Pandoc to convert Markdown into Reveal.js HTML (locally)

  4. Automatically publish Reveal.js Markdown on GitHub Pages with Pandoc & Travis CI

1. Create GitHub repo & write Markdown into README.md (all the time, as you do research)

Create new GitHub repository incl. README.md.

git clone https://github.com/yourUserName/yourRepoName.git

Now clone this repository & use the README.md as thought bin for everything about that topic that seems to be remarkable and may somehow find their way into the presentation later.

2. Prepare GitHub Pages & Markdown for presentation

If you've done enough research, create a new Markdown file presentation.md inside the repository.

This file uses Markdown that will be transformed to reveal.js powered HTML later. Here's an example:

% Title
% Name
% yyyy/mm/dd

# Header1

---

### Header3

- foo
- bar
- foobar

---

### header

1. foo
1. bar
1. baz

# HEADER

---

_foo_

__bar__

___baz___

[foobar_link](https://github.com/hakimel/reveal.js/#full-setup)

> foo bar  
> baz

A --- delimits slides, the rest is simple elegant Markdown :)

3. Use Pandoc to convert Markdown into Reveal.js HTML (locally)

Instead of Pandoc you could also use reveal.js' build in Markdown integration, but this seems to be a bit more error prone and pollutes the output of raw HTML or PDF. Another approach would be to use reveal-md.

Install pandoc:

brew install pandoc

Create a docs folder for the pandoc output:

mkdir docs

Run pandoc with the -t revealjs parameter (more details in the docs):

pandoc \
 --standalone \
 -t revealjs \
 -o docs/index.html \
 presentation.md \
 -V revealjs-url=https://revealjs.com \
 -V theme=solarized

Change your theme with the -V theme=yourChosenTheme parameter as you like.

4. Automatically publish Reveal.js Markdown on GitHub Pages with Pandoc & Travis CI

⚠️ If you have custom githubuser.github.io repo configured, this may lead to a accessible site: The problem is, that if you already configured a githubuser.github.io repo to serve a GitHub page - and configured it with a custom domain name, all the other repositories will try to use that custom domain name also - which won't work, since there's no CNAME configured etc. (see the docs, this issue and see this webapps.stackexchange q&a)

Travis CI can deploy your static files to GitHub Pages after a successful build (see docs)

Therefor create a .travis.yml inside your GitHub repository. It installs pandoc, creates the output directory docs and executes it to generate our reveal.js powered HTML:

---
before_install:
  # Install pandoc
  - sudo apt-get update
  - sudo apt-get -y install pandoc
  - pandoc --version

script:
  # create docs directory for pandoc output
  - mkdir docs
  # Generate reveal.js powered HTML from Markdown
  - pandoc --standalone -t revealjs -o docs/index.html presentation.md -V revealjs-url=https://revealjs.com -V theme=solarized

# Deploy to GitHub pages (see https://docs.travis-ci.com/user/deployment/pages/)
deploy:
  provider: pages
  local_dir: docs
  skip_cleanup: true
  github_token: $GITHUB_TOKEN  # Set in the settings page of your repository, as a secure variable
  keep_history: true
  on:
    branch: master

Then in the deploy section it deployes the static files to GitHub pages. The skip_cleanup: true parameter is important, otherwise our generated HTML will be lost before uploading to pages. Be also sure to generate a personal access token inside your GitHub settings at https://github.com/settings/tokens with the public_repo scope.

Then create a new environment variable inside your TravisCI project settings at https://travis-ci.org/yourGitHubName/yourRepoName/settings called GITHUB_TOKEN and fill in the generated token.

Finally add docs to your .gitignore file to prevent uploading the locally generated HTML and commit/push to your GitHub repository. Travis CI will automatically setup your repository to server GitHub pages after the first successfull run.

Links

https://ebildungslabor.de/blog/revealjs/

https://wittenbrink.net/lostandfound/praesentationen-mit-markdown-reveal-js-und-github-pages-mein-neuer-workflow/

https://medium.com/isovera/devops-for-presentations-reveal-js-markdown-pandoc-gitlab-ci-34d07d2c1011

https://lifelongprogrammer.blogspot.com/2019/03/building-presentations-with-reveal-js-markdown-and-github-pages.html

https://martinmurphy.tech/2018/04/using-github-pages-for-presentations/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment