mirror of
https://github.com/tiennm99/hugoDocs.git
synced 2026-10-14 20:17:17 +00:00
Correct GetRemote docs and examples
This commit is contained in:
1 parent
4e942166ab
commit
2f608055ff
1 file changed
+16
-10
@@ -18,16 +18,23 @@ toc: true
|
|||||||
aliases: [/assets/]
|
aliases: [/assets/]
|
||||||
---
|
---
|
||||||
|
|
||||||
## Get Resource with resources.Get andresources.GetRemote
|
## 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`. The first argument can be either a local the path to file relative to the `asset` directory/directories or a remote URL.
|
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:
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
||||||
{{ $local := resources.Get "sass/main.scss" }}
|
{{ $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" }}
|
{{ $remote := resources.GetRemote "https://www.example.com/styles.scss" }}
|
||||||
```
|
```
|
||||||
|
|
||||||
`resources.Get` and `resources.GetRemote` will always return `nil` if the resource could not be found.
|
`resources.Get` and `resources.GetRemote` return `nil` if the resource is not found.
|
||||||
|
|
||||||
### Error Handling
|
### Error Handling
|
||||||
|
|
||||||
@@ -36,7 +43,7 @@ In order to process an asset with Hugo Pipes, it must be retrieved as a `Resourc
|
|||||||
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.
|
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.
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
||||||
{{ with resources.Get "https://gohugo.io/images/gohugoio-card-1.png" }}
|
{{ with resources.GetRemote "https://gohugo.io/images/gohugoio-card-1.png" }}
|
||||||
{{ with .Err }}
|
{{ with .Err }}
|
||||||
{{ warnf "%s" . }}
|
{{ warnf "%s" . }}
|
||||||
{{ else }}
|
{{ else }}
|
||||||
@@ -49,22 +56,22 @@ Note that if you do not handle `.Err` yourself, Hugo will fail the build the fir
|
|||||||
|
|
||||||
### Remote Options
|
### Remote Options
|
||||||
|
|
||||||
When fetching a remote `Resource`, `resources.Get` takes an optional options map as the last argument, e.g.:
|
When fetching a remote `Resource`, `resources.GetRemote` takes an optional options map as the last argument, e.g.:
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
||||||
{{ $resource := resources.Get "https://example.org/api" (dict "headers" (dict "Authorization" "Bearer abcd")) }}
|
{{ $resource := resources.GetRemote "https://example.org/api" (dict "headers" (dict "Authorization" "Bearer abcd")) }}
|
||||||
```
|
```
|
||||||
|
|
||||||
If you need multiple values for the same header key, use a slice:
|
If you need multiple values for the same header key, use a slice:
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
||||||
{{ $resource := resources.Get "https://example.org/api" (dict "headers" (dict "X-List" (slice "a" "b" "c"))) }}
|
{{ $resource := resources.GetRemote "https://example.org/api" (dict "headers" (dict "X-List" (slice "a" "b" "c"))) }}
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also change the request method and set the request body:
|
You can also change the request method and set the request body:
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
||||||
{{ $postResponse := resources.Get "https://example.org/api" (dict
|
{{ $postResponse := resources.GetRemote "https://example.org/api" (dict
|
||||||
"method" "post"
|
"method" "post"
|
||||||
"body" `{"complete": true}`
|
"body" `{"complete": true}`
|
||||||
"headers" (dict
|
"headers" (dict
|
||||||
@@ -75,13 +82,12 @@ You can also change the request method and set the request body:
|
|||||||
|
|
||||||
### Caching of Remote Resources
|
### Caching of Remote Resources
|
||||||
|
|
||||||
Remote resources fetched with `resources.Get` will be cached on disk. See [Configure File Caches](/getting-started/configuration/#configure-file-caches) for details.
|
Remote resources fetched with `resources.GetRemote` will be cached on disk. See [Configure File Caches](/getting-started/configuration/#configure-file-caches) for details.
|
||||||
|
|
||||||
## Asset directory
|
## 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.
|
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
|
### Asset Publishing
|
||||||
|
|
||||||
Assets will only be published (to `/public`) if `.Permalink` or `.RelPermalink` is used. You can use `.Content` to inline the asset.
|
Assets will only be published (to `/public`) if `.Permalink` or `.RelPermalink` is used. You can use `.Content` to inline the asset.
|
||||||
|
|||||||
Reference in new issue
Block a user