All The Hugo Themes
Using Python to preview my Hugo site with many themes
post / hugo python programmingMy site does well enough with Hugo and a custom theme, but I wanted to explore the themes repository. So I wrote some Python.
Updates
- 2016-01-04
- Added instructions for installing dependencies with Homebrew, and clarified some content based on comments from the Hugo community.
- 2016-01-03
- My checkout of the themes repository was out of date. I refreshed it this morning, resulting in a new GIF.
If you followed the Hugo Quickstart then you probably already have your own copy of the themes to use. Otherwise you might want to clone the hugoThemes repo with git.
Code
The idea here is to ask Hugo to build and serve the site once for each theme. For each built theme, ask the browser to load and screenshot the site with that theme.
I chose Python for this task. No special reason. I was just in a Python mood that day.
Splinter provided the browser controlling API. Since I’m using Chrome for this, I installed the Chrome WebDriver. The subprocess standard library module allowed me to control Hugo, restarting with a fresh theme once the browser had enough time to grab a screenshot.
Then I had a last minute idea: use the convert utility from ImageMagick to collect all the screenshots into an animated GIF.
You may need to install dependencies. Everything you need should be available for your platform, but I still need to double check that. Here are the steps I followed to get things working with Homebrew on my Mac.
All right - that’s out of the way. Now for some code.
The Result
Aside from a few dozen PNG files? Well, there’s that nifty animation. Animated GIFs give me a headache sometimes, so I will link to the GIF instead.
Observations
I noticed a few things with this experiment.
Configuration
Themes vary significantly in their expected configuration options. Some
want social media links under author
. Others wanted them in Params
.
gravatarHash
and GravatarHash
are two distinct options. Many have
hard-coded assumptions in their layouts: an image file
/img/avatar.jpg
, for example. Sometimes it’s called /media/me.jpg
though.
This is not an issue if you pick a favorite from the themes repository
and make your site work with your favorite. It is an issue if you’re
looking at your site in every theme. I turned my config.yaml
into sort
of a mess to make it work with more of the themes.
Layout
Although many themes focus on blog content, some have a different purpose. Their authors may have created them with project documentation, portfolios, or company sites in mind. Their structure is more complex or requires metadata beyond a simple blog.
I like this variety. I find that it’s much easier to create sites with different purposes using Hugo than when using Jekyll.
But it does help understand why sometimes the site renders as an attractive blank space in my preview. Examining the theme README would be a good next step if a particular theme interested me.
Well - reading documentation for the thing you’re using is generally a good idea anyways.
Sections
The themes seemed a little confused by my #craft section. Some
ignored craft projects completely. Others integrated them with posts on the
index.html
listing. Most at least provided a menu link to the section. And
yes, the theme README
would likely remove my confusion.
You will probably need to customize your template if you have special content.
What Theme Should I Use?
Maybe you were wondering which theme you could use for your new site. I suggest Hyde-X for blog sites. It has nice defaults, and provides quality documentation for its many configuration options. My site started with Hyde-X as a base before moving in its own direction.
Hyde-X isn’t the only way to start. There are numerous excellent blog-focused themes in the repository.
For non-blog sites? I don’t know, to be honest. None of my content worked well with those. Good luck with your search!
Anyways, the important thing is to have fun.