Written by: Geoffrey Callaghan

Hugo Tutorial

Hugo Tutorial

This is a step-by-step tutorial for getting started with Hugo, a popular static site generator written in Go:

Step 1: Install Hugo

Download and install Hugo from the official website, or use a package manager if your operating system supports it. Once installed, you can verify the installation by running:

hugo version

Step 2: Create a New Hugo Site

Open your terminal and navigate to the directory where you want to create your Hugo site. Then, run:

hugo new site my-hugo-site
cd my-hugo-site

This will create a new directory named my-hugo-site and initialize it as a Hugo project.

Step 3: Choose a Theme (Optional)

Hugo comes with a variety of themes to choose from. You can browse available themes on the Hugo Themes website. Once you’ve found a theme you like, you can add it to your project as a submodule. For example:

git init
git submodule add <theme-git-url> themes/<theme-name>

Replace <theme-git-url> with the Git URL of the theme you want to use and <theme-name> with the name you want to give to the theme directory.

Step 4: Configure Your Site

Hugo uses a configuration file named config.toml, config.yaml, or config.json to manage site-wide settings. Create a configuration file in the root of your project and specify any necessary configurations, such as the theme, language, title, etc.

# config.toml

baseURL = "https://example.com/"
languageCode = "en-us"
title = "My Hugo Site"
theme = "theme-name"

Step 5: Create Content

Create content for your site using Markdown or HTML files. By default, Hugo expects content to be placed in the content directory. You can organize your content further by using subdirectories within the content directory.

hugo new posts/my-first-post.md

This command creates a new Markdown file for your first post in the content/posts directory.

Step 6: Customize Your Theme (Optional)

If you’re using a theme, you may want to customize its appearance or functionality. Themes typically include customizable templates, stylesheets, and configuration options. Refer to the documentation provided with your chosen theme for instructions on how to customize it.

Step 7: Build Your Site

Once you’ve added content and made any necessary configurations or customizations, you can build your site using the following command:

hugo

This command generates your static site in the public directory by default.

Step 8: Preview Your Site

To preview your site locally, you can use Hugo’s built-in server. Run the following command:

hugo server

This command starts a local server, and you can view your Hugo site by visiting http://localhost:1313 in your web browser.

Step 9: Deploy Your Site

Once you’re satisfied with your site, you can deploy it to your preferred hosting provider. Simply upload the contents of the public directory to your hosting provider’s server.

Step 10: Customize and Extend

Continue customizing and extending your Hugo site by adding more content, tweaking configurations, or integrating additional features using Hugo’s powerful templating system and ecosystem of plugins.

That’s it! You’ve now created a static site using Hugo. Happy building!