2024-02-04 23:33:11 +01:00
---
title: 'Hugo'
date: 2024-02-04T17:41:46+01:00
2024-06-13 14:09:28 +02:00
weight: 3
2024-02-04 23:33:11 +01:00
---
After some years of manually creating`.html` source files I switch to using a
2024-02-29 15:41:18 +01:00
static site generator[^1]. I got used to the Markdown[^2] format and like the
2024-02-04 23:33:11 +01:00
idea of self-contained applications. Thus, the [Hugo ](https://gohugo.io/ )
framework seems to be a promising solution.
2024-02-25 14:54:10 +01:00
{{< figure src = "img/hugo-logo-wide.svg" width = "25%" > }}
2024-02-11 18:44:30 +01:00
2024-02-04 23:33:11 +01:00
## Getting started
{{% steps %}}
2024-02-11 18:49:25 +01:00
### Installing Hugo
2024-02-04 23:33:11 +01:00
The [installation ](https://gohugo.io/installation/ ) is straight forward. There's
an [ArchLinux ](https://gohugo.io/installation/linux/#arch-linux ) package of the
extended edition of Hugo available, which can be installed directly via pacman:
```bash
sudo pacman -S hugo
```
Afterwards I verify the installation using the `hugo version` command. For the
automated building Hugo also needs to be installed on Uberspace. I refer to the
[lab guide ](https://lab.uberspace.de/guide_hugo/ ) until *Create first website*
and skip the rest of it to proceed with the local installation.
{{< callout type = "info" > }}
The Hugo installation on Uberspace is only used for live site building,
which is configured later via [Forgejo ](../forgejo/ ).
{{< / callout > }}
2024-02-11 18:49:25 +01:00
### Choosing a theme
2024-02-04 23:33:11 +01:00
I search the [themes ](https://themes.gohugo.io/ ) list for a minimalistic yet
powerful theme featuring a dark mode and shortcodes so I don't have to reinvent
the wheel and existing content can be migrated pretty easily. Some of themes
provide a demo and in the end [Hextra ](https://themes.gohugo.io/themes/hextra/ )
appeals to me.
2024-02-11 18:49:25 +01:00
### Setting up a repo
2024-02-06 22:44:27 +01:00
I use [Forgejo ](/docs/infrastructure/forgejo/ ) for automatically generating the
`LICENSE` , `README.md` , and `.gitignore` files while [creating a repository ](https://forgejo.org/docs/latest/user/first-repository/#creating-a-repository )
and clone the remote repository to proceed with it locally.
```bash
git clone https://dri.ven.uber.space/thisven/Website
```
2024-02-11 18:49:25 +01:00
### Configuring a site
2024-02-04 23:33:11 +01:00
Though the Hextra theme documentation recommends installing it as a Hugo module
2024-02-29 15:41:18 +01:00
I prefer a [Git submodule ](/docs/infrastructure/forgejo/submodules/ ) setup in
[getting started ](https://imfing.github.io/hextra/docs/getting-started/#setup-hextra-as-git-submodule ):
2024-02-04 23:33:11 +01:00
```bash
2024-02-06 22:44:27 +01:00
hugo new site --force Website --format=yaml
2024-02-04 23:33:11 +01:00
cd Website
git submodule add https://github.com/imfing/hextra.git themes/hextra
echo "theme: hextra" >> hugo.yaml
```
2024-02-06 22:44:27 +01:00
**Remark:** The `--force` Option of the `hugo new site` command is required to
use the already initialized directory cloned from the remote origin before.
2024-02-11 18:49:25 +01:00
### Creating content
2024-02-04 23:33:11 +01:00
I create a home and docs content page:
```bash
hugo new content/_index.md
hugo new content/docs/_index.md
```
and run the development server locally while editing the previous files in a
text editor to write the page bodys:
```bash
hugo server --buildDrafts
```
2024-02-06 22:44:27 +01:00
The development server listens on port 1313 and the site can be previewed at:
2024-02-04 23:33:11 +01:00
[http://localhost:1313 ](http://localhost:1313 )
2024-02-11 18:49:25 +01:00
### Committing changes
2024-02-06 22:44:27 +01:00
Though there are adaptions necessary, it may be the time to commit my first
efforts and push them to the remote origin to get usd to frequent committing.
```bash
git add .
git commit -m "Initialize new hugo site"
git push
```
{{< callout type = "warning" > }}
Remember to frequently use these commands after applying changes to keep the
remote repository up to date and in sync with your local copy.
{{< / callout > }}
2024-02-11 18:49:25 +01:00
### Customizing the site
2024-02-04 23:33:11 +01:00
The [guide ](https://imfing.github.io/hextra/docs/guide/ ) in the documentation of
the Hextra theme expands on several features. Below are some configurations and
quirks that I found useful.
{{% /steps %}}
## Customizations
{{< cards > }}
2024-02-29 15:41:18 +01:00
{{< card link = "archetypes" title = "Archetypes" icon = "book-open" > }}
2024-03-03 22:16:07 +01:00
{{< card link = "custom-css" title = "custom.css" icon = "code" > }}
2024-02-29 15:41:18 +01:00
{{< card link = "shortcodes" title = "Shortcodes" icon = "collection" > }}
2024-02-04 23:33:11 +01:00
{{< / cards > }}
## Resources
2024-02-29 15:41:18 +01:00
Repository: https://dri.ven.uber.space/thisven/Website
[^1]: [Static site generator ](https://en.wikipedia.org/wiki/Static_site_generator )
in the Wikipedia
[^2]: [Markdown Guide ](https://www.markdownguide.org/ ) website