hugo-wasm/content/en/content-management/build-options.md
Bjørn Erik Pedersen 346b60358d Squashed 'docs/' changes from 4429eeeea..73a01565c
73a01565c Remove comment shortcode documentation
0ca7ccd30 Replace usage of comment shortcode with HTML comments
fe10d9899 Remove expired new-in labels
11e89dfcb [editorial] Link to proper render-hook page in relref.md
11a581c2f netlify: Hugo 0.142.0
1a4fcf7f7 Miscellaneous edits
2c7a3165f Markdown linting and cleanup
69d7a781b Replace links to glossary terms with custom render hook syntax
441752d2d Refactor glossary lookup portion of link render hook
80109a14f Fix glossary term linking for plural form
cd95f0f34 Update link render hook to support glossary links
53eadb430 Remove the glossary template
1d40a7f3b Improve transform.ToMath examples
586970df2 Misc edits
6a06a8de7 Add glossary link shortcode
4171c0eb7 Improve description of masking with non-transparent images
41c8feb64 Fix example of image.Mask filter
704a81656 Add alignx option to images.Text usage example
7c03eb0cc Clarify context in example of using the try statement
56d9c9b71 Refactor glossary of terms
042a6846b Add expiry dates to deprecated methods pages
365ab345f Remove services key from instagram shortcode page
b7fe31e07 Reorder options list for images.Text filter
8051ff818 Format directory names, file names, and file paths as code
d09a14623 Update version refs for Hugo and Dart Sass
3bb006974 Add NODE_VERSION to Netlify config examples
3a0f2531e Fix typo
7e3198eaf Fix typo
cf56452a3 Fix typo
a9f51d13e Fix typo
82bfdd8c3 Fix typo
a5c41a053 Fix typo
abcfed7a5 Fix typo
8c1debf3a Remove outdated new-in badges
809ddf9ef Update theme
63867d56f Use warnf instead of errorf in try-catch example
dee3e5f09 Update theme
9791f7057 Remove TODO from comment shortcode examples
a346ca1fd Elevate embedded shortcode documentation to its own section
8fa19b50f hugoreleaser.toml =>  hugoreleaser.yaml
575d60345 Update docs for v0.141.0
a0a442d62 netlify: Hugo 0.141.0
6667cbcd8 Merge commit '81a7b6390036138356773c87a886679c81c524e1'
f36fc013e docs: Regen CLI docs
365a47ded tpl/images: Change signature of images.QR to images.QR TEXT OPTIONS
ae8f8af0a images.Text: Add "alignx" option for horizontal alignment
8f45ccca6 docs: Regen CLI docs
f0e6304f4 Merge commit 'e9fbadacc3f09191e2e19f112a49777eeb8df06c'
cb9bec2b2 tpl/images: Add images.QR function

git-subtree-dir: docs
git-subtree-split: 73a01565c5ba0774d65aa6f2384c44804fefa37d
2025-01-23 09:46:02 +01:00

8.4 KiB

title description categories keywords menu weight toc aliases
Build options Build options help define how Hugo must treat a given page when building the site.
content management
fundamentals
build
content
front matter
page resources
docs
parent weight
content-management 70
70 true
/content/build-options/

Build options are stored in a reserved front matter object named build with these defaults:

{{< code-toggle file=content/example/index.md fm=true >}} [build] list = 'always' publishResources = true render = 'always' {{< /code-toggle >}}

list
When to include the page within page collections. Specify one of:
  • always
    Include the page in all page collections. For example, site.RegularPages, .Pages, etc. This is the default value.
  • local
    Include the page in local page collections. For example, .RegularPages, .Pages, etc. Use this option to create fully navigable but headless content sections.
  • never
    Do not include the page in any page collection.
publishResources
Applicable to page bundles, determines whether to publish the associated page resources. Specify one of:
  • true
    Always publish resources. This is the default value.
  • false
    Only publish a resource when invoking its Permalink, RelPermalink, or Publish method within a template.
render
When to render the page. Specify one of:
  • always
    Always render the page to disk. This is the default value.
  • link
    Do not render the page to disk, but assign Permalink and RelPermalink values.
  • never
    Never render the page to disk, and exclude it from all page collections.

{{% note %}} Any page, regardless of its build options, will always be available by using the .Page.GetPage or .Site.GetPage method.

{{% /note %}}

Example -- headless page

Create a unpublished page whose content and resources can be included in other pages.

content/
├── headless/
│   ├── a.jpg
│   ├── b.jpg
│   └── index.md  <-- leaf bundle
└── _index.md     <-- home page

Set the build options in front matter:

{{< code-toggle file=content/headless/index.md fm=true >}} title = 'Headless page' [build] list = 'never' publishResources = false render = 'never' {{< /code-toggle >}}

To include the content and images on the home page:

{{< code file=layouts/_default/home.html >}} {{ with .Site.GetPage "/headless" }} {{ .Content }} {{ range .Resources.ByType "image" }} {{ end }} {{ end }} {{< /code >}}

The published site will have this structure:

public/
├── headless/
│   ├── a.jpg
│   └── b.jpg
└── index.html

In the example above, note that:

  1. Hugo did not publish an HTML file for the page.
  2. Despite setting publishResources to false in front matter, Hugo published the page resources because we invoked the RelPermalink method on each resource. This is the expected behavior.

Example -- headless section

Create a unpublished section whose content and resources can be included in other pages.

content/
├── headless/
│   ├── note-1/
│   │   ├── a.jpg
│   │   ├── b.jpg
│   │   └── index.md  <-- leaf bundle
│   ├── note-2/
│   │   ├── c.jpg
│   │   ├── d.jpg
│   │   └── index.md  <-- leaf bundle
│   └── _index.md     <-- branch bundle
└── _index.md         <-- home page

Set the build options in front matter, using the cascade keyword to "cascade" the values down to descendant pages.

{{< code-toggle file=content/headless/_index.md fm=true >}} title = 'Headless section' cascade [cascade.build] list = 'local' publishResources = false render = 'never' {{< /code-toggle >}}

In the front matter above, note that we have set list to local to include the descendant pages in local page collections.

To include the content and images on the home page:

{{< code file=layouts/_default/home.html >}} {{ with .Site.GetPage "/headless" }} {{ range .Pages }} {{ .Content }} {{ range .Resources.ByType "image" }} {{ end }} {{ end }} {{ end }} {{< /code >}}

The published site will have this structure:

public/
├── headless/
│   ├── note-1/
│   │   ├── a.jpg
│   │   └── b.jpg
│   └── note-2/
│       ├── c.jpg
│       └── d.jpg
└── index.html

In the example above, note that:

  1. Hugo did not publish an HTML file for the page.
  2. Despite setting publishResources to false in front matter, Hugo correctly published the page resources because we invoked the RelPermalink method on each resource. This is the expected behavior.

Example -- list without publishing

Publish a section page without publishing the descendant pages. For example, to create a glossary:

content/
├── glossary/
│   ├── _index.md
│   ├── bar.md
│   ├── baz.md
│   └── foo.md
└── _index.md

Set the build options in front matter, using the cascade keyword to "cascade" the values down to descendant pages.

{{< code-toggle file=content/glossary/_index.md fm=true >}} title = 'Glossary' [build] render = 'always' cascade [cascade.build] list = 'local' publishResources = false render = 'never' {{< /code-toggle >}}

To render the glossary:

{{< code file=layouts/glossary/list.html >}}

{{ range .Pages }}
{{ .Title }}
{{ .Content }}
{{ end }}
{{< /code >}}

The published site will have this structure:

public/
├── glossary/
│   └── index.html
└── index.html

Example -- publish without listing

Publish a section's descendant pages without publishing the section page itself.

content/
├── books/
│   ├── _index.md
│   ├── book-1.md
│   └── book-2.md
└── _index.md

Set the build options in front matter:

{{< code-toggle file=content/books/_index.md fm=true >}} title = 'Books' [build] render = 'never' list = 'never' {{< /code-toggle >}}

The published site will have this structure:

public/
├── books/
│   ├── book-1/
│   │   └── index.html
│   └── book-2/
│       └── index.html
└── index.html

Example -- conditionally hide section

Consider this example. A documentation site has a team of contributors with access to 20 custom shortcodes. Each shortcode takes several arguments, and requires documentation for the contributors to reference when using them.

Instead of external documentation for the shortcodes, include an "internal" section that is hidden when building the production site.

content/
├── internal/
│   ├── shortcodes/
│   │   ├── _index.md
│   │   ├── shortcode-1.md
│   │   └── shortcode-2.md
│   └── _index.md
├── reference/
│   ├── _index.md
│   ├── reference-1.md
│   └── reference-2.md
├── tutorials/
│   ├── _index.md
│   ├── tutorial-1.md
│   └── tutorial-2.md
└── _index.md

Set the build options in front matter, using the cascade keyword to "cascade" the values down to descendant pages, and use the target keyword to target the production environment.

{{< code-toggle file=content/internal/_index.md >}} title = 'Internal' cascade [cascade.build] render = 'never' list = 'never' [cascade._target] environment = 'production' {{< /code-toggle >}}

The production site will have this structure:

public/
├── reference/
│   ├── reference-1/
│   │   └── index.html
│   ├── reference-2/
│   │   └── index.html
│   └── index.html
├── tutorials/
│   ├── tutorial-1/
│   │   └── index.html
│   ├── tutorial-2/
│   │   └── index.html
│   └── index.html
└── index.html