Converting static website to Hugo

Aug 21, 2020

While rebuilding my personal website I wanted to add my projects and blogs. Since I didn’t want to copy-paste a page for every project or blog I started looking for alternatives, and ended up at static site generator Hugo. A static site generator generates all pages as html files, so nothing needs to be done dynamically anymore.

Traditional HTML

A traditional website structure looks more or less like this

<!DOCTYPE html>
        <!-- A title, which is different for every page -->
    <!-- A navbar -->
      <!-- Content, which is different for each page -->
      <!-- A footer -->

As you can see, there are only two things that change. We are going to make use of this while converting the website to Hugo.

Creating the Hugo

First, install hugo on your system. On my Arch Linux system it is as simple as running

sudo pacman -S hugo

Next, create the site skeleton by running:

hugo new site <SITENAME>


After creating the website using the previous command, you end up with the following structure

└── your-site
    ├── archetypes
    │   └──
    ├── config.toml
    ├── content
    ├── data
    ├── layouts
    ├── static
    └── themes

We will create a new theme, in which we will port our exisiting website to a Hugo Theme.

hugo new theme <THEMENAME>

This command will create a folder in themes/ with the following structure.

    │   ├───partials
    │   └───_default

The first will we will look at is the baseof.html. This is the base of every other page and look like this.

<!DOCTYPE html>
    {{- partial "head.html" . -}}
        {{- partial "header.html" . -}}
        <div id="content">
        {{- block "main" . }}{{- end }}
        {{- partial "footer.html" . -}}

The first thing we notice the use of partial. This keyword will include a html file. The power of partials is that every part of your website is reusable if you make it a partial.

This article is a work in progress and will be finished in the future.

arrow-up icon