31
loading...
This website collects cookies to deliver better user experience
hugo --help
on your terminal to make sure that the installation was complete and that it works. These are the first few lines you should see.$ hugo --help
hugo is the main command, used to build your Hugo site.
Hugo is a Fast and Flexible Static Site Generator built with love by spf13 and friends in Go.
$ hugo new site <site-name>
Congratulations! Your new Hugo site is created in <site-path>.
archetypes
. You may optionally choose to add a theme and make slight config changes instead of building the site from scratch. You can find a range of themes at theme.hugo.io. Adding them is usually the same for most themes. Although, some may have slight variations. To illustrate what adding a theme is like let's take the example of this startup website theme. Change directories to the site folder, initialize a git repository, and add the theme as a submodule.$ cd <site-name>
$ git init
$ git submodule add https://github.com/SteveLane/hugo-icon.git themes/hugo-icon
$ hugo server -t hugo-icon --config themes/hugo-icon/exampleSite/config.toml
├── archetypes
├── config
├── content
├── data
├── layouts
├── resources
├── static
└── themes
---
title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
draft: true
---
hugo new
command contains this as its front matter. Running hugo new posts/hello.md
will create the following file in contents/posts
:--------
title: "Hello"
date: 2021-05-20T11:03:02
draft: true
--------
--kind
flag. For example, if a profile archetype exists at archetypes/profile.md
, you can create a new profile in the content folder using hugo new profile/lisa-jane.md
. assets/sass/form.sass
. To convert the SASS to CSS, you will use the resources.ToCSS
pipe.{{ $formSass := resources.Get "sass/form.sass" }}
{{ $formStyling := $formSass | resources.ToCSS }}
config.toml
file at the site root. You can configure any number of things like cache, URL, site titles, live reload, content directories, archetype directories, languages, builds, the dev server, etc. You may choose to have multiple configuration files for better organization. In this case, these will be stored in the config
folder. The config can also be specified using the --config
flag with a Hugo command. Files used with this flag take precedence over other configs. Here is an example of the config file for the startup site created above:baseURL = "http://a-startup.com/"
languageCode = "en-us"
title = "My Startup Site"
posts/hello.md
, the front matter is the title, date, and draft status. You create a content instance using the hugo new
command. .Site.Data
variable. Let's take the example of a coffee shop site that has its menu in a data/menus/beverages.json
file.{
"beverages": [
{ "name": "Americano", "price": "$2.50" },
{ "name": "Cappuccino", "price": "$3.75" },
{ "name": "Espresso", "price": "$3.00" },
{ "name": "Macchiato", "price": "$4.00" }
]
}
{{ range $.Site.Data.menus.beverages }}
{{ .name }}: {{ .price }}
{{ end }}
data
folder is meant for static data files, it is still possible to fetch JSON and CSV data from external sources such as CMSs like Strapi or other APIs. You could use functions like getJSON
and getCSV
for these purposes. This allows for greater flexibility as you don’t have to build the site every time some data changes. With Strapi, you can add data to your backend and consume it on your Hugo site. You can find out more about how to access external data on your Hugo site here and how to get started on hosting your data with Strapi here. [text/template](https://golang.org/pkg/text/template/)
and [html/template](https://golang.org/pkg/html/template/)
packages in Go. They are written in HTML but variables and functions can be used inside nested curly braces {{ }}
within them. Using logic and referencing external templates inside them is possible. You can find a great primer on this template language at this link. archetypes/default.md
, you may have noticed this:title: "{{ replace .Name "-" " " | title }}"
replace
is a function that replaces part of a string with something else. In this case, the file name is the input, and all the -
characters are removed then replaced with a single space. title
is also a function that converts a string to title case. These are just a few examples. There are many more listed in Hugo's function reference. [.Site](http://(https://gohugo.io/variables/site/#site-variables-list)
variable holds site-related values like languages, sections, the site title, the base URL, etc. 31