So you’ve decided to make a static site blog⌗


I’m a sysadmin. I know computers. I should be able to get something like Hugo working, right? Right!?

I run a WordPress site for my kendo club and lately I’ve been reading about security concerns and governence issues with WordPress. So I thought “I’ll read up on self-hosted blogging alternatives”. I listen to the Late Night Linux family of podcasts and I heard them talking about Hugo. Let’s give that a shot I though. Here’s my lessons learned, and learning, from that experience.

Technology Stack⌗

First off: the stack. I have a VPS running Ubuntu 22.04. I serve web pages using NGINX with certs provided by Let’s Encrypt. I have DNS hosting and use their management console for my records. I also have PHP-FPM installed but it’s not relevant to Hugo because Hugo creates static sites in HTML. I’ve done a fair amount of configuration in my life and I can get a PHP app working behind an NGINX reverse proxy. I’m even proxying some Docker apps. I like to run things non-containerized but I can follow docs and get things going if I have to.

Hugo + GitHub Setup⌗

Making a site in Hugo can be done on almost any machine. I’d rather work in an IDE than on the VPS so I’m setting up Git access on both. I’ll do the content creation on my Mac, run hugo to generate the static pages, push it to Git and then pull it on the VPS. To get things started I did the following:

  • Installed Hugo via brew on MacOS. If you don’t have HomeBrew you can install it using these directions brew update && brew install hugo This installed Hugo 0.143.1 which appears to support Hugo Enhanced

  • Made a directory called hugo_testing in my home folder

  • Hugo uses the hugo command to do all its actions. I created a new site by running this in the hugo_testing folder (Note - the –force option is in case you already did git init and the directory isn’t empty. I ended up doing this multiple times.) hugo new site . --force

  • Made a new git project using git init

  • Set up SSH access for Github. Add the lines below to ~/.ssh/config Host github.com IdentityFile ~/.ssh/[your private key] IdentitiesOnly yes

  • Set the remote repository for this project to my repo in Github. This makes you authenticate with your SSH key, which ought to be password-protected. remote add origin git@github.com:redshiftltd/hugo_testing.git

  • Add the files to the local repo git add .

  • Make a new commit git commit -a -m "initial commit"

  • Push that data to the Github repo git push -v origin main

That’s the initial setup done. Now on to configuring Hugo and making ‘content’.


Hugo Structure⌗

Hugo has as interesting structure and doesn’t really need a lot of assets to make a few static pages. The basic setup is

Website Root Directory
           |
           |-> 'content' folder
                    |
                    |-> Subfolders with your posts/images/media files
           |-> 'layouts' folder
                    |
                    |-> '\_default' folder that supplies the default layout of the site
                    |-> 'partials' folder that holds re-usable code 
           |-> 'public' folder. Hugo makes this when you run the hugo command. Don't touch anything in here
           |-> 'resources' folder. I think this holds css/scss code
           |-> 'static' folder. Dunno? I don't have anything in here yet
           |-> 'themes' folder. Holds themes that [you can browse here](https://themes.gohugo.io/)
           hugo.toml -> Main config file
           .gitmodules -> Listing of submodules, usually themes, that your site uses

Defaults in hugo are prefaced by _[pagename] for example _index.md If _index.md exists in a folder under ‘content’ it will provide the main post content to the page in that directory. I think for subdirectories it can also provide a template if a ’normal’ index.md doesn’t exist.

Hugo has ‘page bundles’, directories that contain both content and resources. They also use a ’leaves and branches’ approach to pages. Branches can contain leaves but not vice versa. Leaves generally contain an index.md file but branches generally contain a _index.md file. _index.md can be used as the default page for any leaf/branch. I’ve been using it as a table of contents page for high level pages.

Front Matter⌗

Hugo stores metadata for each page at the top of each file and calls it ‘front matter’. Many attributes can be defined here, called parameters. Those parameters can then be accessed using a double curly brace notation like

{{ .Params.Author }}

Default front matter attributes are :

  • title
  • date
  • draft status

Taxonomies⌗

Grouping pages can be done with taxonomies. These are set in the front matter using the tags: attribute and/or using the categories: attribute. Syntax is below:

+++
date = '{{ .Date }}'
draft = true
title = '{{ replace .File.ContentBaseName "-" " " | title }}'
tags: ["tag1", "tag2"]
categories: ["cat1", "cat2"]
+++

Taxonomies aren’t visible by default but can be displayed. Hugo will aggregate pages based on tags and categories and create a list template page for all pages with a given tag/category. Hugo also supports arbitrary values for taxonomies using the same syntax but they need to be declared in the hugo.toml file. Note - the definition needs to be singular = “plural”. Also note that you need to define Hugo’s default taxonomies if you choose to extend them.

[taxonomies]
  tag = "tags"
  category = "categories"
  mood = "moods"
+++
date = '{{ .Date }}'
draft = true
title = '{{ replace .File.ContentBaseName "-" " " | title }}'
tags: ["tag1", "tag2"]
categories: ["cat1", "cat2"]
moods: ["Happy", "Energizing"]
+++

Archtypes⌗

Archtypes are used to define custom front matter for new pages. In the archtypes folder of your Hugo installation you’ll find the file default.md that defines the front matter:

+++
date = '{{ .Date }}'
draft = true
title = '{{ replace .File.ContentBaseName "-" " " | title }}'
+++

Notice how the date is auto generated. Draft is set to true. The title is generated from the filename in content/ and replaces - characters with spaces. You can customize this. If you want to have an Author attribute you can set it like so:

+++
date = '{{ .Date }}'
author = "Brandon"
draft = true
title = '{{ replace .File.ContentBaseName "-" " " | title }}'
+++

Customizing Archtypes⌗

Archtypes can be set for specific content directories as well. In the archtypes directory create a file called *directoryname.md* with that file created when you run hugo new content/*directory*/*filename*.md hugo will look for any available archtypes with that directory defined and use the values there instead of the defaults.

Creating Content⌗

To make a new page go to the /var/www/html/*subdomain.your_website_name*.com/ folder and run the command hugo new content/*folder_name*/*page_name*.md This will create a new file, page_name.md with the proper ‘front matter’ that gets interpreted by Hugo to create and render the page. An example of front matter is below. Note the draft = false line, which defaults to true. If you don’t set that to false then Hugo will hide the page until you do.

+++
date = '2025-02-14T17:23:30-05:00'
draft = false
title = 'Chana Masala'
+++

Under the +++ you can add anything to create your page. Hugo uses Markdown and some Hugo specific shortcodes to display content.

Resources (images, video, etc) are referenced from the /content directory. The code below displays an image from the content/soups_stews_chilis/ directory:


  
Chana Masala
Chana Masala

Shortcodes⌗

Hugo has a lot of pre-defined shortcodes that allow for common web functions without you having to program them.

{{< shortcote name parameter >}}

For example, you can embed a YouTube video using the syntax below:

{{< youtube 2xkNJL4gJ9E >}}

Pulling Content⌗

On the server sign in as root Go to the site directory -> cd /var/www/html/subdomain.your_website_name.com Pull the updated files -> git pull git@github.com:/your_repo_name.git Check the site -> https://subdomain.your_website_name.com

Themes⌗

As of this writing Hugo has about 300 themes hosted here. Themes go in the /var/www/html/subdomain.your_website_name.com/themes directory. Integrating them into Hugo is not as simple as just downloading the theme into a new folder though. You need to either:

- Integrate the theme as a Hugo module (I don't know how to do this yet)

- Make Git aware of the theme as a submodule

So far I’ve tried out the Re-Terminal and Risotto themes. Here’s how I installed the Terminal theme based on the author’s docs:

cd /var/www/html/*subdomain.your_website_name*.com/

git clone https://github.com/mirus-ua/hugo-theme-re-terminal.git themes/re-terminal

git submodule add -f https://github.com/mirus-ua/hugo-theme-re-terminal.git themes/re-terminal

Note: To see what submodules you have in your project edit the file .gitmodules

You can play with the new theme locally using hugo server -t re-terminal and navigating to http://localhost:1313 The file hugo.toml contains settings that themes need to work correctly. You’ll have to check the theme documentation to see what needs to be customized. I’ve been saving hugo.toml files as `hugo.toml_themename`` in case I want to switch them around.

Customizing Themes⌗