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

168 lines
6.9 KiB
Markdown
Raw Normal View History

---
title: Hugo Pipes Introduction
Squashed 'docs/' changes from 316cec249..4eb10c1a9 4eb10c1a9 Set a sensible maxAge on the image cache 2c37f4f89 Update lists.md 8690c018f Update introduction.md 0458c3d88 Update index.md 150982f5e Update index.md 50dc0b6b9 Update multilingual.md 648598090 Configure image cache to use :cacheDir/images 4dfb523c3 Update introduction.md b94d42e6f Add text to social images d3253d2aa Add resources/_gen/images/ to .gitignore 8a56e1dfd Delete resources/_gen/images 1521e79b6 Update introduction.md c7110a597 Update introduction.md f7c4d220f Update introduction.md c14ecf1ff Update introduction.md c4b388c20 Fix shortcode in hugo-pipes/introduction (#1605) d9876bd68 Update introduction.md a39a532d5 Update introduction.md fa8758122 netlify: Hugo 0.90.1 50cc40570 Update Contribute to Hugo Development fc98fc82c Add .vscode dir to .gitignore (#1602) 8f8bcdefc Add frontmatter param to code-toggle shortcode (#1601) f3b432c7c Add markdownlint configuration file (#1597) 7ea3aea92 netlify: Bump to 0.90.0 e2b6f990b docs: Regenerate docs helper c02259e33 Merge commit '8d9511a08f14260cbfb73119e4afae50e5a9966d' 2e3573899 Add custom font support to images.Text 3186e6458 images: Text filter that draws text with the given options (#9239) 424f219eb tpl/transform: Optional options for highlight func 7993f17d0 Implement XML data support 1eb9d34cf Make resources.Get use a file cache for remote resources 8a0fffd56 Add remote support to resources.Get git-subtree-dir: docs git-subtree-split: 4eb10c1a9689aebf652011a6260a14bf8a3dcef4
2021-12-13 20:04:12 +00:00
linkTitle: Hugo Pipes
description: Hugo Pipes is Hugo's asset processing set of functions.
date: 2018-07-14
publishdate: 2018-07-14
lastmod: 2018-07-14
categories: [asset management]
keywords: []
menu:
docs:
parent: "pipes"
weight: 20
weight: 01
sections_weight: 01
draft: false
Squashed 'docs/' changes from 316cec249..4eb10c1a9 4eb10c1a9 Set a sensible maxAge on the image cache 2c37f4f89 Update lists.md 8690c018f Update introduction.md 0458c3d88 Update index.md 150982f5e Update index.md 50dc0b6b9 Update multilingual.md 648598090 Configure image cache to use :cacheDir/images 4dfb523c3 Update introduction.md b94d42e6f Add text to social images d3253d2aa Add resources/_gen/images/ to .gitignore 8a56e1dfd Delete resources/_gen/images 1521e79b6 Update introduction.md c7110a597 Update introduction.md f7c4d220f Update introduction.md c14ecf1ff Update introduction.md c4b388c20 Fix shortcode in hugo-pipes/introduction (#1605) d9876bd68 Update introduction.md a39a532d5 Update introduction.md fa8758122 netlify: Hugo 0.90.1 50cc40570 Update Contribute to Hugo Development fc98fc82c Add .vscode dir to .gitignore (#1602) 8f8bcdefc Add frontmatter param to code-toggle shortcode (#1601) f3b432c7c Add markdownlint configuration file (#1597) 7ea3aea92 netlify: Bump to 0.90.0 e2b6f990b docs: Regenerate docs helper c02259e33 Merge commit '8d9511a08f14260cbfb73119e4afae50e5a9966d' 2e3573899 Add custom font support to images.Text 3186e6458 images: Text filter that draws text with the given options (#9239) 424f219eb tpl/transform: Optional options for highlight func 7993f17d0 Implement XML data support 1eb9d34cf Make resources.Get use a file cache for remote resources 8a0fffd56 Add remote support to resources.Get git-subtree-dir: docs git-subtree-split: 4eb10c1a9689aebf652011a6260a14bf8a3dcef4
2021-12-13 20:04:12 +00:00
toc: true
aliases: [/assets/]
---
Squashed 'docs/' changes from 3f95a2ace..a393f4cf4 a393f4cf4 Add a Spellcheck GitHub Action and config 8b6b1c381 netlify: Bump to Hugo 0.93.3 84515c183 Delete deployment-with-nanobox.md dd45f9899 Fix typos in docs e69de81a9 Update build-options.md 7745b7891 netlify: Hubo 0.93.2 037d63364 Clarify GitHub Pages Branches 94660c34b add missing %s 325de15e2 fix link to latest release note since the release notes were moved to GitHub: https://gohugo.io/news/no-more-releasenotes-here/ dbff41d01 Update introduction.md 0ecd627f7 netlify: Hugo 0.93.1 a74e16582 Update diagrams.md 33e310956 Add Goat example to test styling fa0100a5b Update diagrams.md 64ac75367 Adjust diagram docs f1d600044 Update theme 95bedff1a netlify: Bump to Hugo 0.93.0 849a8437f Merge commit 'c1398b91a9f4c67876b31feb67516b252e654d3c' c0c60c43c docs: Regenerate docs helper 2c63fe518 cod: Regen CLI docs f33ba4e5a CodeblockContext method renames 979b47968 Move the Goat template to the correct place 2df37e9e8 Add Markdown diagrams and render hooks for code blocks bd8037d43 Allow images to be cropped without being resized 8b2af4b49 modules: Add modules.Workspace config for Go 1.18 46b99dea1 Add --printUnusedTemplates 1285302c9 commands: Rename --i18n-warnings to printI18nWarnings dea2242c6 commands: Rename --path-warnings, --print-men to --printPathWarnings, --printMemoryUsage db782ea46 deps: Update github.com/alecthomas/chroma v0.9.4 => v0.10.0 git-subtree-dir: docs git-subtree-split: a393f4cf43829011e96d109de2f039a9b05b2d16
2022-03-08 18:37:17 +00:00
## Find Resources in /assets
This is about the global Resources mounted inside `/assets`. For the `.Page` scoped Resources, see [Page Resources](/content-management/page-resources/).
Note that you can mount any directory into Hugo's virtual `assets` folder using the [Mount Configuration](/hugo-modules/configuration/#module-config-mounts).
| Function | Description |
| ------------- | ------------- |
| `resources.Get` | Get locates the filename given in Hugo's assets filesystem and creates a `Resource` object that can be used for further transformations. See [Get Resource with resources.Get and resources.GetRemote](#get-resource-with-resourcesget-and-resourcesgetremote). |
| `resources.GetRemote` | Same as `Get`, but it accepts remote URLs. See [Get Resource with resources.Get and resources.GetRemote](#get-resource-with-resourcesget-and-resourcesgetremote).|
| `resources.GetMatch` | `GetMatch` finds the first Resource matching the given pattern, or nil if none found. See Match for a more complete explanation about the rules used. |
| `resources.Match` | `Match` gets all resources matching the given base path prefix, e.g "*.png" will match all png files. The "*" does not match path delimiters (/), so if you organize your resources in sub-folders, you need to be explicit about it, e.g.: "images/*.png". To match any PNG image anywhere in the bundle you can do "\*\*.png", and to match all PNG images below the images folder, use "images/\*\*.jpg". The matching is case insensitive. Match matches by using the files name with path relative to the file system root with Unix style slashes (/) and no leading slash, e.g. "images/logo.png". See https://github.com/gobwas/glob for the full rules set.|
See the [GoDoc Page](https://pkg.go.dev/github.com/gohugoio/hugo@v0.93.1/tpl/resources) for the `resources` package for an up to date overview of all template functions in this namespace.
## Get Resource with resources.Get and resources.GetRemote
In order to process an asset with Hugo Pipes, it must be retrieved as a `Resource` using `resources.Get` or `resources.GetRemote`.
With `resources.Get`, the first argument is a local path relative to the `assets` directory/directories:
Squashed 'docs/' changes from 316cec249..4eb10c1a9 4eb10c1a9 Set a sensible maxAge on the image cache 2c37f4f89 Update lists.md 8690c018f Update introduction.md 0458c3d88 Update index.md 150982f5e Update index.md 50dc0b6b9 Update multilingual.md 648598090 Configure image cache to use :cacheDir/images 4dfb523c3 Update introduction.md b94d42e6f Add text to social images d3253d2aa Add resources/_gen/images/ to .gitignore 8a56e1dfd Delete resources/_gen/images 1521e79b6 Update introduction.md c7110a597 Update introduction.md f7c4d220f Update introduction.md c14ecf1ff Update introduction.md c4b388c20 Fix shortcode in hugo-pipes/introduction (#1605) d9876bd68 Update introduction.md a39a532d5 Update introduction.md fa8758122 netlify: Hugo 0.90.1 50cc40570 Update Contribute to Hugo Development fc98fc82c Add .vscode dir to .gitignore (#1602) 8f8bcdefc Add frontmatter param to code-toggle shortcode (#1601) f3b432c7c Add markdownlint configuration file (#1597) 7ea3aea92 netlify: Bump to 0.90.0 e2b6f990b docs: Regenerate docs helper c02259e33 Merge commit '8d9511a08f14260cbfb73119e4afae50e5a9966d' 2e3573899 Add custom font support to images.Text 3186e6458 images: Text filter that draws text with the given options (#9239) 424f219eb tpl/transform: Optional options for highlight func 7993f17d0 Implement XML data support 1eb9d34cf Make resources.Get use a file cache for remote resources 8a0fffd56 Add remote support to resources.Get git-subtree-dir: docs git-subtree-split: 4eb10c1a9689aebf652011a6260a14bf8a3dcef4
2021-12-13 20:04:12 +00:00
```go-html-template
{{ $local := resources.Get "sass/main.scss" }}
```
With `resources.GetRemote`, the first argument is a remote URL:
```go-html-template
{{ $remote := resources.GetRemote "https://www.example.com/styles.scss" }}
```
`resources.Get` and `resources.GetRemote` return `nil` if the resource is not found.
Squashed 'docs/' changes from 316cec249..4eb10c1a9 4eb10c1a9 Set a sensible maxAge on the image cache 2c37f4f89 Update lists.md 8690c018f Update introduction.md 0458c3d88 Update index.md 150982f5e Update index.md 50dc0b6b9 Update multilingual.md 648598090 Configure image cache to use :cacheDir/images 4dfb523c3 Update introduction.md b94d42e6f Add text to social images d3253d2aa Add resources/_gen/images/ to .gitignore 8a56e1dfd Delete resources/_gen/images 1521e79b6 Update introduction.md c7110a597 Update introduction.md f7c4d220f Update introduction.md c14ecf1ff Update introduction.md c4b388c20 Fix shortcode in hugo-pipes/introduction (#1605) d9876bd68 Update introduction.md a39a532d5 Update introduction.md fa8758122 netlify: Hugo 0.90.1 50cc40570 Update Contribute to Hugo Development fc98fc82c Add .vscode dir to .gitignore (#1602) 8f8bcdefc Add frontmatter param to code-toggle shortcode (#1601) f3b432c7c Add markdownlint configuration file (#1597) 7ea3aea92 netlify: Bump to 0.90.0 e2b6f990b docs: Regenerate docs helper c02259e33 Merge commit '8d9511a08f14260cbfb73119e4afae50e5a9966d' 2e3573899 Add custom font support to images.Text 3186e6458 images: Text filter that draws text with the given options (#9239) 424f219eb tpl/transform: Optional options for highlight func 7993f17d0 Implement XML data support 1eb9d34cf Make resources.Get use a file cache for remote resources 8a0fffd56 Add remote support to resources.Get git-subtree-dir: docs git-subtree-split: 4eb10c1a9689aebf652011a6260a14bf8a3dcef4
2021-12-13 20:04:12 +00:00
## Copy a Resource
{{< new-in "0.100.0" >}}
`resources.Copy` allows you to copy almost any Hugo `Resource` (the one exception is the `Page`), possibly most useful for renaming things:
```go-html-template
{{ $resized := $image.Resize "400x400" | resources.Copy "images/mynewname.jpg" }}
<img src="{{ $resized.RelPermalink }}">
```
### Caching
By default, Hugo calculates a cache key based on the `URL` and the `options` (e.g. headers) given.
{{< new-in "0.97.0" >}} You can override this by setting a `key` in the options map. This can be used to get more fine grained control over how often a remote resource is fetched, e.g.:
```go-html-template
{{ $cacheKey := print $url (now.Format "2006-01-02") }}
{{ $resource := resource.GetRemote $url (dict "key" $cacheKey) }}
```
Squashed 'docs/' changes from 316cec249..4eb10c1a9 4eb10c1a9 Set a sensible maxAge on the image cache 2c37f4f89 Update lists.md 8690c018f Update introduction.md 0458c3d88 Update index.md 150982f5e Update index.md 50dc0b6b9 Update multilingual.md 648598090 Configure image cache to use :cacheDir/images 4dfb523c3 Update introduction.md b94d42e6f Add text to social images d3253d2aa Add resources/_gen/images/ to .gitignore 8a56e1dfd Delete resources/_gen/images 1521e79b6 Update introduction.md c7110a597 Update introduction.md f7c4d220f Update introduction.md c14ecf1ff Update introduction.md c4b388c20 Fix shortcode in hugo-pipes/introduction (#1605) d9876bd68 Update introduction.md a39a532d5 Update introduction.md fa8758122 netlify: Hugo 0.90.1 50cc40570 Update Contribute to Hugo Development fc98fc82c Add .vscode dir to .gitignore (#1602) 8f8bcdefc Add frontmatter param to code-toggle shortcode (#1601) f3b432c7c Add markdownlint configuration file (#1597) 7ea3aea92 netlify: Bump to 0.90.0 e2b6f990b docs: Regenerate docs helper c02259e33 Merge commit '8d9511a08f14260cbfb73119e4afae50e5a9966d' 2e3573899 Add custom font support to images.Text 3186e6458 images: Text filter that draws text with the given options (#9239) 424f219eb tpl/transform: Optional options for highlight func 7993f17d0 Implement XML data support 1eb9d34cf Make resources.Get use a file cache for remote resources 8a0fffd56 Add remote support to resources.Get git-subtree-dir: docs git-subtree-split: 4eb10c1a9689aebf652011a6260a14bf8a3dcef4
2021-12-13 20:04:12 +00:00
### Error Handling
{{< new-in "0.91.0" >}}
Squashed 'docs/' changes from 316cec249..4eb10c1a9 4eb10c1a9 Set a sensible maxAge on the image cache 2c37f4f89 Update lists.md 8690c018f Update introduction.md 0458c3d88 Update index.md 150982f5e Update index.md 50dc0b6b9 Update multilingual.md 648598090 Configure image cache to use :cacheDir/images 4dfb523c3 Update introduction.md b94d42e6f Add text to social images d3253d2aa Add resources/_gen/images/ to .gitignore 8a56e1dfd Delete resources/_gen/images 1521e79b6 Update introduction.md c7110a597 Update introduction.md f7c4d220f Update introduction.md c14ecf1ff Update introduction.md c4b388c20 Fix shortcode in hugo-pipes/introduction (#1605) d9876bd68 Update introduction.md a39a532d5 Update introduction.md fa8758122 netlify: Hugo 0.90.1 50cc40570 Update Contribute to Hugo Development fc98fc82c Add .vscode dir to .gitignore (#1602) 8f8bcdefc Add frontmatter param to code-toggle shortcode (#1601) f3b432c7c Add markdownlint configuration file (#1597) 7ea3aea92 netlify: Bump to 0.90.0 e2b6f990b docs: Regenerate docs helper c02259e33 Merge commit '8d9511a08f14260cbfb73119e4afae50e5a9966d' 2e3573899 Add custom font support to images.Text 3186e6458 images: Text filter that draws text with the given options (#9239) 424f219eb tpl/transform: Optional options for highlight func 7993f17d0 Implement XML data support 1eb9d34cf Make resources.Get use a file cache for remote resources 8a0fffd56 Add remote support to resources.Get git-subtree-dir: docs git-subtree-split: 4eb10c1a9689aebf652011a6260a14bf8a3dcef4
2021-12-13 20:04:12 +00:00
The return value from `resources.GetRemote` includes an `.Err` method that will return an error if the call failed. If you want to just log any error as a `WARNING` you can use a construct similar to the one below.
Squashed 'docs/' changes from 316cec249..4eb10c1a9 4eb10c1a9 Set a sensible maxAge on the image cache 2c37f4f89 Update lists.md 8690c018f Update introduction.md 0458c3d88 Update index.md 150982f5e Update index.md 50dc0b6b9 Update multilingual.md 648598090 Configure image cache to use :cacheDir/images 4dfb523c3 Update introduction.md b94d42e6f Add text to social images d3253d2aa Add resources/_gen/images/ to .gitignore 8a56e1dfd Delete resources/_gen/images 1521e79b6 Update introduction.md c7110a597 Update introduction.md f7c4d220f Update introduction.md c14ecf1ff Update introduction.md c4b388c20 Fix shortcode in hugo-pipes/introduction (#1605) d9876bd68 Update introduction.md a39a532d5 Update introduction.md fa8758122 netlify: Hugo 0.90.1 50cc40570 Update Contribute to Hugo Development fc98fc82c Add .vscode dir to .gitignore (#1602) 8f8bcdefc Add frontmatter param to code-toggle shortcode (#1601) f3b432c7c Add markdownlint configuration file (#1597) 7ea3aea92 netlify: Bump to 0.90.0 e2b6f990b docs: Regenerate docs helper c02259e33 Merge commit '8d9511a08f14260cbfb73119e4afae50e5a9966d' 2e3573899 Add custom font support to images.Text 3186e6458 images: Text filter that draws text with the given options (#9239) 424f219eb tpl/transform: Optional options for highlight func 7993f17d0 Implement XML data support 1eb9d34cf Make resources.Get use a file cache for remote resources 8a0fffd56 Add remote support to resources.Get git-subtree-dir: docs git-subtree-split: 4eb10c1a9689aebf652011a6260a14bf8a3dcef4
2021-12-13 20:04:12 +00:00
```go-html-template
{{ with resources.GetRemote "https://gohugo.io/images/gohugoio-card-1.png" }}
Squashed 'docs/' changes from 316cec249..4eb10c1a9 4eb10c1a9 Set a sensible maxAge on the image cache 2c37f4f89 Update lists.md 8690c018f Update introduction.md 0458c3d88 Update index.md 150982f5e Update index.md 50dc0b6b9 Update multilingual.md 648598090 Configure image cache to use :cacheDir/images 4dfb523c3 Update introduction.md b94d42e6f Add text to social images d3253d2aa Add resources/_gen/images/ to .gitignore 8a56e1dfd Delete resources/_gen/images 1521e79b6 Update introduction.md c7110a597 Update introduction.md f7c4d220f Update introduction.md c14ecf1ff Update introduction.md c4b388c20 Fix shortcode in hugo-pipes/introduction (#1605) d9876bd68 Update introduction.md a39a532d5 Update introduction.md fa8758122 netlify: Hugo 0.90.1 50cc40570 Update Contribute to Hugo Development fc98fc82c Add .vscode dir to .gitignore (#1602) 8f8bcdefc Add frontmatter param to code-toggle shortcode (#1601) f3b432c7c Add markdownlint configuration file (#1597) 7ea3aea92 netlify: Bump to 0.90.0 e2b6f990b docs: Regenerate docs helper c02259e33 Merge commit '8d9511a08f14260cbfb73119e4afae50e5a9966d' 2e3573899 Add custom font support to images.Text 3186e6458 images: Text filter that draws text with the given options (#9239) 424f219eb tpl/transform: Optional options for highlight func 7993f17d0 Implement XML data support 1eb9d34cf Make resources.Get use a file cache for remote resources 8a0fffd56 Add remote support to resources.Get git-subtree-dir: docs git-subtree-split: 4eb10c1a9689aebf652011a6260a14bf8a3dcef4
2021-12-13 20:04:12 +00:00
{{ with .Err }}
{{ warnf "%s" . }}
{{ else }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
{{ end }}
{{ end }}
```
Note that if you do not handle `.Err` yourself, Hugo will fail the build the first time you start using the `Resource` object.
### Remote Options
When fetching a remote `Resource`, `resources.GetRemote` takes an optional options map as the last argument, e.g.:
Squashed 'docs/' changes from 316cec249..4eb10c1a9 4eb10c1a9 Set a sensible maxAge on the image cache 2c37f4f89 Update lists.md 8690c018f Update introduction.md 0458c3d88 Update index.md 150982f5e Update index.md 50dc0b6b9 Update multilingual.md 648598090 Configure image cache to use :cacheDir/images 4dfb523c3 Update introduction.md b94d42e6f Add text to social images d3253d2aa Add resources/_gen/images/ to .gitignore 8a56e1dfd Delete resources/_gen/images 1521e79b6 Update introduction.md c7110a597 Update introduction.md f7c4d220f Update introduction.md c14ecf1ff Update introduction.md c4b388c20 Fix shortcode in hugo-pipes/introduction (#1605) d9876bd68 Update introduction.md a39a532d5 Update introduction.md fa8758122 netlify: Hugo 0.90.1 50cc40570 Update Contribute to Hugo Development fc98fc82c Add .vscode dir to .gitignore (#1602) 8f8bcdefc Add frontmatter param to code-toggle shortcode (#1601) f3b432c7c Add markdownlint configuration file (#1597) 7ea3aea92 netlify: Bump to 0.90.0 e2b6f990b docs: Regenerate docs helper c02259e33 Merge commit '8d9511a08f14260cbfb73119e4afae50e5a9966d' 2e3573899 Add custom font support to images.Text 3186e6458 images: Text filter that draws text with the given options (#9239) 424f219eb tpl/transform: Optional options for highlight func 7993f17d0 Implement XML data support 1eb9d34cf Make resources.Get use a file cache for remote resources 8a0fffd56 Add remote support to resources.Get git-subtree-dir: docs git-subtree-split: 4eb10c1a9689aebf652011a6260a14bf8a3dcef4
2021-12-13 20:04:12 +00:00
```go-html-template
{{ $resource := resources.GetRemote "https://example.org/api" (dict "headers" (dict "Authorization" "Bearer abcd")) }}
Squashed 'docs/' changes from 316cec249..4eb10c1a9 4eb10c1a9 Set a sensible maxAge on the image cache 2c37f4f89 Update lists.md 8690c018f Update introduction.md 0458c3d88 Update index.md 150982f5e Update index.md 50dc0b6b9 Update multilingual.md 648598090 Configure image cache to use :cacheDir/images 4dfb523c3 Update introduction.md b94d42e6f Add text to social images d3253d2aa Add resources/_gen/images/ to .gitignore 8a56e1dfd Delete resources/_gen/images 1521e79b6 Update introduction.md c7110a597 Update introduction.md f7c4d220f Update introduction.md c14ecf1ff Update introduction.md c4b388c20 Fix shortcode in hugo-pipes/introduction (#1605) d9876bd68 Update introduction.md a39a532d5 Update introduction.md fa8758122 netlify: Hugo 0.90.1 50cc40570 Update Contribute to Hugo Development fc98fc82c Add .vscode dir to .gitignore (#1602) 8f8bcdefc Add frontmatter param to code-toggle shortcode (#1601) f3b432c7c Add markdownlint configuration file (#1597) 7ea3aea92 netlify: Bump to 0.90.0 e2b6f990b docs: Regenerate docs helper c02259e33 Merge commit '8d9511a08f14260cbfb73119e4afae50e5a9966d' 2e3573899 Add custom font support to images.Text 3186e6458 images: Text filter that draws text with the given options (#9239) 424f219eb tpl/transform: Optional options for highlight func 7993f17d0 Implement XML data support 1eb9d34cf Make resources.Get use a file cache for remote resources 8a0fffd56 Add remote support to resources.Get git-subtree-dir: docs git-subtree-split: 4eb10c1a9689aebf652011a6260a14bf8a3dcef4
2021-12-13 20:04:12 +00:00
```
Squashed 'docs/' changes from 316cec249..4eb10c1a9 4eb10c1a9 Set a sensible maxAge on the image cache 2c37f4f89 Update lists.md 8690c018f Update introduction.md 0458c3d88 Update index.md 150982f5e Update index.md 50dc0b6b9 Update multilingual.md 648598090 Configure image cache to use :cacheDir/images 4dfb523c3 Update introduction.md b94d42e6f Add text to social images d3253d2aa Add resources/_gen/images/ to .gitignore 8a56e1dfd Delete resources/_gen/images 1521e79b6 Update introduction.md c7110a597 Update introduction.md f7c4d220f Update introduction.md c14ecf1ff Update introduction.md c4b388c20 Fix shortcode in hugo-pipes/introduction (#1605) d9876bd68 Update introduction.md a39a532d5 Update introduction.md fa8758122 netlify: Hugo 0.90.1 50cc40570 Update Contribute to Hugo Development fc98fc82c Add .vscode dir to .gitignore (#1602) 8f8bcdefc Add frontmatter param to code-toggle shortcode (#1601) f3b432c7c Add markdownlint configuration file (#1597) 7ea3aea92 netlify: Bump to 0.90.0 e2b6f990b docs: Regenerate docs helper c02259e33 Merge commit '8d9511a08f14260cbfb73119e4afae50e5a9966d' 2e3573899 Add custom font support to images.Text 3186e6458 images: Text filter that draws text with the given options (#9239) 424f219eb tpl/transform: Optional options for highlight func 7993f17d0 Implement XML data support 1eb9d34cf Make resources.Get use a file cache for remote resources 8a0fffd56 Add remote support to resources.Get git-subtree-dir: docs git-subtree-split: 4eb10c1a9689aebf652011a6260a14bf8a3dcef4
2021-12-13 20:04:12 +00:00
If you need multiple values for the same header key, use a slice:
```go-html-template
{{ $resource := resources.GetRemote "https://example.org/api" (dict "headers" (dict "X-List" (slice "a" "b" "c"))) }}
```
Squashed 'docs/' changes from 316cec249..4eb10c1a9 4eb10c1a9 Set a sensible maxAge on the image cache 2c37f4f89 Update lists.md 8690c018f Update introduction.md 0458c3d88 Update index.md 150982f5e Update index.md 50dc0b6b9 Update multilingual.md 648598090 Configure image cache to use :cacheDir/images 4dfb523c3 Update introduction.md b94d42e6f Add text to social images d3253d2aa Add resources/_gen/images/ to .gitignore 8a56e1dfd Delete resources/_gen/images 1521e79b6 Update introduction.md c7110a597 Update introduction.md f7c4d220f Update introduction.md c14ecf1ff Update introduction.md c4b388c20 Fix shortcode in hugo-pipes/introduction (#1605) d9876bd68 Update introduction.md a39a532d5 Update introduction.md fa8758122 netlify: Hugo 0.90.1 50cc40570 Update Contribute to Hugo Development fc98fc82c Add .vscode dir to .gitignore (#1602) 8f8bcdefc Add frontmatter param to code-toggle shortcode (#1601) f3b432c7c Add markdownlint configuration file (#1597) 7ea3aea92 netlify: Bump to 0.90.0 e2b6f990b docs: Regenerate docs helper c02259e33 Merge commit '8d9511a08f14260cbfb73119e4afae50e5a9966d' 2e3573899 Add custom font support to images.Text 3186e6458 images: Text filter that draws text with the given options (#9239) 424f219eb tpl/transform: Optional options for highlight func 7993f17d0 Implement XML data support 1eb9d34cf Make resources.Get use a file cache for remote resources 8a0fffd56 Add remote support to resources.Get git-subtree-dir: docs git-subtree-split: 4eb10c1a9689aebf652011a6260a14bf8a3dcef4
2021-12-13 20:04:12 +00:00
You can also change the request method and set the request body:
```go-html-template
{{ $postResponse := resources.GetRemote "https://example.org/api" (dict
Squashed 'docs/' changes from 316cec249..4eb10c1a9 4eb10c1a9 Set a sensible maxAge on the image cache 2c37f4f89 Update lists.md 8690c018f Update introduction.md 0458c3d88 Update index.md 150982f5e Update index.md 50dc0b6b9 Update multilingual.md 648598090 Configure image cache to use :cacheDir/images 4dfb523c3 Update introduction.md b94d42e6f Add text to social images d3253d2aa Add resources/_gen/images/ to .gitignore 8a56e1dfd Delete resources/_gen/images 1521e79b6 Update introduction.md c7110a597 Update introduction.md f7c4d220f Update introduction.md c14ecf1ff Update introduction.md c4b388c20 Fix shortcode in hugo-pipes/introduction (#1605) d9876bd68 Update introduction.md a39a532d5 Update introduction.md fa8758122 netlify: Hugo 0.90.1 50cc40570 Update Contribute to Hugo Development fc98fc82c Add .vscode dir to .gitignore (#1602) 8f8bcdefc Add frontmatter param to code-toggle shortcode (#1601) f3b432c7c Add markdownlint configuration file (#1597) 7ea3aea92 netlify: Bump to 0.90.0 e2b6f990b docs: Regenerate docs helper c02259e33 Merge commit '8d9511a08f14260cbfb73119e4afae50e5a9966d' 2e3573899 Add custom font support to images.Text 3186e6458 images: Text filter that draws text with the given options (#9239) 424f219eb tpl/transform: Optional options for highlight func 7993f17d0 Implement XML data support 1eb9d34cf Make resources.Get use a file cache for remote resources 8a0fffd56 Add remote support to resources.Get git-subtree-dir: docs git-subtree-split: 4eb10c1a9689aebf652011a6260a14bf8a3dcef4
2021-12-13 20:04:12 +00:00
"method" "post"
"body" `{"complete": true}`
"headers" (dict
"Content-Type" "application/json"
)
)}}
```
### Caching of Remote Resources
Remote resources fetched with `resources.GetRemote` will be cached on disk. See [Configure File Caches](/getting-started/configuration/#configure-file-caches) for details.
Squashed 'docs/' changes from 316cec249..4eb10c1a9 4eb10c1a9 Set a sensible maxAge on the image cache 2c37f4f89 Update lists.md 8690c018f Update introduction.md 0458c3d88 Update index.md 150982f5e Update index.md 50dc0b6b9 Update multilingual.md 648598090 Configure image cache to use :cacheDir/images 4dfb523c3 Update introduction.md b94d42e6f Add text to social images d3253d2aa Add resources/_gen/images/ to .gitignore 8a56e1dfd Delete resources/_gen/images 1521e79b6 Update introduction.md c7110a597 Update introduction.md f7c4d220f Update introduction.md c14ecf1ff Update introduction.md c4b388c20 Fix shortcode in hugo-pipes/introduction (#1605) d9876bd68 Update introduction.md a39a532d5 Update introduction.md fa8758122 netlify: Hugo 0.90.1 50cc40570 Update Contribute to Hugo Development fc98fc82c Add .vscode dir to .gitignore (#1602) 8f8bcdefc Add frontmatter param to code-toggle shortcode (#1601) f3b432c7c Add markdownlint configuration file (#1597) 7ea3aea92 netlify: Bump to 0.90.0 e2b6f990b docs: Regenerate docs helper c02259e33 Merge commit '8d9511a08f14260cbfb73119e4afae50e5a9966d' 2e3573899 Add custom font support to images.Text 3186e6458 images: Text filter that draws text with the given options (#9239) 424f219eb tpl/transform: Optional options for highlight func 7993f17d0 Implement XML data support 1eb9d34cf Make resources.Get use a file cache for remote resources 8a0fffd56 Add remote support to resources.Get git-subtree-dir: docs git-subtree-split: 4eb10c1a9689aebf652011a6260a14bf8a3dcef4
2021-12-13 20:04:12 +00:00
## Asset directory
Squashed 'docs/' changes from 316cec249..4eb10c1a9 4eb10c1a9 Set a sensible maxAge on the image cache 2c37f4f89 Update lists.md 8690c018f Update introduction.md 0458c3d88 Update index.md 150982f5e Update index.md 50dc0b6b9 Update multilingual.md 648598090 Configure image cache to use :cacheDir/images 4dfb523c3 Update introduction.md b94d42e6f Add text to social images d3253d2aa Add resources/_gen/images/ to .gitignore 8a56e1dfd Delete resources/_gen/images 1521e79b6 Update introduction.md c7110a597 Update introduction.md f7c4d220f Update introduction.md c14ecf1ff Update introduction.md c4b388c20 Fix shortcode in hugo-pipes/introduction (#1605) d9876bd68 Update introduction.md a39a532d5 Update introduction.md fa8758122 netlify: Hugo 0.90.1 50cc40570 Update Contribute to Hugo Development fc98fc82c Add .vscode dir to .gitignore (#1602) 8f8bcdefc Add frontmatter param to code-toggle shortcode (#1601) f3b432c7c Add markdownlint configuration file (#1597) 7ea3aea92 netlify: Bump to 0.90.0 e2b6f990b docs: Regenerate docs helper c02259e33 Merge commit '8d9511a08f14260cbfb73119e4afae50e5a9966d' 2e3573899 Add custom font support to images.Text 3186e6458 images: Text filter that draws text with the given options (#9239) 424f219eb tpl/transform: Optional options for highlight func 7993f17d0 Implement XML data support 1eb9d34cf Make resources.Get use a file cache for remote resources 8a0fffd56 Add remote support to resources.Get git-subtree-dir: docs git-subtree-split: 4eb10c1a9689aebf652011a6260a14bf8a3dcef4
2021-12-13 20:04:12 +00:00
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.
### Asset Publishing
Hugo publishes assets to the to the `publishDir` (typically `public`) when you invoke `.Permalink`, `.RelPermalink`, or `.Publish`. You can use `.Content` to inline the asset.
Squashed 'docs/' changes from 316cec249..4eb10c1a9 4eb10c1a9 Set a sensible maxAge on the image cache 2c37f4f89 Update lists.md 8690c018f Update introduction.md 0458c3d88 Update index.md 150982f5e Update index.md 50dc0b6b9 Update multilingual.md 648598090 Configure image cache to use :cacheDir/images 4dfb523c3 Update introduction.md b94d42e6f Add text to social images d3253d2aa Add resources/_gen/images/ to .gitignore 8a56e1dfd Delete resources/_gen/images 1521e79b6 Update introduction.md c7110a597 Update introduction.md f7c4d220f Update introduction.md c14ecf1ff Update introduction.md c4b388c20 Fix shortcode in hugo-pipes/introduction (#1605) d9876bd68 Update introduction.md a39a532d5 Update introduction.md fa8758122 netlify: Hugo 0.90.1 50cc40570 Update Contribute to Hugo Development fc98fc82c Add .vscode dir to .gitignore (#1602) 8f8bcdefc Add frontmatter param to code-toggle shortcode (#1601) f3b432c7c Add markdownlint configuration file (#1597) 7ea3aea92 netlify: Bump to 0.90.0 e2b6f990b docs: Regenerate docs helper c02259e33 Merge commit '8d9511a08f14260cbfb73119e4afae50e5a9966d' 2e3573899 Add custom font support to images.Text 3186e6458 images: Text filter that draws text with the given options (#9239) 424f219eb tpl/transform: Optional options for highlight func 7993f17d0 Implement XML data support 1eb9d34cf Make resources.Get use a file cache for remote resources 8a0fffd56 Add remote support to resources.Get git-subtree-dir: docs git-subtree-split: 4eb10c1a9689aebf652011a6260a14bf8a3dcef4
2021-12-13 20:04:12 +00:00
## Go Pipes
For improved readability, the Hugo Pipes examples of this documentation will be written using [Go Pipes](/templates/introduction/#pipes):
Squashed 'docs/' changes from 316cec249..4eb10c1a9 4eb10c1a9 Set a sensible maxAge on the image cache 2c37f4f89 Update lists.md 8690c018f Update introduction.md 0458c3d88 Update index.md 150982f5e Update index.md 50dc0b6b9 Update multilingual.md 648598090 Configure image cache to use :cacheDir/images 4dfb523c3 Update introduction.md b94d42e6f Add text to social images d3253d2aa Add resources/_gen/images/ to .gitignore 8a56e1dfd Delete resources/_gen/images 1521e79b6 Update introduction.md c7110a597 Update introduction.md f7c4d220f Update introduction.md c14ecf1ff Update introduction.md c4b388c20 Fix shortcode in hugo-pipes/introduction (#1605) d9876bd68 Update introduction.md a39a532d5 Update introduction.md fa8758122 netlify: Hugo 0.90.1 50cc40570 Update Contribute to Hugo Development fc98fc82c Add .vscode dir to .gitignore (#1602) 8f8bcdefc Add frontmatter param to code-toggle shortcode (#1601) f3b432c7c Add markdownlint configuration file (#1597) 7ea3aea92 netlify: Bump to 0.90.0 e2b6f990b docs: Regenerate docs helper c02259e33 Merge commit '8d9511a08f14260cbfb73119e4afae50e5a9966d' 2e3573899 Add custom font support to images.Text 3186e6458 images: Text filter that draws text with the given options (#9239) 424f219eb tpl/transform: Optional options for highlight func 7993f17d0 Implement XML data support 1eb9d34cf Make resources.Get use a file cache for remote resources 8a0fffd56 Add remote support to resources.Get git-subtree-dir: docs git-subtree-split: 4eb10c1a9689aebf652011a6260a14bf8a3dcef4
2021-12-13 20:04:12 +00:00
```go-html-template
{{ $style := resources.Get "sass/main.scss" | resources.ToCSS | resources.Minify | resources.Fingerprint }}
<link rel="stylesheet" href="{{ $style.Permalink }}">
```
Squashed 'docs/' changes from 316cec249..4eb10c1a9 4eb10c1a9 Set a sensible maxAge on the image cache 2c37f4f89 Update lists.md 8690c018f Update introduction.md 0458c3d88 Update index.md 150982f5e Update index.md 50dc0b6b9 Update multilingual.md 648598090 Configure image cache to use :cacheDir/images 4dfb523c3 Update introduction.md b94d42e6f Add text to social images d3253d2aa Add resources/_gen/images/ to .gitignore 8a56e1dfd Delete resources/_gen/images 1521e79b6 Update introduction.md c7110a597 Update introduction.md f7c4d220f Update introduction.md c14ecf1ff Update introduction.md c4b388c20 Fix shortcode in hugo-pipes/introduction (#1605) d9876bd68 Update introduction.md a39a532d5 Update introduction.md fa8758122 netlify: Hugo 0.90.1 50cc40570 Update Contribute to Hugo Development fc98fc82c Add .vscode dir to .gitignore (#1602) 8f8bcdefc Add frontmatter param to code-toggle shortcode (#1601) f3b432c7c Add markdownlint configuration file (#1597) 7ea3aea92 netlify: Bump to 0.90.0 e2b6f990b docs: Regenerate docs helper c02259e33 Merge commit '8d9511a08f14260cbfb73119e4afae50e5a9966d' 2e3573899 Add custom font support to images.Text 3186e6458 images: Text filter that draws text with the given options (#9239) 424f219eb tpl/transform: Optional options for highlight func 7993f17d0 Implement XML data support 1eb9d34cf Make resources.Get use a file cache for remote resources 8a0fffd56 Add remote support to resources.Get git-subtree-dir: docs git-subtree-split: 4eb10c1a9689aebf652011a6260a14bf8a3dcef4
2021-12-13 20:04:12 +00:00
## 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`, `resources.ExecuteAsTemplate` and `resources.Concat`.
The example above can therefore also be written as follows:
Squashed 'docs/' changes from 316cec249..4eb10c1a9 4eb10c1a9 Set a sensible maxAge on the image cache 2c37f4f89 Update lists.md 8690c018f Update introduction.md 0458c3d88 Update index.md 150982f5e Update index.md 50dc0b6b9 Update multilingual.md 648598090 Configure image cache to use :cacheDir/images 4dfb523c3 Update introduction.md b94d42e6f Add text to social images d3253d2aa Add resources/_gen/images/ to .gitignore 8a56e1dfd Delete resources/_gen/images 1521e79b6 Update introduction.md c7110a597 Update introduction.md f7c4d220f Update introduction.md c14ecf1ff Update introduction.md c4b388c20 Fix shortcode in hugo-pipes/introduction (#1605) d9876bd68 Update introduction.md a39a532d5 Update introduction.md fa8758122 netlify: Hugo 0.90.1 50cc40570 Update Contribute to Hugo Development fc98fc82c Add .vscode dir to .gitignore (#1602) 8f8bcdefc Add frontmatter param to code-toggle shortcode (#1601) f3b432c7c Add markdownlint configuration file (#1597) 7ea3aea92 netlify: Bump to 0.90.0 e2b6f990b docs: Regenerate docs helper c02259e33 Merge commit '8d9511a08f14260cbfb73119e4afae50e5a9966d' 2e3573899 Add custom font support to images.Text 3186e6458 images: Text filter that draws text with the given options (#9239) 424f219eb tpl/transform: Optional options for highlight func 7993f17d0 Implement XML data support 1eb9d34cf Make resources.Get use a file cache for remote resources 8a0fffd56 Add remote support to resources.Get git-subtree-dir: docs git-subtree-split: 4eb10c1a9689aebf652011a6260a14bf8a3dcef4
2021-12-13 20:04:12 +00:00
```go-html-template
{{ $style := resources.Get "sass/main.scss" | toCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $style.Permalink }}">
```
Squashed 'docs/' changes from 316cec249..4eb10c1a9 4eb10c1a9 Set a sensible maxAge on the image cache 2c37f4f89 Update lists.md 8690c018f Update introduction.md 0458c3d88 Update index.md 150982f5e Update index.md 50dc0b6b9 Update multilingual.md 648598090 Configure image cache to use :cacheDir/images 4dfb523c3 Update introduction.md b94d42e6f Add text to social images d3253d2aa Add resources/_gen/images/ to .gitignore 8a56e1dfd Delete resources/_gen/images 1521e79b6 Update introduction.md c7110a597 Update introduction.md f7c4d220f Update introduction.md c14ecf1ff Update introduction.md c4b388c20 Fix shortcode in hugo-pipes/introduction (#1605) d9876bd68 Update introduction.md a39a532d5 Update introduction.md fa8758122 netlify: Hugo 0.90.1 50cc40570 Update Contribute to Hugo Development fc98fc82c Add .vscode dir to .gitignore (#1602) 8f8bcdefc Add frontmatter param to code-toggle shortcode (#1601) f3b432c7c Add markdownlint configuration file (#1597) 7ea3aea92 netlify: Bump to 0.90.0 e2b6f990b docs: Regenerate docs helper c02259e33 Merge commit '8d9511a08f14260cbfb73119e4afae50e5a9966d' 2e3573899 Add custom font support to images.Text 3186e6458 images: Text filter that draws text with the given options (#9239) 424f219eb tpl/transform: Optional options for highlight func 7993f17d0 Implement XML data support 1eb9d34cf Make resources.Get use a file cache for remote resources 8a0fffd56 Add remote support to resources.Get git-subtree-dir: docs git-subtree-split: 4eb10c1a9689aebf652011a6260a14bf8a3dcef4
2021-12-13 20:04:12 +00:00
## Caching
Hugo Pipes invocations are cached based on the entire _pipe chain_.
An example of a pipe chain is:
```go-html-template
{{ $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.