Files
hextra_mirror/exampleSite/content/docs/guide/organize-files.md
Keith Stockdale 72c383ef5c feat: allow authors to set the value of reversePagination in page front matter (#674)
* Allow authors to set the reverse pagination setting of a page using front matter

* Adding some documentation of the reversePagination front matter custom parameter along with an example of how to use it and why you might want to use it
2025-05-23 01:23:25 +01:00

9.4 KiB
Raw Blame History

title, weight, prev
title weight prev
Organize Files 1 /docs/guide

Directory Structure

By default, Hugo searches for Markdown files in the content directory, and the structure of the directory determines the final output structure of your website. Take this site as an example:

{{< filetree/container >}} {{< filetree/folder name="content" >}} {{< filetree/file name="_index.md" >}} {{< filetree/folder name="docs" state="open" >}} {{< filetree/file name="_index.md" >}} {{< filetree/file name="getting-started.md" >}} {{< filetree/folder name="guide" state="open" >}} {{< filetree/file name="_index.md" >}} {{< filetree/file name="organize-files.md" >}} {{< /filetree/folder >}} {{< /filetree/folder >}} {{< filetree/folder name="blog" state="open" >}} {{< filetree/file name="_index.md" >}} {{< filetree/file name="post-1.md" >}} {{< /filetree/folder >}} {{< /filetree/folder >}} {{< /filetree/container >}}

Each of the _index.md files is the index page for the corresponding section. The other Markdown files are regular pages.

content
├── _index.md // <- /
├── docs
│   ├── _index.md // <- /docs/
│   ├── getting-started.md // <- /docs/getting-started/
│   └── guide
│       ├── _index.md // <- /docs/guide/
│       └── organize-files.md // <- /docs/guide/organize-files/
└── blog
    ├── _index.md // <- /blog/
    └── post-1.md // <- /blog/post-1/

Layouts

Hextra offers three layouts for different content types:

Layout Directory Features
docs content/docs/ Ideal for structured documentation, same as this section.
blog content/blog/ For blog postings, with both listing and detailed article views.
default All other directories Single-page article view without sidebar.

To customize a section to mirror the behavior of a built-in layout, specify the desired type in the front matter of the section's _index.md.

---
title: My Docs
cascade:
  type: docs
---

The above example configuration ensures that the content files inside content/my-docs/ will be treated as documentation (docs type) by default.

Sidebar Navigation

The sidebar navigation is generated automatically based on the content organization alphabetically. To manually configure the sidebar order, we can use the weight parameter in the front matter of the Markdown files.

---
title: Guide
weight: 2
---

{{< callout emoji="">}} It is recommended to keep the sidebar not too deep. If you have a lot of content, consider splitting them into multiple sections. {{< /callout >}}

Section Navigation

Section Pagination Order

The order in which pages, accessed via PAGE.PrevInSection and PAGE.NextInSection in a page collection, are ordered, is reversed by default.

To disable this reversed ordering you can set the reversePagination custom parameter in the page front matter to false. By default reversePagination is set to true.

Example

Given the following directory structure:

{{< filetree/container >}} {{< filetree/folder name="content" >}} {{< filetree/file name="_index.md" >}} {{< filetree/folder name="blog" state="open" >}} {{< filetree/file name="_index.md" >}} {{< filetree/folder name="my-blog-series" state="open" >}} {{< filetree/file name="_index.md" >}} {{< filetree/folder name="post-a" state="open" >}} {{< filetree/file name="index.md" >}} {{< /filetree/folder >}} {{< filetree/folder name="post-b" state="open" >}} {{< filetree/file name="index.md" >}} {{< /filetree/folder >}} {{< filetree/folder name="post-c" state="open" >}} {{< filetree/file name="index.md" >}} {{< /filetree/folder >}} {{< /filetree/folder >}} {{< /filetree/folder >}} {{< /filetree/folder >}} {{< /filetree/container >}}

And the following front matter in the posts:

---
title: Post A
weight: 1
---
---
title: Post B
weight: 2
---
---
title: Post C
weight: 3
---

If the reader is at the bottom of post-b/index.md, they will see that the next page is post-a, and the previous page is post-c. This is due to reversePagination being set to true by default. This is ok when we want our posts to be displayed in chronological order from latest to oldest. However, in the case of a blog series where there are multiple parts, we typically want people to read the first post, and then move to the second and so on. So we want to disable the reversed ordering.

We can turn off reversePagination in every blog post in this series by adding the following front matter to my-blog-series/_index.md

---
title: My Blog Series
cascade:
    params:
        reversePagination: false
---

We are using cascade here to propagate the setting to all posts in the my-blog-series so that reversePagination is set to false for all descendents. This will now ensure that when the reader is on post-b/index.md they will see that the next page is post-c and the previous page is post-a.

Breadcrumb Navigation

Breadcrumbs are auto-generated based on the directory structure of /content.

For example, consider the file structure demonstrated above. Given that structure, the breadcrumbs atop the page at /docs/guide/organize-files/ would appear automatically as follows:

Documentation > Guide > Organize Files

By default, each breadcrumb link is generated based on that page's title parameter. You can customize this by specifying a linkTitle.

For example, if instead of Organize Files we wanted the breadcrumb to be Foo Bar:

---
linkTitle: Foo Bar
title: Organize Files
---

This would now generate the following breadcrumbs:

Documentation > Guide > Foo Bar

Hiding Breadcrumbs

You can hide breadcrumbs completely from a page by specifying breadcrumbs: false in its front matter:

---
breadcrumbs: false
title: Organize Files
---

Configure Content Directory

By default, the root content/ directory is used by Hugo to build the site. If you need to use a different directory for content, for example docs/, this can be done by setting the contentDir parameter in the site configuration hugo.yaml.

Add Images

To add images, the easiest way is to put the image files in the same directory as the Markdown file. For example, add an image file image.png alongside the my-page.md file:

{{< filetree/container >}} {{< filetree/folder name="content" >}} {{< filetree/folder name="docs" >}} {{< filetree/file name="my-page.md" >}} {{< filetree/file name="image.png" >}} {{< /filetree/folder >}} {{< /filetree/folder >}} {{< /filetree/container >}}

Then, we can use the following Markdown syntax to add the image to the content:

![](image.png)

We can also utilize the page bundles feature of Hugo to organize the image files together with the Markdown file. To achieve that, turn the my-page.md file into a directory my-page and put the content into a file named index.md, and put the image files inside the my-page directory:

{{< filetree/container >}} {{< filetree/folder name="content" >}} {{< filetree/folder name="docs" >}} {{< filetree/folder name="my-page" >}} {{< filetree/file name="index.md" >}} {{< filetree/file name="image.png" >}} {{< /filetree/folder >}} {{< /filetree/folder >}} {{< /filetree/folder >}} {{< /filetree/container >}}

![](image.png)

Alternatively, we can also put the image files in the static directory, which will make the images available for all pages:

{{< filetree/container >}} {{< filetree/folder name="static" >}} {{< filetree/folder name="images" >}} {{< filetree/file name="image.png" >}} {{< /filetree/folder >}} {{< /filetree/folder >}} {{< filetree/folder name="content" >}} {{< filetree/folder name="docs" >}} {{< filetree/file name="my-page.md" >}} {{< /filetree/folder >}} {{< /filetree/folder >}} {{< /filetree/container >}}

Note that the image path begins with a slash / and is relative to the static directory:

![](/images/image.png)