Jürgen's Notebook

I use Hugo together with the Relearn theme to create this website.

Install Hugo

You can install Hugo on your server. But since Hugo creates purely static web contents, I installed on my Linux laptop which runs Ubuntu. For Ubuntu, Hugo maintains newer versions only as a snap package. So in to do the installation just call:

sudo snap install hugo

Initial Setup of the Website

Note

Visit Hugo Quick Start and Relearn Documentation for a detailed introduction.

In your home directory you can create a new directory, e.g. src, if you do not already have it. Then move in this directory.

mkdir ~/src
cd ~/src

To create a new site with the Relearn theme enabled, just follow the instructions on Getting Started. Personally, I prefer the approach to install themes via Hugo’s module system.

With the command hugo server a webserver is started. Open http://localhost:1313 with your web browser to see your website. With CTRL+C you can stop the webserver.

Simply calling hugo will create a static version of the website in the folder ~/src/<your_site_name>/public. This folder will later be used by Caddy to provide the website to your audience.

If you are using git for source control, it is recommended to create a .gitignore file to exclude files in the directory, that are created by Hugo:

# ---> Hugo
# Generated files by hugo
/public/
/resources/_gen/
/assets/jsconfig.json
hugo_stats.json

# Temporary lock file while building
/.hugo_build.lock

Releasing the Website

To release the website, the contents of the public directory needs to be copied to your server. I recommend to create on server side a directory under the existing /usr/share/caddy folder:

On your server, execute:

sudo mkdir /usr/share/caddy/<your_site_name>
sudo chmod 777 /usr/share/caddy/<your_site_name>

The tool rsync can be used to publish the website. I created a script release.sh that does this and can be executed on my laptop:

#!/bin/bash

set +x

# build the site
hugo
# copy over the site to the server
rsync -v --delete --recursive ./public/ <your_server>:/usr/share/caddy/<your_site_name>/

Caddy Setup

The static website content is now available in the directory /usr/share/caddy/<your_site_name>. I assume you have created the domain website.example.com that can be used for providing the website on the internet.

Note

For a detailed documentation pleaser refer to the Caddy website.

Now you need to add following lines in the file /etc/caddy/Caddyfile:

website.example.com {
    root * /usr/share/caddy/<your_site_name>
    file_server
}

With following commands Caddy will read the new configuration and you can check for the status:

cd /etc/caddy
sudo caddy reload
sudo service caddy status

Caddy will serve the contents in /usr/share/caddy/<your_site_name> as website with the address https://website.example.com. An SSL certificate will be assigned and updated automatically.