RawContent and Content Fingerprints in Hugo
Updated  2021-December-29

Page contents


2021-August-17  Published this evolving⁠[1] article.


This article assumes you know the basics about the Hugo static site generator.


Anatomy of a Hugo page’s primary source file

Abstractly a Hugo page’s primary⁠[2] source file looks like this:

front matter

main matter

Details about this are in Infinite Ink’s Hugo Tutorial in the Anatomy of a content file section.


Using a page’s “main matter” in a Hugo layout file

In a Hugo layout file, the “main matter” of a page can be accessed with the following page variables.


The main matter as it appears in the source file, i.e., everything below the front matter.


The main matter after it has been processed by Hugo with the help of a markup renderer, such as Asciidoctor, Goldmark, or Pandoc.


Fingerprinting or hashing a page

One way to check if a page has changed is to check its fingerprint or hash. For example, the layout file for this page includes:

RawContent {{ .Page.RawContent | sha256 | truncate 6 "" | upper }}

which the hugo command renders as:

RawContent EFC51D


If a page does not use any external snippets,⁠[3] it’s often sufficient to use the above .Page.RawContent fingerprint. But if a page uses external snippets, you need to fingerprint .Page.Content. with, for example, this:

Content {{ .Page.Content | sha256 | truncate 6 "" | upper }}

Fingerprinting the .Content, rather than the .RawContent, is needed because it’s possible that the .RawContent will be unchanged but one (or more) external snippet will have changed.

On Infinite Ink I use both these fingerprints because that way I can tell if changes happened in one or both of:

  • the primary source file

  • the external snippets

For an example of these fingerprints, see the Page Meta section of this page below.


See also


1. Many Infinite Ink articles, including this one, are evergreen and regularly updated.
2. It is possible for a Hugo page’s primary source file to call snippets from other (non-primary) source files.
3. Snippets can be specified in front matter, Hugo layout files (including Hugo shortcodes), AsciiDoc attributes, and AsciiDoc includes.

Comments and questions 📝 👍 👎 🤔

Your public comment or question might immediately improve this page or help me to (eventually) improve this page.