Hugo’s Getting Started guide is the place to start!
It is quite easy to get started. Once Hugo is installed is installed, you can generate a new site from the command line using the built-in command hugo new site <sitename>
. This will generate all the files and directories that are needed to get going.
hugo new site <sitename>
hugo new site blog
will create a blog
directory containing the following files:
- archetypes: Markdown templates for the various types of content such as posts, projects etc.
- config.toml file for the configuration variables for the site.
- content directory to hold the content for the site
- data directory to hold data files in YAML, JSON or TOML.
- layouts folder to define how the site will look. This folder contains templates in
.html
format. - static directory for images, CSS, JavaScript
- themes folder to hold themes that you can create yourself or download.
The directory structure is explained on the getting started guide here.
Hugo commands
-
hugo help
Once Hugo is installed you can use thehugo help
command to see some help documentation. This will list the available Hugo commands and flag options. The main ones I have used so far are: -
hugo new site <my_blog>
to generate a new site directory contains files files and folders listed above. -
hugo server
to run a local development server. Go to the the localhost (usually 1313) in your browser to see the website. -
hugo server -D
Using theD
flag will also include content marked asdraft:true
status. Any content with draft:true will not be published by default. -
hugo
to build / rebuild the site before deploying. The website will be generated to thepublic/
folder by default although this can be changed. The website is then ready to be deployed to a web server.
These commands are all usually run from the root of the site.
Deploying a hugo website
After running the hugo server
command for local web development you need to run hugo
command to rebuild the site. Hugo generates a static site which can be hosted anywhere on any web server. So far I have only used Netlify to host a site but there are other options.
The two options I have used for deploying the site so far are:
-
pushing the entire hugo folder to GitHub then configure Netlify settings to build the site.
-
Pushing just the public folder to a GitHub repository. Then deploy to Netlify.
Once the site has been setup on Netlify and linked to the Git repository you only need to push the changes to GitHub and the site will automatically be updated.
- You can also manually drag a public folder into Netlify.
Live Reload
Hugo comes with LiveReload which is a tool for web developers and designers.
LiveReload monitors changes in the file system. As soon as you save a file, it is preprocessed as needed, and the browser is refreshed. When you change a CSS file or an image, the browser is updated instantly without reloading the page.
Running the hugo server
command will run a fully functioning web server while at the same time watching the file system for additions, deletions or changes within certain parts of the site including the static, content, data, i18n, layouts, themes/current theme folders and the config file. Whenever you make changes Hugo simultaneously rebuilds the site while serving the content.
Creating Content
The command hugo new
can be used to create content for the site.
hugo new content/_index.md
to create a home page.hugo new content/about.md
to create an about pagehugo new content/contact.md
to create a page called contacthugo new posts/my-post.md
to create a blog post in the posts section.
You can create different sections under the content folder. Some common sections might be for projects, blog posts, presentations, CV / resumé.
Configuring the Hugo site
- The configuration section of the getting started guide provides the full list of configuration options. There are many default configurations which you don’t need to specify unless you want to change from the defaults. For example Goldmark is the current default Markdown rendering engine but you could still use the
BlackFriday
markdown rendering engine by setting thedefaultMarkdownHandler
toblackfriday
in the top level markup config of the configuration file.
Here are some of the configurations from the list of all configuration settings .
-
baseURL
for the hostname and path to the root -
enableEmoji
defaults to False. See Emoji cheatsheet -
enableInlineShortcodes = true
to implement shortcodes inline. This is set to false for security reasons as explained here. However for a blog website such as this where you have total control over the content it would be safe to allow inline shortcodes. See Shortcode variables. -
enableRobotsTXT
defaults to false. Change to true to enable generations ofrobots.txt
file. -
footnoteReturnLinkContents
for the text to display for footnote return links. -
googleAnalytics("")
to use your google analytics tracking id. -
menu
to add non content entries to a Menu. See Add Non-content Entries to a Menu. See menu-templates -
paginate
to change the default number (10) of elements per page in pagination. -
permalinks
-
publishDir
to change the directory where Hugo builds the final static site from the default which is the public directory. -
relativeURLs
to make all relative URLs relative to content root -
theme
the theme to use -
title
the site’s title. -
uglyURLs
to create URLs of the form/filename.html
instead of/filename/
.
Help and learning resources.
The hugo help
command will list the availabe hugo commands and options.
- Hugo’s home page provides links to a quick start guide as well as the list of Hugo themes, documentation and a discourse community and more.
Hugo’s getting started guide has a list of external learning resources including books and video tutorials.