concept page in category hugo

appears as: page, page, pages, pages, The pages, A page, The page
Hugo in Action: Static sites and dynamic JAMstack apps

This is an excerpt from Manning's book Hugo in Action: Static sites and dynamic JAMstack apps.

In traditional Content Management Systems (CMS) the server plays a major role in handling user interactions. Fresh pages need to be generated even when just a part of the page needs to be modified. That is not just unnecessary but suboptimal. Modern JavaScript is fully capable of storing the user state in the browser and updating the content based on it. It can communicate with the server and update the interface without the user needing to perform a reload or see a flicker in the interface.

We already have split out the menu (created in chapter 2) on the config file in section 4.1. Let’s go over the menu.yaml that we created. Each menu entry consists of multiple fields. The identifier is able to uniquely find an entry. The weight field is used to order the entries. The url field provides the relative path to the page from the website base. Hugo is flexible with the other fields and their purpose. Some themes use the name field for the display text of the menu entry and others use title. To create sub-menus, we need to provide the parent field with the identifier to the parent menu entry.

Listing 4.1. Menu entries using the config file.
# config/_default/menu.yaml
main:                                       #    - Name of the menu
  - identifier: about                       #       - Identifier
    name: About                             #       - Display name (theme specific key)
    url: /about                             #       - Target URL
    weight: 1                               #       - Sorting order
  - identifier: contact
    name: Contact
    url: /contact
    weight: 2

There are two ways to include pages in the website menus using Hugo. The first approach is to add menu items in the config file. This approach helps localize and tightly monitor the menu. The other approach is to specify the menus the page belongs to within its front matter. This way the menu becomes more dynamic and controlled by the content. If we delete a page, the menu automatically gets trimmed and we do not have to worry about cleaning up stale links. The choice of the type to use depends on the use case. If the objective is to have the menu at one place, the config file is the way to go. If it is desired to split the ownership of menus amongst owners of the different content sections of the website, then using the front matter is the way to go. Both can be mixed and matched as needed.

A common problem with website source codes is the scattering of the content across databases, file systems and third-party locations. The images associated with the page live in a different location that makes it very difficult to properly clean up after the page is removed from the website. The pages are not portable across websites and the authors need access to multiple places to create them.

Hugo attempts to make contents of a web page more self-contained. The menu field in the front matter that we just learned is one of the features that Hugo has to do this. Front matter menus allow each page to own its menu entries so that it can be added/removed independently. Another feature to enable this independence is Page Bundles. Page Bundles are a collection of resources, both textual and non-textual (like images, pdf files and fonts) that are sufficient to represent pages. Page Bundles can be independently placed/removed from a Hugo website to add the associated web pages. There are two main types of Page Bundles - The Leaf and the Branch Bundles. Apart from these we also have less commonly used Headless Bundles.