Getting Started with Hugo and Deploying to Netlify

undefined or mostly null.
Search for a command to run...

undefined or mostly null.
In this series, I will share articles related to best practices for building and deploying applications on the web with the JavaScript and Python programming languages.
Developers tend to know how to iterate through JavaScript Arrays easily but most times they tend to get confused while working with JavaScript Objects especially beginners and intermediates. In this article, I'll show you Five (5) different ways of ...
I wrote this article in December 2023 for an interview screening task and thought to share it today while clearing my drafts for some new content prep, just in case it's still helpful to someone out t

Hey! I’m super excited to announce that I have joined the Secretariat Team at the Digital Public Goods Alliance. In this role, I leverage my passion for open source and technical background to assess DPG applications, provide technical support and ad...

Creative designs have become more important than ever in the software ecosystem today with many industries and end-consumers having several use cases that require them to offer design editing solutions to either designers or end-consumers. Every busi...

With the rise of artificial intelligence (AI) and large language models (LLMs), it has become easier to solve different human problems than ever before. Even consumers with little to no technical expertise can benefit from AI. Humans can now automate...

Some years ago, GitHub introduced the new Profile README feature that allowed GitHub users to pin a markdown file on their profile using a special repository named after their GitHub username. Since then, developers have used this file as a quick por...

Hugo is a fast and modern static site generator written in Go and designed to make website creation fun again. It builds pages when you create or update your content. Websites built with Hugo are extremely fast and secure. Hugo takes a source directory of files and templates and uses these as input to create a complete website.
Hugo sites can be hosted anywhere, including Netlify, Heroku, GoDaddy, DreamHost, GitHub Pages, GitLab Pages, Surge, Aerobatic, Firebase, Google Cloud Storage, Amazon S3, Rackspace, Azure, and CloudFront and work well with CDNs. Hugo sites run without the need for a database or dependencies on expensive runtimes like Ruby, Python, or PHP.
In this tutorial, I’d show you how to build your first Hugo site and deploy to Netlify. Let’s roll :)
Hugo is the fastest tool of its kind. At <1 ms per page, the average site builds in less than a second. Watch this video here to see how fast Hugo is
Hugo supports unlimited content types, taxonomies, menus, dynamic API-driven content, and more, all without plugins.
We love the beautiful simplicity of markdown’s syntax, but there are times when we want more flexibility. Hugo shortcodes allow for both beauty and flexibility.
Hugo ships with pre-made templates to make quick work of SEO, commenting, analytics and other functions. One line of code and you’re done.
Hugo provides full i18n support for multi-language sites with the same straightforward development experience Hugo users love in single-language sites.
Hugo allows you to output your content in multiple formats, including JSON or AMP and makes it easy to create your own.
All features can be found here
For this tutorial, we’re going to build a Simple Blog with Hugo.
PS: I would be using a windows machine in this tutorial. Hence all steps would be based on windows, but I added installation guides for other operating systems.
I’ve also created a repository with starter files found here. Use the installation guide to get Hugo running on your machine and fork the starter files. Ensure you follow the steps.
Git
Code Editor
Install Hugo
Fork the starter repository here
Create a new site
Deploy to Netlify
To start using Hugo, you need first to install it.
Hugo was written in Go, but you don’t need to install Go to enjoy Hugo. You only need a precompiled binary!
Hugo currently provides pre-built binaries for the following:
macOS (Darwin) for x64, i386, and ARM architectures
Windows
Linux
OpenBSD
FreeBSD
Follow the video below to install Hugo on your macOS or read the Installation guide. There are several techniques for installing Hugo on mac, so I won’t be going through them. BTW, I’m using a windows machine, so I possibly don't know how to guide you :)
Follow the video below to install Hugo on your windows machine or read the Installation guide. This video is a complete guide, but please let me know in comments if you have installation issues.
To install the “extended” Sass/SCSS:
snap install hugo --channel=extended
To install the non-extended version without Sass/SCSS support:
snap install hugo
This installs the “extended” Sass/SCSS version.
sudo apt-get install hugo
sudo pacman -Syu hugo
sudo dnf install hugo
doas pkg_add hugo
You can fork the starter repository. It contains the finished work with Theme and custom posts. Creating a site with Hugo is quite simple, follow the following steps.
hugo new site Hugo10
Now you should have a new folder Hugo101 with subfolders:
├── archetypes
├── assets
├── config
├── content
├── data
├── layouts
├── static
└── themes
Full directory structure explanation can be found here
Additional resource:
This video would show you how to install and use themes on Hugo. Installing is very simple; you need to find the theme you like and download it into the themes subdirectory. If you’re using the starter file, I’ve done that already.
hugo server -D
Now your new site should be available at localhost:1313.
hugo new post/my-first-post.md
This would be added in /contents/post
---
title: "my first post"
date: 2018-11-05T13:22:14+24:00
draft: false
tags: ["markdown", "GitHub", "website"]
categories: ["hugo", "base16"]
---
hugo
Now your directory would have a new subfolder public; this is the final build. Hugo takes a source directory of files and templates and uses these as input to create a complete website. The public is the complete website and is what you’d deploy.
├── archetypes
├── assets
├── config
├── content
├── data
├── layouts
├── public
├── static
└── themes
We would deploy to Netlify in the next section of this tutorial, but before that, we need to configure Hugo for Netlify.
Create a new file in your project's root; If you’re using the starter file, I’ve added this already.
touch netlify.toml
Paste this in it: (This is just configuring how Hugo should work with Netlify)
[build]
publish = "public"
command = "hugo --gc --minify"
[context.production.environment]
HUGO_VERSION = "0.54.0"
HUGO_ENV = "production"
HUGO_ENABLEGITINFO = "true"
[context.split1]
command = "hugo --gc --minify --enableGitInfo"
[context.split1.environment]
HUGO_VERSION = "0.54.0"
HUGO_ENV = "production"
[context.deploy-preview]
command = "hugo --gc --minify --buildFuture -b $DEPLOY_PRIME_URL"
[context.deploy-preview.environment]
HUGO_VERSION = "0.54.0"
[context.branch-deploy]
command = "hugo --gc --minify -b $DEPLOY_PRIME_URL"
[context.branch-deploy.environment]
HUGO_VERSION = "0.54.0"
[context.next.environment]
HUGO_ENABLEGITINFO = "true"
Netlify is an all-in-one workflow that combines global deployment, continuous integration, automatic HTTPS and many other features.
Ensure you have a forked version of the starter files or a version of your own project hosted on GitHub
Visit app.netlify.com and select your preferred signup method.

Select the “New site from git.” button


For this tutorial, I assume its Hugo101; else you can filter through your repositories in real-time.

Here you select the branch you wanted to be published, your build command, and your publish directory (Directory that contains the built static files). The publish directory for Hugo is public. The following steps assume you are publishing from the master branch.

In the Netlify console, select “Deploy site” and wait for it to build

Once the build is finished, you should now see a “Hero Card” at the top of your screen, letting you know the deployment is successful. You’ll see that Netlify automatically generates the URL. You can update the URL in “Settings.” Visit the live site.
Now every time you push changes to your hosted git repository, Netlify will rebuild and redeploy your site. You can add your own changes to the starter files and tweak as you wish.
Hugo is the world’s fastest framework for building websites. It is one of the most popular open-source static site generators. With its amazing speed and flexibility, Hugo makes building websites fun again. (Hugo docs)
Hugo is open-source and completely free, you can contribute to Hugo here
This is just a beginners guide, there’s still more to Hugo, head out and read the Hugo docs to learn more. Below is a list of useful resources you might need.