Debian Codegraph @

docs/content/en/hugo-pipes/introduction.md

raw
1 ---
2 title: Hugo Pipes
3 linkTitle: Introduction
4 description: Hugo Pipes is Hugo's asset processing set of functions.
5 categories: []
6 keywords: []
7 weight: 10
8 aliases: [/assets/]
9 ---
10
11 ## Find resources in assets
12
13 This is about global and remote resources.
14
15 global resource
16 : A file within the `assets` directory, or within any directory [mounted][] to the `assets` directory.
17
18 remote resource
19 : A file on a remote server, accessible via HTTP or HTTPS.
20
21 For `.Page` scoped resources, see the [page resources][] section.
22
23 ## Get a resource
24
25 In order to process an asset with Hugo Pipes, it must be retrieved as a resource.
26
27 For global resources, use:
28
29 - [`resources.ByType`][]
30 - [`resources.Get`][]
31 - [`resources.GetMatch`][]
32 - [`resources.Match`][]
33
34 For remote resources, use:
35
36 - [`resources.GetRemote`][]
37
38 ## Copy a resource
39
40 See the [`resources.Copy`][] function.
41
42 ## Asset directory
43
44 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.
45
46 ## Asset publishing
47
48 Hugo publishes assets to the `publishDir` (typically `public`) when you invoke `.Permalink`, `.RelPermalink`, or `.Publish`. You can use `.Content` to inline the asset.
49
50 ## Go Pipes
51
52 For improved readability, the Hugo Pipes examples of this documentation will be written using [Go Pipes][]:
53
54 ```go-html-template
55 {{ $style := resources.Get "sass/main.scss" | css.Sass | resources.Minify | resources.Fingerprint }}
56 <link rel="stylesheet" href="{{ $style.Permalink }}">
57 ```
58
59 ## Caching
60
61 Hugo Pipes invocations are cached based on the entire _pipe chain_.
62
63 An example of a pipe chain is:
64
65 ```go-html-template
66 {{ $mainJs := resources.Get "js/main.js" | js.Build "main.js" | minify | fingerprint }}
67 ```
68
69 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.
70
71 [Go Pipes]: /templates/introduction/#pipes
72 [`resources.ByType`]: /functions/resources/bytype/
73 [`resources.Copy`]: /functions/resources/copy/
74 [`resources.GetMatch`]: /functions/resources/getmatch/
75 [`resources.GetRemote`]: /functions/resources/getremote/
76 [`resources.Get`]: /functions/resources/get/
77 [`resources.Match`]: /functions/resources/match/
78 [mounted]: /configuration/module/#mounts
79 [page resources]: /content-management/page-resources/