<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Revealjs on Haseeb Majid</title>
    <link>https://haseebmajid.dev/tags/revealjs/</link>
    <description>Recent content in Revealjs on Haseeb Majid</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <lastBuildDate>Sun, 26 May 2024 00:00:00 +0000</lastBuildDate><atom:link href="https://haseebmajid.dev/tags/revealjs/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>How to Add reveal-hugo to a Hugo Site</title>
      <link>https://haseebmajid.dev/posts/2024-05-26-how-to-add-hugo-revealjs-to-a-hugo-site/</link>
      <pubDate>Sun, 26 May 2024 00:00:00 +0000</pubDate>
      <author>Me</author>
      <guid>https://haseebmajid.dev/posts/2024-05-26-how-to-add-hugo-revealjs-to-a-hugo-site/</guid>
      <description>&lt;p&gt;What we are trying to achieve is hosting RevealJS slides on our Hugo blog like
&lt;a href=&#34;https://haseebmajid.dev/slides/reproducible-envs-with-nix/#/&#34;&gt;this example slide deck&lt;/a&gt;.
The markdown the slides are built from is in
&lt;a href=&#34;https://gitlab.com/hmajid2301/blog/-/blob/main/content/slides/reproducible-envs-with-nix/_index.md&#34;&gt;the slide source&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;background&#34;&gt;Background&lt;/h2&gt;
&lt;p&gt;Recently, I did a talk at the Conf42 conference &lt;a href=&#34;../../talks/reproducible-envs-with-nix&#34;&gt;shameless plug here&lt;/a&gt;. At
the time I was working on the slides using &lt;a href=&#34;https://revealjs.com/&#34;&gt;Reveal.js&lt;/a&gt;, as I did for all of my slides
as I can create a slideshow using just plain markdown. I hosted all of my talks in a separate
&lt;a href=&#34;https://gitlab.com/hmajid2301/talks&#34;&gt;repository&lt;/a&gt;. Which published to a simple &lt;a href=&#34;https://talks.haseebmajid.dev/&#34;&gt;site&lt;/a&gt;.&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>What we are trying to achieve is hosting RevealJS slides on our Hugo blog like
<a href="https://haseebmajid.dev/slides/reproducible-envs-with-nix/#/">this example slide deck</a>.
The markdown the slides are built from is in
<a href="https://gitlab.com/hmajid2301/blog/-/blob/main/content/slides/reproducible-envs-with-nix/_index.md">the slide source</a>.</p>
<h2 id="background">Background</h2>
<p>Recently, I did a talk at the Conf42 conference <a href="/talks/reproducible-envs-with-nix">shameless plug here</a>. At
the time I was working on the slides using <a href="https://revealjs.com/">Reveal.js</a>, as I did for all of my slides
as I can create a slideshow using just plain markdown. I hosted all of my talks in a separate
<a href="https://gitlab.com/hmajid2301/talks">repository</a>. Which published to a simple <a href="https://talks.haseebmajid.dev/">site</a>.</p>
<p>However, I wanted to move all the talks into a blog so I could manage all in one place. As I already had a section
for my talks, which then linked to this other site. I then came across this
<a href="https://github.com/joshed-io/reveal-hugo">project</a>.</p>
<h2 id="getting-started">Getting Started</h2>
<p>Let&rsquo;s assume you already have a Hugo site, and we will add reveal-hugo to it. If not, you can follow this simple
<a href="https://gohugo.io/getting-started/quick-start/#explanation-of-commands">getting started guide</a>. To set up a basic
Hugo site.</p>
<h3 id="issues">Issues</h3>
<p>So one problem I found with adding reveal-hugo was to get code highlighting using highlight-js, we need to turn off
code fences on our Hugo site. Which means we need to use the Hugo short code to add code blocks to our blog posts.
Which means instead of doing:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">```md
</span></span></code></pre></div><p>We need to do:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-go" data-lang="go"><span class="line"><span class="cl"><span class="nx"><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">199
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-go" data-lang="go"><span class="line"><span class="cl"><span class="c1">// ... code</span></span></span></code></pre></td></tr></table>
</div>
</div></span><span class="w">
</span></span></span></code></pre></div><p>But we have to specify the style everytime as well (from what I recall). So in the end I decided just to have two Hugo
sites in the same repository. My main one which would be hosted at <code>haseebmajid.dev</code> then my slides one which which use
<code>haseebmajid.dev/slides/</code>. During the build process we would run <code>hugo &amp;&amp; hugo --config hugo-slides.toml</code>. Then our
site is available in <code>public</code> folder.</p>
<p>Let me know if you know a better way to solve this problem, but it works well enough for now if a bit &ldquo;hacky&rdquo;.</p>
<h2 id="add-reveal-hugo">Add reveal-hugo</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">hugo mod init example
</span></span><span class="line"><span class="cl">hugo mod get github.com/dzello/reveal-hugo
</span></span></code></pre></div><p>Create another hugo file for the slides.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">nvim hugo-slides.toml
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-toml" data-lang="toml"><span class="line"><span class="cl"><span class="nx">baseURL</span> <span class="p">=</span> <span class="s2">&#34;https://example.com/slides&#34;</span>
</span></span><span class="line"><span class="cl"><span class="nx">title</span> <span class="p">=</span> <span class="s2">&#34;Example Blog&#34;</span>
</span></span><span class="line hl"><span class="cl"><span class="nx">theme</span> <span class="p">=</span> <span class="p">[</span><span class="s2">&#34;github.com/dzello/reveal-hugo&#34;</span><span class="p">]</span>
</span></span><span class="line hl"><span class="cl"><span class="nx">contentDir</span> <span class="p">=</span> <span class="s2">&#34;content/slides&#34;</span>
</span></span><span class="line hl"><span class="cl"><span class="nx">publishDir</span> <span class="p">=</span> <span class="s2">&#34;public/slides&#34;</span>
</span></span><span class="line hl"><span class="cl"><span class="nx">staticDir</span> <span class="p">=</span> <span class="s2">&#34;static/slides&#34;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="p">[</span><span class="nx">markup</span><span class="p">.</span><span class="nx">highlight</span><span class="p">]</span>
</span></span><span class="line"><span class="cl"><span class="nx">codeFences</span> <span class="p">=</span> <span class="kc">false</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="p">[</span><span class="nx">markup</span><span class="p">.</span><span class="nx">goldmark</span><span class="p">.</span><span class="nx">renderer</span><span class="p">]</span>
</span></span><span class="line"><span class="cl"><span class="nx">unsafe</span> <span class="p">=</span> <span class="kc">true</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="p">[</span><span class="nx">outputFormats</span><span class="p">.</span><span class="nx">Reveal</span><span class="p">]</span>
</span></span><span class="line"><span class="cl"><span class="nx">baseName</span> <span class="p">=</span> <span class="s2">&#34;index&#34;</span>
</span></span><span class="line"><span class="cl"><span class="nx">mediaType</span> <span class="p">=</span> <span class="s2">&#34;text/html&#34;</span>
</span></span><span class="line"><span class="cl"><span class="nx">isHTML</span> <span class="p">=</span> <span class="kc">true</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="p">[</span><span class="nx">sitemap</span><span class="p">]</span>
</span></span><span class="line"><span class="cl"><span class="nx">changefreq</span> <span class="p">=</span> <span class="s2">&#34;monthly&#34;</span>
</span></span><span class="line"><span class="cl"><span class="nx">filename</span> <span class="p">=</span> <span class="s2">&#34;sitemap.xml&#34;</span>
</span></span><span class="line"><span class="cl"><span class="nx">priority</span> <span class="p">=</span> <span class="mf">0.5</span>
</span></span></code></pre></div><p>The key points here being we are looking at:</p>
<p>First we add the reveal-hugo module as a theme.</p>
<p>Then contentDir, where it will look for our content i.e. markdown for our slides.</p>
<p>Then publishDir where the site will be built when we run <code>hugo --config hugo-slides.toml</code>. Cannot be <code>publish</code> because
it will overwrite our main site.</p>
<p>Finally staticDir, where the slides will look for static content like CSS.</p>
<p>Within our <code>hugo.toml</code> file add the following:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-toml" data-lang="toml"><span class="line"><span class="cl"><span class="nx">baseURL</span> <span class="p">=</span> <span class="s2">&#34;https://example.com/&#34;</span>
</span></span><span class="line"><span class="cl"><span class="nx">title</span> <span class="p">=</span> <span class="s2">&#34;Example&#34;</span>
</span></span><span class="line"><span class="cl"><span class="nx">paginate</span> <span class="p">=</span> <span class="mi">25</span>
</span></span><span class="line"><span class="cl"><span class="nx">enableRobotsTXT</span> <span class="p">=</span> <span class="kc">true</span>
</span></span><span class="line"><span class="cl"><span class="nx">buildDrafts</span> <span class="p">=</span> <span class="kc">false</span>
</span></span><span class="line"><span class="cl"><span class="nx">buildFuture</span> <span class="p">=</span> <span class="kc">false</span>
</span></span><span class="line"><span class="cl"><span class="nx">buildExpired</span> <span class="p">=</span> <span class="kc">false</span>
</span></span><span class="line"><span class="cl"><span class="nx">enableEmoji</span> <span class="p">=</span> <span class="kc">true</span>
</span></span><span class="line hl"><span class="cl"><span class="nx">ignorefiles</span> <span class="p">=</span> <span class="p">[</span><span class="s2">&#34;content/slides&#34;</span><span class="p">]</span>
</span></span></code></pre></div><p>So when building the main site it will not build for our slides.</p>
<h3 id="new-slides">New Slides</h3>
<p>Add new slides, assuming we are at the root of our hugo project (where <code>hugo.toml</code> and <code>hugo-slides.toml</code> are).
Notice the <code>contentDir</code> above, hence we put into the <code>content/slides</code> folder.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">mkdir -p content/slides/first-talk
</span></span><span class="line"><span class="cl">touch content/slides/first-talk/_index.md
</span></span></code></pre></div><p>Then in our <code>_index.md</code> file we want to do something like:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-md" data-lang="md"><span class="line"><span class="cl">+++
</span></span><span class="line"><span class="cl">title = &#34;Reproducible &amp; Ephemeral Development Environments with Nix&#34;
</span></span><span class="line"><span class="cl">outputs = [&#34;Reveal&#34;]
</span></span><span class="line"><span class="cl">+++
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="gh"># Hello world!
</span></span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">This is my first slide.
</span></span></code></pre></div><p><code>hugo server --config hugo-slides.toml</code>, we can now access the slides at <code>http://localhost:1313/slides/first-talk/#/</code>.
You can look at the <a href="https://github.com/dzello/reveal-hugo">README</a> for more information about syntax.</p>
<h3 id="add-theme">Add Theme</h3>
<p>If we want to add a custom theme to our site we can do something like in our frontmatter:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-md" data-lang="md"><span class="line"><span class="cl">+++
</span></span><span class="line"><span class="cl">title = &#34;Reproducible &amp; Ephemeral Development Environments with Nix&#34;
</span></span><span class="line"><span class="cl">outputs = [&#34;Reveal&#34;]
</span></span><span class="line"><span class="cl">[reveal_hugo]
</span></span><span class="line hl"><span class="cl">custom_theme = &#34;stylesheets/reveal/catppuccin.css&#34;
</span></span><span class="line hl"><span class="cl">slide_number = true
</span></span><span class="line"><span class="cl">+++
</span></span></code></pre></div><p>Where the stylesheet can be found in <code>static/slides/stylesheets/reveal/catppuccin.css</code>.  You could also have a separate
theme for styling, but I put them into a single CSS file to make my life a bit easier. But you may prefer them
in two separate files to make them easier to share between slides.</p>
<p>That&rsquo;s it! We added reveal-hugo to our existing Hugo blog whilst keeping existing syntax highlighting working.
It wasn&rsquo;t the most elegant solution, but as I said earlier it works well enough for me!</p>
<h2 id="appendix">Appendix</h2>
<ul>
<li><a href="https://gitlab.com/hmajid2301/blog">My Hugo Blog</a></li>
</ul>
]]></content:encoded>
    </item>
    
  </channel>
</rss>
