Understanding Hugo

This post contains nothing but notes that I took while experimenting Hugo templates. To understand each page and it’s variables (properties) I’ve created a partial called hugo_debug.html and used it in baseof.html, simply by adding this line: {{ partial "hugo_debug.html" . }}

<div>
Title: {{.Title}} <br>
Kind: {{.Kind}} <br>
Section: {{.Section}} <br>
Type: {{.Type}} <br>
Layout: {{.Layout}}<br>
Site Author: {{.Site.Author.FullName}}<br>
Author: {{ .Params.Author }} <br>
Categories: {{ .Params.Categories }} <br>
Date: {{.Date.Format "2006-01-02 Monday"}}<br>
Params: {{.Params}}<br>
</div>

Section vs Type

  • Section is the first folder under content (content/blog => blog)
  • Section cannot be set in front matter
  • Type can be set in front matter
  • If Type isn’t set, the value of Section will be used

Example: for a file named “foo” from a section called “posts”.

/content/post/foo.md
Type: post
Section: post
Kind: page

Example: for a file named “bar” from a section called “foo”.

/content/foo/bar.md
Type: foo
Section: foo
Kind: page

Section Pages

Section pages are the index pages or home pages for that section. These pages are created auto-magically by Hugo and we can overwrite them by simply creating a file called _index.md in that section.

/content/foo/
Type: foo
Section: foo
Kind: section

Ordinary Pages (about.md)

/content/about.md

Normally, these pages have the following properties. Yet, I set Type: ordinary to be able to separate them from normal blog posts while listing content with Hugo templates. Explained here

Type: page
Section:
Kind: page

Taxonomy

Hugo lets us group content with taxonomies.

/categories
Type: categories
Section: categories
Kind: taxonomy

Term

/categories/foo
Type: categories
Section: categories
Kind: term

Next Episode

published on 03.08.2020

In this post, I aim to explain this website. Template by template… The main purpose here is to create a document to myself for future reference. Templates are complicated and not easy to read. That’s why I’ll probably forget what I did and why I coded this way. […] We are …

Previous Episode

published on 02.08.2020

A few days ago, I decided to migrate my website from Jekyll to Hugo. Instead of using a theme from the Hugo community, I wanted to port my existing website. Converting, markdown content and SCSS wasn’t hard. I read a few articles, blogs, and the original documentation to learn about …

TAG CLOUD