A Hugo Update Everyone Should Be Talking About

A Hugo Update Everyone Should Be Talking About

For Hugo users a few great updates came out recently with a long-awaited feature: nested sections. Along with nested sections, Hugo 0.22-0.24 added a series of improvements that make building websites even easier.

Nested Sections, What’s The Big Deal?

If you’re not familiar with Hugo, sections are the different types of content your Hugo site has. For example Posts, Pages, and Press Releases.

Until Hugo 0.22, nesting sections weren’t supported as a feature, meaning you couldn’t easily have a hierarchical relationship between different types of content.

Why is this important? It’s because there are many scenarios where nested sections are an asset! Take a documentation site, for example…

In a documentation site, you can create a section for FAQs, for a getting started guide, and for API docs. Inside each section, you can now add a nested subsection for specific topics.

Imagine API documentation where you document a set of endpoints for users.

Instead of using categories or tags to manage this relationship, you can just nest them which will create easily readable, human URLs such as /docs/api/users.

Improvements to Page Fetching

On top of nested sections, Hugo 0.22 has upgraded the .Site.GetPage template function to get any regular page, which means you can now fetch any page by filename.

For example:

{{ .Site.GetPage "page" "post" "example-post.md" }}

On top of this, performance improvements were made to page fetching to make it even faster.

Archetypes as GoTemplates

In Hugo 0.24 Archetypes received a huge update. They can now be formatted as GoTemplates, letting you run complex logic when you create content using an Archetype.

For example:

title: "{{ replace .TranslationBaseName "-" " " | title }}"
publishDate: {{ .Date }}
draft: true

**Insert Lead paragraph here.**

## New Cool Posts

{{ range first 10 ( where .Site.RegularPages "Type" "cool" ) }}
* {{ .Title }}
{{ end }}

In this example, the title​ field is automatically localized, the date​ is automatically configured from the current date, and a set of related posts are listed in the markdown body. 

This is a killer feature for developers managing content from the CLI, and can easily be paired with Front Matter Templates to offer similar functionality to your content managers in Forestry.

Note: Forestry does not support GoTemplate syntax when importing Archetypes to create Front Matter Templates. More info found here.

Other improvements

  • 0.24.1fixed bugs with hugo new when no Archetype was available, as well as when shortcodes were being used.

  • Archetypes can now be used to create content for all content types, not just markdown.

  • Improved hugo serve to handle removal of directories, or directories pasted into /content out of the box.

  • Added noindex tag to HTML generated by Hugo aliases, which helps improves SEO

  • Ensures the 404 page is not included in the autogenerated sitemap, which helps improve SEO

  • Add uniq function, which allows you to remove duplicates from an array.

For a full summary of the latest releases, see the Hugo releases!