Switching my website from Jekyll to Hugo and the reasons why
Why switching the website generator?
When I switched from Wordpress to Jekyll I was quite happy cause maintaining the site was much easier - cause everything is code. However, as I want to add more stuff than only blog posts including some non-english content, I tried adding multi-language support to my Jekyll-site, using jekyll-multiple-languages-plugin. As I was struggling to get it working quickly, I figured, maybe should sit down and see whether Jekyll is the right choice. back then I did not really look around, but just wanted to get rid of Wordpress. So this time let’s do some research.
Why Hugo
I eventually found https://jamstack.org/. As of today the page list 322 results, which is a lot of static website generator - too much to evaluate each one of them. So how to proceed then? Well obviously a good start is looking at the onces with most Github stars - apparently these frameworks seems very appealing to a lot of people.
Do be clear, mi intention is not to do a comparison of different frameworks as this would need a proper evaluation. I am just simply looking for something easy to use incl. multi-language support
Among the top project is not only Jekyll, but also others. So what I did is
looked into the documentation and the showcases
installed (some of) them and initialized a simple website
made some modifications to see how difficult it is to understand syntax and make changes
As I am no web developer I usually rely on cool open-source themes and then do my modifications - which is by the way really nice to get to know details. During my “evaluation” I eventually found DOKS - an amazing theme. It`s made with Hugo.
Thanks
Kudos to the guys from [DOKS], their theme is amazing
So while looking at this theme and try to do modifications I really got fond of Hugo and here is why. Hugo …
… is incredibly fast to build a site - much faster than other tools
… in contrary to Jekyll - which relies on plugins to add features - Hugo has it all-in-one
Sure this means if you are missing a feature it cannot be added as you could do with Jekyll. BUt I am fine with that
In Jekyll posts need to follow the format 2017-01-02-my-first-post.md. When working on drafts in Jekyll, you can skip yyyy-mm-ddd prefix of your post so the posts do not appear in the page. This means every time you want to publish you have to rename the post. I like Hugo`s approach much better.
snippets inside your content files calling built-in or custom templates
So how did I get started
As mentioned I started with DOKS and then modifying some things to my needs. Even so the documentation of Hugo is great I eventually had to reach out to the Community which is very cool and supportive.
Add a language switcher
First what I was missing is a language switcher, which allows me to switch the language if a translated page is available. So I added an language-switcher.html under layouts/partials/main which looks as follows:
Which then can be included in layouts/header/header.html as follows
As you can see, the aperance is configurable by the parameter in the params.toml
Adding some custom css and you get this result:
Logo on the upper left
On the upper left I prefer to show the logo instead of site title. So I add the following parameters to params.toml
Adding the following code to the layouts\header\header.html allows you to display yor site logo and/or text:
Contributors taxonomy
Taxonomies which are user-defined groupings of content. I want to show the author or contributor(s) of the blog post or page - at the moment this is usually only me but who knows what the future looks like.
First once has to specify the taxonomy in the config.toml
To show the information in the page, I made the following modifications to layouts/main/blog-meta.html:
Then one can define the parameter in the front matter:
1
2
3
4
5
6
7
8
9
10
11
12
---
title: "Switching Static Website Generator"
description: "Switching my website from Jekyll to Hugo and the reasons why"
lead: "Switching my website from Jekyll to Hugo and the reasons why"
date: 2021-02-16T07:36:13+02:00
lastmod: 2021-02-19T08:18:41+02:00
draft: false
weight: 50
images: ["website_new.png"]
contributors: ["Adrian Wyssmann"]
---
...
So that’s it, first thing accomplished. Now, when clicking on the contributor, one should see the details like social links etc.
For this to happen, I added a new data file data/social.yml
Then in the respective front matter of the page e.g content/en/contributors/adrian-wyssmann/index.md I then can add social parameters like this
So to use this, I create two partials. layouts/partials/main/social-icons.html which iterates over the list of social-parameters
The above calls layouts/partials/main/social-icon.html, which then renders the icon using FontAwesome:
At last, the social-icons.html is called within contributors/list.html template as follows:
{{ define "main" }}
<divclass="row justify-content-center">
<divclass="col-md-12 col-lg-10 col-xl-10">
<article>
<h1class="text-center">{{ if .Params.userimage}}
{{ partial "main/user-image.html" . }}{{ end -}} {{ .Title }}</h1>
<divclass="social">
{{ partial "main/social-icons.html" . }}
</div>
<divclass="text-center">{{ .Content }}</div>
<divclass="card-list">
{{ range .Data.Pages -}}
<divclass="card">
<divclass="card-body">
<h2class="h3"><aclass="stretched-link text-body"href="{{ .Permalink }}">{{ .Params.title }}</a></h2>
{{ if eq .Section "blog" -}}
<p>{{ .Params.lead | safeHTML }}</p>
{{ partial "main/blog-meta.html" . -}}
{{ end -}}
{{ if ne .Section "blog" -}}
<p>{{ .Params.description | safeHTML }}</p>
<divclass="social">
{{ partial "main/social-icons.html" . }}
</div>
{{ end -}}
</div>
</div>
{{ end -}}
</div>
</article>
</div>
</div>
{{ end }}
Final words
By accomplishing small tasks to make my site look as I imagine helped me a lot to learn and really like Hugo.
I am sure one can do the same things with the other Jamstack tools as well. However, I made my choice to use Hugo for all the reasons I mentioned above.