Grouping similar pages together in Hugo can be done in a few different ways, depending on your needs. Here are some common methods:
1. Using Sections
Hugo organizes content into sections based on the directory structure. For example, if you have a directory called blog
, all markdown files within it will be part of the blog
section.
- You can create subdirectories within the main directory to further group content.
2. Using Taxonomies
Taxonomies like tags and categories can be used to group content. You can define custom taxonomies in your config.toml
file:
[taxonomies]
category = "categories"
tag = "tags"
Then, in your content files, you can add these taxonomies in the front matter:
---
title: "My Post"
categories: ["tech"]
tags: ["hugo", "static-site"]
---
3. Using Front Matter Parameters
You can use custom front matter parameters to group content. For example, you can add a group
parameter to your content files:
---
title: "My Post"
group: "tutorials"
---
Then, you can use Hugo’s GroupByParam
function in your templates to group content by this parameter.
Read more.
4. Page Bundles
Hugo supports page bundles, which allow you to group related content together. A page bundle is a directory that contains an index.md
file and other related files.
Example structure:
content/
├── blog/
│ ├── post-1/
│ │ ├── index.md
│ │ ├── image1.jpg
│ ├── post-2/
│ │ ├── index.md
│ │ ├── image2.jpg
Conclusion
These methods can be combined to create a flexible and organized content structure in Hugo. Whether you’re structuring blog posts, documentation, or tutorials, these tools provide a powerful way to group and manage pages effectively.
For further insights: