While that may not seem like a lot, you’ll still get hands-on with the following aspects of Hugo:
The Hugo CLI tool
Site configuration
Site structure
Templating
Themes
Let’s begin.
Generate a new Hugo site shell
The first thing to do is to generate a basic Hugo website (the core file and directory structure). To do that and change into the newly created directory, in your terminal run the command below.
bash
hugo new site test-site
cd test-site
When the command completes, you should see output similar to that below in your terminal.
bash
Congratulations! Your new Hugo site is created in /opt/workspace/hugo-site.
Just a few more steps and you're ready to go:
1. Download a theme into the same-named folder. Choose a theme from https://themes.gohugo.io/ or create your own with the "hugo new theme <THEMENAME>" command.
2. Perhaps you want to add some content. You can add single files
with "hugo new <SECTIONNAME>/<FILENAME>.<FORMAT>".
3. Start the built-in live server via "hugo server".
Visit https://gohugo.io/ for quickstart guide and full documentation.
By having a quick read through the output, you can see two key things:
The site’s been generated in /opt/workspace/hugo-site. Your location will be different, based on the location that you ran the command from.
Before you can view the website, you need to:
Before you do that, have a quick look at the site’s structure to familiarise yourself with it. It will come in handy later. In the terminal, if you print the file and directory structure, by running a command such as tree, it would look as follows.
bash
.
├── archetypes
│ └── default.md
├── config.toml
├── content
├── data
├── layouts
├── static
└── themes
There’s a bit to take in, so the important things to take note of are the following:
config.toml
This is Hugo’s core configuration file. By default it’s written in TOML format. But Hugo also supports Yaml and JSON.
content
This directory contains all of the content for your site, such as blog posts, about, contact and other pages.
layouts
This directory contains the layouts. In Hugo, pages are broken into two parts. The outer template contains content which remains the same across requests, such as the page’s header, footer, and navigation elements, and the content that is unique to a given page, such as a blog post’s content. This directory also contains theme overrides. We’ll come to that later.
static
This directory, as the name suggests, contains all of the website’s static assets, such as images.
themes
This directory contains one or more themes. You can download a free theme, or create your own.
Next, it’s time to configure the site. Open config.toml, located in the top-level directory of the site. It should look like the example below.
toml
baseURL = 'http://example.org/'
languageCode = 'en-us'
title = 'A Test Hugo Site'
Change these settings as you see fit. I recommend changing the title.
Deploy the Hugo site locally
With that done, it’s time to start the site, or deploy it locally. To do that, run the command below.
bash
hugo server
Slightly paraphrasing the documentation:
hugo server starts a high performance webserver which builds and serves the site
After it completes, you should see output similar to the following in the terminal.
bash
Start building sites …
hugo v0.92.2+extended linux/amd64 BuildDate=2022-02-23T16:47:50Z VendorInfo=ubuntu:0.92.2-1
| EN
-------------------+-----
Pages | 0
Paginator pages | 0
Non-page files | 0
Static files | 6
Processed images | 0
Aliases | 0
Sitemaps | 1
Cleaned | 0
Built in 9 ms
Watching for changes in /opt/workspace/hugo-site/{archetypes,content,data,layouts,static,themes}
Watching for config changes in /opt/workspace/hugo-site/config.toml
Environment: "development"
Serving pages from memory
Running in Fast Render Mode. For full rebuilds on change: hugo server --disableFastRender
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
Press Ctrl+C to stop
If you scan through the command’s output, you’ll see that the site was generated in 9 milliseconds, how many different files were involved (6 static files and 1 sitemap) that the new site is available on http://localhost:1313/ and that if you make any changes in /opt/workspace/hugo-site/{archetypes,content,data,layouts,static,themes} or /opt/workspace/hugo-site/config.toml, that a new version of the site will be generated.
Sadly, however, if you open http://localhost:1313/ in your browser of choice, you won’t see a lot. You won’t see anything, actually, as you don’t have a theme installed.