hugo/docs/content/en/hugo-pipes/introduction.md
2018-07-19 09:18:11 +02:00

1.7 KiB
Executable file

title description date publishdate lastmod categories keywords menu weight sections_weight draft aliases
Hugo Pipes Introduction Hugo Pipes is Hugo's asset processing set of functions. 2018-07-14 2018-07-14 2018-07-14
asset management
docs
parent weight
pipes 20
01 01 false
/assets/

Asset directory

Asset files must be stored in the asset directory. This is /assets by default, but can be configured via the configuration file's assetDir key.

From file to resource

In order to process an asset with Hugo Pipes, it must be retrieved as a resource using resources.Get, which takes one argument: the filepath of the file relative to the asset directory.

{{ $style := resources.Get "sass/main.scss" }}

Asset publishing

Assets will only be published (to /public) if .Permalink or .RelPermalink is used.

Go Pipes

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

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

Method aliases

Each Hugo Pipes resources transformation method uses a camelCased alias (toCSS for resources.ToCSS). Non-transformation methods deprived of such aliases are resources.Get, resources.FromString and resources.ExecuteAsTemplate.

The example above can therefore also be written as follows:

{{ $style := resources.Get "sass/main.scss" | toCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $style.Permalink }}">