HUGO
Menu
GitHub 90089 stars Mastodon

Hugo Pipes

Hugo Pipes is Hugo’s asset processing set of functions.

Find resources in assets

This is about global and remote resources.

global resource
A file within the assets directory, or within any directory mounted to the assets directory.
remote resource
A file on a remote server, accessible via HTTP or HTTPS.

For .Page scoped resources, see the page resources section.

Get a resource

In order to process an asset with Hugo Pipes, it must be retrieved as a resource.

For global resources, use:

For remote resources, use:

Copy a resource

See the resources.Copy function.

Assets directory

Asset files must reside in the assets directory of the unified file system.

Asset publishing

Hugo publishes assets to the public directory when you invoke .Permalink, .RelPermalink, or .Publish. You can use .Content to inline the asset.

Go Pipes

For improved readability, the Hugo Pipes examples of this documentation will be written using Go Pipes:

{{ $style := resources.Get "sass/main.scss" | css.Sass | resources.Minify | resources.Fingerprint }}
<link rel="stylesheet" href="{{ $style.Permalink }}">

Caching

Hugo Pipes invocations are cached based on the entire pipe chain.

An example of a pipe chain is:

{{ $mainJs := resources.Get "js/main.js" | js.Build "main.js" | minify | fingerprint }}

The pipe chain is only invoked the first time it is encountered in a site build, and results are otherwise loaded from cache. As such, Hugo Pipes can be used in templates which are executed thousands or millions of times without negatively impacting the build performance.