mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-23 21:53:09 +02:00
Merge commit '5be51ac3db225d5df501ed1fa1499c41d97dbf65'
This commit is contained in:
@@ -3,42 +3,36 @@ title: Colors
|
||||
description: Applicable to images, returns a slice of the most dominant colors using a simple histogram method.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related: []
|
||||
returnType: '[]images.Color'
|
||||
signatures: [RESOURCE.Colors]
|
||||
toc: true
|
||||
math: true
|
||||
params:
|
||||
functions_and_methods:
|
||||
returnType: '[]images.Color'
|
||||
signatures: [RESOURCE.Colors]
|
||||
---
|
||||
|
||||
The `Resources.Colors` method returns a slice of the most dominant colors in an image, ordered from most dominant to least dominant. This method is fast, but if you also downsize your image you can improve performance by extracting the colors from the scaled image.
|
||||
{{% include "/_common/methods/resource/global-page-remote-resources.md" %}}
|
||||
|
||||
{{% include "methods/resource/_common/global-page-remote-resources.md" %}}
|
||||
The `Resources.Colors` method returns a slice of the most dominant colors in an image, ordered from most dominant to least dominant. This method is fast, but if you also downsize your image you can improve performance by extracting the colors from the scaled image.
|
||||
|
||||
## Methods
|
||||
|
||||
Each color is an object with the following methods:
|
||||
|
||||
ColorHex
|
||||
### ColorHex
|
||||
|
||||
{{< new-in 0.125.0 />}}
|
||||
: (`string`) Returns the [hexadecimal color] value, prefixed with a hash sign.
|
||||
|
||||
Luminance
|
||||
(`string`) Returns the [hexadecimal color] value, prefixed with a hash sign.
|
||||
|
||||
### Luminance
|
||||
|
||||
{{< new-in 0.125.0 />}}
|
||||
: (`float64`) Returns the [relative luminance] of the color in the sRGB colorspace in the range [0, 1]. A value of `0` represents the darkest black, while a value of `1` represents the lightest white.
|
||||
|
||||
{{% note %}}
|
||||
Image filters such as [`images.Dither`], [`images.Padding`], and [`images.Text`] accept either hexadecimal color values or `images.Color` objects as arguments.
|
||||
(`float64`) Returns the [relative luminance] of the color in the sRGB colorspace in the range [0, 1]. A value of `0` represents the darkest black, while a value of `1` represents the lightest white.
|
||||
|
||||
Hugo renders an `images.Color` object as a hexadecimal color value.
|
||||
|
||||
[`images.Dither`]: /functions/images/dither/
|
||||
[`images.Padding`]: /functions/images/padding/
|
||||
[`images.Text`]: /functions/images/text/
|
||||
{{% /note %}}
|
||||
|
||||
[hexadecimal color]: https://developer.mozilla.org/en-US/docs/Web/CSS/hex-color
|
||||
[relative luminance]: https://www.w3.org/TR/WCAG21/#dfn-relative-luminance
|
||||
> [!note]
|
||||
> Image filters such as [`images.Dither`], [`images.Padding`], and [`images.Text`] accept either hexadecimal color values or `images.Color` objects as arguments.
|
||||
>
|
||||
> Hugo renders an `images.Color` object as a hexadecimal color value.
|
||||
|
||||
## Sorting
|
||||
|
||||
@@ -169,7 +163,12 @@ Calculate the contrast ratio to determine WCAG conformance:
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
[WCAG]: https://en.wikipedia.org/wiki/Web_Content_Accessibility_Guidelines
|
||||
[`images.Dither`]: /functions/images/dither/
|
||||
[`images.Padding`]: /functions/images/padding/
|
||||
[`images.Text`]: /functions/images/text/
|
||||
[contrast ratio]: https://www.w3.org/TR/WCAG21/#dfn-contrast-ratio
|
||||
[enhanced]: https://www.w3.org/WAI/WCAG22/quickref/?showtechniques=145#contrast-enhanced
|
||||
[hexadecimal color]: https://developer.mozilla.org/en-US/docs/Web/CSS/hex-color
|
||||
[minimum]: https://www.w3.org/WAI/WCAG22/quickref/?showtechniques=145#contrast-minimum
|
||||
[relative luminance]: https://www.w3.org/TR/WCAG21/#dfn-relative-luminance
|
||||
[WCAG]: https://en.wikipedia.org/wiki/Web_Content_Accessibility_Guidelines
|
||||
|
@@ -3,20 +3,21 @@ title: Content
|
||||
description: Returns the content of the given resource.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related: []
|
||||
returnType: any
|
||||
signatures: [RESOURCE.Content]
|
||||
toc:
|
||||
params:
|
||||
functions_and_methods:
|
||||
returnType: any
|
||||
signatures: [RESOURCE.Content]
|
||||
---
|
||||
|
||||
{{% include "/_common/methods/resource/global-page-remote-resources.md" %}}
|
||||
|
||||
The `Content` method on a `Resource` object returns `template.HTML` when the resource type is `page`, otherwise it returns a `string`.
|
||||
|
||||
[resource type]: /methods/resource/resourcetype/
|
||||
|
||||
{{< code file=assets/quotations/kipling.txt >}}
|
||||
```text {file="assets/quotations/kipling.txt"}
|
||||
He travels the fastest who travels alone.
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
To get the content:
|
||||
|
||||
@@ -57,5 +58,3 @@ To create inline JavaScript:
|
||||
<script>{{ .Content | safeJS }}</script>
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
{{% include "methods/resource/_common/global-page-remote-resources.md" %}}
|
||||
|
@@ -3,18 +3,14 @@ title: Crop
|
||||
description: Applicable to images, returns an image resource cropped to the given dimensions without resizing.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related:
|
||||
- methods/resource/Fit
|
||||
- methods/resource/Fill
|
||||
- methods/resource/Resize
|
||||
- methods/resource/Process
|
||||
- functions/images/Process
|
||||
returnType: images.ImageResource
|
||||
signatures: [RESOURCE.Crop SPEC]
|
||||
toc: true
|
||||
params:
|
||||
functions_and_methods:
|
||||
returnType: images.ImageResource
|
||||
signatures: [RESOURCE.Crop SPEC]
|
||||
---
|
||||
|
||||
{{% include "/_common/methods/resource/global-page-remote-resources.md" %}}
|
||||
|
||||
Crop an image to match the given dimensions without resizing. You must provide both width and height.
|
||||
|
||||
```go-html-template
|
||||
@@ -25,9 +21,7 @@ Crop an image to match the given dimensions without resizing. You must provide b
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
{{% include "methods/resource/_common/global-page-remote-resources.md" %}}
|
||||
|
||||
{{% include "/methods/resource/_common/processing-spec.md" %}}
|
||||
{{% include "/_common/methods/resource/processing-spec.md" %}}
|
||||
|
||||
## Example
|
||||
|
||||
|
@@ -3,18 +3,18 @@ title: Data
|
||||
description: Applicable to resources returned by the resources.GetRemote function, returns information from the HTTP response.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related:
|
||||
- functions/resources/GetRemote
|
||||
- methods/resource/Err
|
||||
returnType: map
|
||||
signatures: [RESOURCE.Data]
|
||||
params:
|
||||
functions_and_methods:
|
||||
returnType: map
|
||||
signatures: [RESOURCE.Data]
|
||||
---
|
||||
|
||||
The `Data` method on a resource returned by the [`resources.GetRemote`] function returns information from the HTTP response.
|
||||
|
||||
[`resources.GetRemote`]: /functions/resources/getremote/
|
||||
|
||||
## Example
|
||||
|
||||
```go-html-template
|
||||
{{ $url := "https://example.org/images/a.jpg" }}
|
||||
{{ $opts := dict "responseHeaders" (slice "Server") }}
|
||||
@@ -36,30 +36,31 @@ The `Data` method on a resource returned by the [`resources.GetRemote`] function
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
###### ContentLength
|
||||
## Methods
|
||||
|
||||
### ContentLength
|
||||
|
||||
(`int`) The content length in bytes.
|
||||
|
||||
###### ContentType
|
||||
### ContentType
|
||||
|
||||
(`string`) The content type.
|
||||
|
||||
###### Headers
|
||||
### Headers
|
||||
|
||||
(`map[string][]string`) A map of response headers matching those requested in the [`responseHeaders`] option passed to the `resources.GetRemote` function. The header name matching is case-insensitive. In most cases there will be one value per header key.
|
||||
|
||||
[`responseHeaders`]: /functions/resources/getremote/#responseheaders
|
||||
|
||||
###### Status
|
||||
### Status
|
||||
|
||||
(`string`) The HTTP status text.
|
||||
|
||||
###### StatusCode
|
||||
### StatusCode
|
||||
|
||||
(`int`) The HTTP status code.
|
||||
|
||||
###### TransferEncoding
|
||||
### TransferEncoding
|
||||
|
||||
(`string`) The transfer encoding.
|
||||
|
||||
[`resources.GetRemote`]: /functions/resources/getremote/
|
||||
[`responseHeaders`]: /functions/resources/getremote/#responseheaders
|
||||
|
@@ -1,22 +1,20 @@
|
||||
---
|
||||
title: Err
|
||||
description: Applicable to resources returned by the resources.GetRemote function, returns an error message if the HTTP request fails, else nil.
|
||||
description: Applicable to resources returned by the resources.GetRemote function, returns an error message if the HTTP request fails, else nil.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related:
|
||||
- functions/resources/GetRemote
|
||||
- methods/resource/Data
|
||||
returnType: resource.resourceError
|
||||
signatures: [RESOURCE.Err]
|
||||
params:
|
||||
functions_and_methods:
|
||||
returnType: resource.resourceError
|
||||
signatures: [RESOURCE.Err]
|
||||
expiryDate: 2027-01-16 # deprecated 2025-01-16 in v0.141.0
|
||||
---
|
||||
|
||||
{{% deprecated-in 0.141.0 %}}
|
||||
{{< deprecated-in 0.141.0 >}}
|
||||
Use the `try` statement instead. See [example].
|
||||
|
||||
[example]: /functions/go-template/try/#example
|
||||
{{% /deprecated-in %}}
|
||||
{{< /deprecated-in >}}
|
||||
|
||||
The `Err` method on a resource returned by the [`resources.GetRemote`] function returns an error message if the HTTP request fails, else nil. If you do not handle the error yourself, Hugo will fail the build.
|
||||
|
||||
@@ -58,6 +56,5 @@ To log an error as a warning instead of an error:
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
An HTTP response with a 404 status code is not an HTTP request error. To handle 404 status codes, code defensively using the nested `with-else-end` construct as shown above.
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> An HTTP response with a 404 status code is not an HTTP request error. To handle 404 status codes, code defensively using the nested `with-else-end` construct as shown above.
|
||||
|
@@ -3,28 +3,35 @@ title: Exif
|
||||
description: Applicable to JPEG, PNG, TIFF, and WebP images, returns an EXIF object containing image metadata.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related: []
|
||||
returnType: exif.ExifInfo
|
||||
signatures: [RESOURCE.Exif]
|
||||
toc: true
|
||||
params:
|
||||
functions_and_methods:
|
||||
returnType: exif.ExifInfo
|
||||
signatures: [RESOURCE.Exif]
|
||||
---
|
||||
|
||||
{{% include "/_common/methods/resource/global-page-remote-resources.md" %}}
|
||||
|
||||
Applicable to JPEG, PNG, TIFF, and WebP images, the `Exif` method on an image `Resource` object returns an [EXIF] object containing image metadata.
|
||||
|
||||
## Methods
|
||||
|
||||
Date
|
||||
: (`time.Time`) Returns the image creation date/time. Format with the [`time.Format`] function.
|
||||
### Date
|
||||
|
||||
Lat
|
||||
: (`float64`) Returns the GPS latitude in degrees.
|
||||
(`time.Time`) Returns the image creation date/time. Format with the [`time.Format`] function.
|
||||
|
||||
Long
|
||||
: (`float64`) Returns the GPS longitude in degrees.
|
||||
### Lat
|
||||
|
||||
Tags
|
||||
: (`exif.Tags`) Returns a collection of the available EXIF tags for this image. You may include or exclude specific tags from this collection in the [site configuration].
|
||||
(`float64`) Returns the GPS latitude in degrees.
|
||||
|
||||
### Long
|
||||
|
||||
(`float64`) Returns the GPS longitude in degrees.
|
||||
|
||||
### Tags
|
||||
|
||||
(`exif.Tags`) Returns a collection of the available EXIF tags for this image. You may include or exclude specific tags from this collection. See [configure imaging].
|
||||
|
||||
[configure imaging]: /configuration/imaging/#exif-data
|
||||
|
||||
## Examples
|
||||
|
||||
@@ -71,8 +78,5 @@ To list specific values:
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
{{% include "methods/resource/_common/global-page-remote-resources.md" %}}
|
||||
|
||||
[exif]: https://en.wikipedia.org/wiki/Exif
|
||||
[site configuration]: /content-management/image-processing/#exif-data
|
||||
[`time.Format`]: /functions/time/format/
|
||||
|
@@ -1,20 +1,16 @@
|
||||
---
|
||||
title: Fill
|
||||
description: Applicable to images, returns an image resource cropped and resized to the given dimensions.
|
||||
description: Applicable to images, returns an image resource cropped and resized to the given dimensions.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related:
|
||||
- methods/resource/Crop
|
||||
- methods/resource/Fit
|
||||
- methods/resource/Resize
|
||||
- methods/resource/Process
|
||||
- functions/images/Process
|
||||
returnType: images.ImageResource
|
||||
signatures: [RESOURCE.Fill SPEC]
|
||||
toc: true
|
||||
params:
|
||||
functions_and_methods:
|
||||
returnType: images.ImageResource
|
||||
signatures: [RESOURCE.Fill SPEC]
|
||||
---
|
||||
|
||||
{{% include "/_common/methods/resource/global-page-remote-resources.md" %}}
|
||||
|
||||
Crop and resize an image to match the given dimensions. You must provide both width and height.
|
||||
|
||||
```go-html-template
|
||||
@@ -25,9 +21,7 @@ Crop and resize an image to match the given dimensions. You must provide both wi
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
{{% include "methods/resource/_common/global-page-remote-resources.md" %}}
|
||||
|
||||
{{% include "/methods/resource/_common/processing-spec.md" %}}
|
||||
{{% include "/_common/methods/resource/processing-spec.md" %}}
|
||||
|
||||
## Example
|
||||
|
||||
|
@@ -3,14 +3,14 @@ title: Filter
|
||||
description: Applicable to images, applies one or more image filters to the given image resource.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related:
|
||||
- functions/images/Filter
|
||||
returnType: images.ImageResource
|
||||
signatures: [RESOURCE.Filter FILTER...]
|
||||
toc: true
|
||||
params:
|
||||
functions_and_methods:
|
||||
returnType: images.ImageResource
|
||||
signatures: [RESOURCE.Filter FILTER...]
|
||||
---
|
||||
|
||||
{{% include "/_common/methods/resource/global-page-remote-resources.md" %}}
|
||||
|
||||
Apply one or more [image filters](#image-filters) to the given image.
|
||||
|
||||
To apply a single filter:
|
||||
@@ -41,8 +41,6 @@ You can also apply image filters using the [`images.Filter`] function.
|
||||
|
||||
[`images.Filter`]: /functions/images/filter/
|
||||
|
||||
{{% include "methods/resource/_common/global-page-remote-resources.md" %}}
|
||||
|
||||
## Example
|
||||
|
||||
```go-html-template
|
||||
@@ -65,4 +63,4 @@ You can also apply image filters using the [`images.Filter`] function.
|
||||
|
||||
Use any of these filters with the `Filter` method.
|
||||
|
||||
{{< list-pages-in-section path=/functions/images filter=functions_images_no_filters filterType=exclude >}}
|
||||
{{% list-pages-in-section path=/functions/images filter=functions_images_no_filters filterType=exclude %}}
|
||||
|
@@ -1,20 +1,16 @@
|
||||
---
|
||||
title: Fit
|
||||
description: Applicable to images, returns an image resource downscaled to fit the given dimensions while maintaining aspect ratio.
|
||||
description: Applicable to images, returns an image resource downscaled to fit the given dimensions while maintaining aspect ratio.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related:
|
||||
- methods/resource/Crop
|
||||
- methods/resource/Fill
|
||||
- methods/resource/Resize
|
||||
- methods/resource/Process
|
||||
- functions/images/Process
|
||||
returnType: images.ImageResource
|
||||
signatures: [RESOURCE.Fit SPEC]
|
||||
toc: true
|
||||
params:
|
||||
functions_and_methods:
|
||||
returnType: images.ImageResource
|
||||
signatures: [RESOURCE.Fit SPEC]
|
||||
---
|
||||
|
||||
{{% include "/_common/methods/resource/global-page-remote-resources.md" %}}
|
||||
|
||||
Downscale an image to fit the given dimensions while maintaining aspect ratio. You must provide both width and height.
|
||||
|
||||
```go-html-template
|
||||
@@ -25,9 +21,7 @@ Downscale an image to fit the given dimensions while maintaining aspect ratio. Y
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
{{% include "methods/resource/_common/global-page-remote-resources.md" %}}
|
||||
|
||||
{{% include "/methods/resource/_common/processing-spec.md" %}}
|
||||
{{% include "/_common/methods/resource/processing-spec.md" %}}
|
||||
|
||||
## Example
|
||||
|
||||
|
@@ -3,13 +3,14 @@ title: Height
|
||||
description: Applicable to images, returns the height of the given resource.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related:
|
||||
- methods/resource/Width
|
||||
returnType: int
|
||||
signatures: [RESOURCE.Height]
|
||||
params:
|
||||
functions_and_methods:
|
||||
returnType: int
|
||||
signatures: [RESOURCE.Height]
|
||||
---
|
||||
|
||||
{{% include "/_common/methods/resource/global-page-remote-resources.md" %}}
|
||||
|
||||
```go-html-template
|
||||
{{ with resources.Get "images/a.jpg" }}
|
||||
{{ .Height }} → 400
|
||||
@@ -23,5 +24,3 @@ Use the `Width` and `Height` methods together when rendering an `img` element:
|
||||
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}">
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
{{% include "methods/resource/_common/global-page-remote-resources.md" %}}
|
||||
|
@@ -1,45 +0,0 @@
|
||||
---
|
||||
title: Key
|
||||
description: Returns the unique key for the given resource, equivalent to its publishing path.
|
||||
draft: true
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related:
|
||||
- methods/resource/Permalink
|
||||
- methods/resource/RelPermalink
|
||||
- methods/resource/Publish
|
||||
returnType: string
|
||||
signatures: [RESOURCE.Key]
|
||||
---
|
||||
|
||||
By way of example, consider this site configuration:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
baseURL = 'https://example.org/docs/'
|
||||
{{< /code-toggle >}}
|
||||
|
||||
And this template:
|
||||
|
||||
```go-html-template
|
||||
{{ with resources.Get "images/a.jpg" }}
|
||||
{{ with resources.Copy "foo/bar/b.jpg" . }}
|
||||
{{ .Key }} → foo/bar/b.jpg
|
||||
|
||||
{{ .Name }} → images/a.jpg
|
||||
{{ .Title }} → images/a.jpg
|
||||
|
||||
{{ .RelPermalink }} → /docs/foo/bar/b.jpg
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
We used the [`resources.Copy`] function to change the publishing path. The `Key` method returns the updated path, but note that it is different than the value returned by [`RelPermalink`]. The `RelPermalink` value includes the subdirectory segment of the `baseURL` in the site configuration.
|
||||
|
||||
The `Key` method is useful if you need to get the resource's publishing path without publishing the resource. Unlike the `Permalink`, `RelPermalink`, or `Publish` methods, calling `Key` will not publish the resource.
|
||||
|
||||
{{% include "methods/resource/_common/global-page-remote-resources.md" %}}
|
||||
|
||||
[`Permalink`]: /methods/resource/permalink/
|
||||
[`RelPermalink`]: /methods/resource/relpermalink/
|
||||
[`resources.Copy`]: /functions/resources/copy/
|
@@ -3,18 +3,21 @@ title: MediaType
|
||||
description: Returns a media type object for the given resource.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related: []
|
||||
returnType: media.Type
|
||||
signatures: [RESOURCE.MediaType]
|
||||
params:
|
||||
functions_and_methods:
|
||||
returnType: media.Type
|
||||
signatures: [RESOURCE.MediaType]
|
||||
---
|
||||
|
||||
{{% include "/_common/methods/resource/global-page-remote-resources.md" %}}
|
||||
|
||||
The `MediaType` method on a `Resource` object returns an object with additional methods.
|
||||
|
||||
## Methods
|
||||
|
||||
Type
|
||||
: (`string`) The resource's media type.
|
||||
### Type
|
||||
|
||||
(`string`) The resource's media type.
|
||||
|
||||
```go-html-template
|
||||
{{ with resources.Get "images/a.jpg" }}
|
||||
@@ -22,8 +25,9 @@ Type
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
MainType
|
||||
: (`string`) The main type of the resource’s media type.
|
||||
### MainType
|
||||
|
||||
(`string`) The main type of the resource's media type.
|
||||
|
||||
```go-html-template
|
||||
{{ with resources.Get "images/a.jpg" }}
|
||||
@@ -31,8 +35,9 @@ MainType
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
SubType
|
||||
: (`string`) The subtype of the resource’s media type. This may or may not correspond to the file suffix.
|
||||
### SubType
|
||||
|
||||
(`string`) The subtype of the resource's media type. This may or may not correspond to the file suffix.
|
||||
|
||||
```go-html-template
|
||||
{{ with resources.Get "images/a.jpg" }}
|
||||
@@ -40,8 +45,9 @@ SubType
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
Suffixes
|
||||
: (`slice`) A slice of possible file suffixes for the resource’s media type.
|
||||
### Suffixes
|
||||
|
||||
(`slice`) A slice of possible file suffixes for the resource's media type.
|
||||
|
||||
```go-html-template
|
||||
{{ with resources.Get "images/a.jpg" }}
|
||||
@@ -49,4 +55,12 @@ Suffixes
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
{{% include "methods/resource/_common/global-page-remote-resources.md" %}}
|
||||
### FirstSuffix.Suffix
|
||||
|
||||
(`string`) The first of the possible file suffixes for the resource's media type.
|
||||
|
||||
```go-html-template
|
||||
{{ with resources.Get "images/a.jpg" }}
|
||||
{{ .MediaType.FirstSuffix.Suffix }} → jpg
|
||||
{{ end }}
|
||||
```
|
||||
|
@@ -3,12 +3,10 @@ title: Name
|
||||
description: Returns the name of the given resource as optionally defined in front matter, falling back to its file path.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related:
|
||||
- methods/resource/Title
|
||||
returnType: string
|
||||
signatures: [RESOURCE.Name]
|
||||
toc: true
|
||||
params:
|
||||
functions_and_methods:
|
||||
returnType: string
|
||||
signatures: [RESOURCE.Name]
|
||||
---
|
||||
|
||||
The value returned by the `Name` method on a `Resource` object depends on the resource type.
|
||||
|
@@ -3,10 +3,10 @@ title: Params
|
||||
description: Returns a map of resource parameters as defined in front matter.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related: []
|
||||
returnType: map
|
||||
signatures: [RESOURCE.Params]
|
||||
params:
|
||||
functions_and_methods:
|
||||
returnType: map
|
||||
signatures: [RESOURCE.Params]
|
||||
---
|
||||
|
||||
Use the `Params` method with [page resources](g). It is not applicable to either [global resources](g) or [remote resources](g).
|
||||
|
@@ -1,16 +1,16 @@
|
||||
---
|
||||
title: Permalink
|
||||
description: Publishes the given resource and returns its permalink.
|
||||
description: Publishes the given resource and returns its permalink.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related:
|
||||
- methods/resource/RelPermalink
|
||||
- methods/resource/Publish
|
||||
returnType: string
|
||||
signatures: [RESOURCE.Permalink]
|
||||
params:
|
||||
functions_and_methods:
|
||||
returnType: string
|
||||
signatures: [RESOURCE.Permalink]
|
||||
---
|
||||
|
||||
{{% include "/_common/methods/resource/global-page-remote-resources.md" %}}
|
||||
|
||||
The `Permalink` method on a `Resource` object writes the resource to the publish directory, typically `public`, and returns its [permalink](g).
|
||||
|
||||
```go-html-template
|
||||
@@ -18,5 +18,3 @@ The `Permalink` method on a `Resource` object writes the resource to the publish
|
||||
{{ .Permalink }} → https://example.org/images/a.jpg
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
{{% include "methods/resource/_common/global-page-remote-resources.md" %}}
|
||||
|
@@ -3,18 +3,14 @@ title: Process
|
||||
description: Applicable to images, returns an image resource processed with the given specification.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related:
|
||||
- methods/resource/Crop
|
||||
- methods/resource/Fit
|
||||
- methods/resource/Fill
|
||||
- methods/resource/Resize
|
||||
- functions/images/Process
|
||||
returnType: images.ImageResource
|
||||
signatures: [RESOURCE.Process SPEC]
|
||||
toc: true
|
||||
params:
|
||||
functions_and_methods:
|
||||
returnType: images.ImageResource
|
||||
signatures: [RESOURCE.Process SPEC]
|
||||
---
|
||||
|
||||
{{% include "/_common/methods/resource/global-page-remote-resources.md" %}}
|
||||
|
||||
Process an image with the given specification. The specification can contain an optional action, one of `crop`, `fill`, `fit`, or `resize`. This means that you can use this method instead of [`Crop`], [`Fill`], [`Fit`], or [`Resize`].
|
||||
|
||||
```go-html-template
|
||||
@@ -37,9 +33,7 @@ You can also use this method to apply simple transformations such as rotation an
|
||||
|
||||
The `Process` method is also available as a filter, which is more effective if you need to apply multiple filters to an image. See [`images.Process`].
|
||||
|
||||
{{% include "methods/resource/_common/global-page-remote-resources.md" %}}
|
||||
|
||||
{{% include "/methods/resource/_common/processing-spec.md" %}}
|
||||
{{% include "/_common/methods/resource/processing-spec.md" %}}
|
||||
|
||||
## Example
|
||||
|
||||
|
@@ -3,14 +3,14 @@ title: Publish
|
||||
description: Publishes the given resource.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related:
|
||||
- methods/resource/Permalink
|
||||
- methods/resource/RelPermalink
|
||||
returnType: nil
|
||||
signatures: [RESOURCE.Publish]
|
||||
params:
|
||||
functions_and_methods:
|
||||
returnType: nil
|
||||
signatures: [RESOURCE.Publish]
|
||||
---
|
||||
|
||||
{{% include "/_common/methods/resource/global-page-remote-resources.md" %}}
|
||||
|
||||
The `Publish` method on a `Resource` object writes the resource to the publish directory, typically `public`.
|
||||
|
||||
```go-html-template
|
||||
@@ -30,5 +30,3 @@ Instead of this:
|
||||
```go-html-template
|
||||
{{ $noop := $resource.Permalink }}
|
||||
```
|
||||
|
||||
{{% include "methods/resource/_common/global-page-remote-resources.md" %}}
|
||||
|
@@ -3,14 +3,14 @@ title: RelPermalink
|
||||
description: Publishes the given resource and returns its relative permalink.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related:
|
||||
- methods/resource/Permalink
|
||||
- methods/resource/Publish
|
||||
returnType: string
|
||||
signatures: [RESOURCE.RelPermalink]
|
||||
params:
|
||||
functions_and_methods:
|
||||
returnType: string
|
||||
signatures: [RESOURCE.RelPermalink]
|
||||
---
|
||||
|
||||
{{% include "/_common/methods/resource/global-page-remote-resources.md" %}}
|
||||
|
||||
The `Permalink` method on a `Resource` object writes the resource to the publish directory, typically `public`, and returns its [relative permalink](g).
|
||||
|
||||
```go-html-template
|
||||
@@ -18,5 +18,3 @@ The `Permalink` method on a `Resource` object writes the resource to the publish
|
||||
{{ .RelPermalink }} → /images/a.jpg
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
{{% include "methods/resource/_common/global-page-remote-resources.md" %}}
|
||||
|
@@ -3,17 +3,14 @@ title: Resize
|
||||
description: Applicable to images, returns an image resource resized to the given width and/or height.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related:
|
||||
- methods/resource/Crop
|
||||
- methods/resource/Fit
|
||||
- methods/resource/Fill
|
||||
- methods/resource/Process
|
||||
- functions/images/Process
|
||||
returnType: images.ImageResource
|
||||
signatures: [RESOURCE.Resize SPEC]
|
||||
params:
|
||||
functions_and_methods:
|
||||
returnType: images.ImageResource
|
||||
signatures: [RESOURCE.Resize SPEC]
|
||||
---
|
||||
|
||||
{{% include "/_common/methods/resource/global-page-remote-resources.md" %}}
|
||||
|
||||
Resize an image to the given width and/or height.
|
||||
|
||||
If you specify both width and height, the resulting image will be disproportionally scaled unless the original image has the same aspect ratio.
|
||||
@@ -26,9 +23,7 @@ If you specify both width and height, the resulting image will be disproportiona
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
{{% include "methods/resource/_common/global-page-remote-resources.md" %}}
|
||||
|
||||
{{% include "/methods/resource/_common/processing-spec.md" %}}
|
||||
{{% include "/_common/methods/resource/processing-spec.md" %}}
|
||||
|
||||
## Example
|
||||
|
||||
|
@@ -3,12 +3,14 @@ title: ResourceType
|
||||
description: Returns the main type of the given resource's media type.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related: []
|
||||
returnType: string
|
||||
signatures: [RESOURCE.ResourceType]
|
||||
params:
|
||||
functions_and_methods:
|
||||
returnType: string
|
||||
signatures: [RESOURCE.ResourceType]
|
||||
---
|
||||
|
||||
{{% include "/_common/methods/resource/global-page-remote-resources.md" %}}
|
||||
|
||||
Common resource types include `audio`, `image`, `text`, and `video`.
|
||||
|
||||
```go-html-template
|
||||
@@ -34,10 +36,8 @@ content/
|
||||
|
||||
With the structure above, we can range through page resources of type `page` to build content:
|
||||
|
||||
{{< code file=layouts/lessons/single.html >}}
|
||||
```go-html-template {file="layouts/lessons/single.html"}
|
||||
{{ range .Resources.ByType "page" }}
|
||||
{{ .Content }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
{{% include "methods/resource/_common/global-page-remote-resources.md" %}}
|
||||
```
|
||||
|
@@ -3,12 +3,10 @@ title: Title
|
||||
description: Returns the title of the given resource as optionally defined in front matter, falling back to a relative path or hashed file name depending on resource type.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related:
|
||||
- methods/resource/Name
|
||||
returnType: string
|
||||
signatures: [RESOURCE.Title]
|
||||
toc: true
|
||||
params:
|
||||
functions_and_methods:
|
||||
returnType: string
|
||||
signatures: [RESOURCE.Title]
|
||||
---
|
||||
|
||||
The value returned by the `Title` method on a `Resource` object depends on the resource type.
|
||||
|
@@ -3,13 +3,14 @@ title: Width
|
||||
description: Applicable to images, returns the width of the given resource.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related:
|
||||
- methods/resource/Height
|
||||
returnType: int
|
||||
signatures: [RESOURCE.Width]
|
||||
params:
|
||||
functions_and_methods:
|
||||
returnType: int
|
||||
signatures: [RESOURCE.Width]
|
||||
---
|
||||
|
||||
{{% include "/_common/methods/resource/global-page-remote-resources.md" %}}
|
||||
|
||||
```go-html-template
|
||||
{{ with resources.Get "images/a.jpg" }}
|
||||
{{ .Width }} → 600
|
||||
@@ -23,5 +24,3 @@ Use the `Width` and `Height` methods together when rendering an `img` element:
|
||||
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}">
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
{{% include "methods/resource/_common/global-page-remote-resources.md" %}}
|
||||
|
@@ -1,13 +0,0 @@
|
||||
---
|
||||
cascade:
|
||||
_build:
|
||||
list: never
|
||||
publishResources: false
|
||||
render: never
|
||||
---
|
||||
|
||||
<!--
|
||||
Files within this headless branch bundle are Markdown snippets. Each file must contain front matter delimiters, though front matter fields are not required.
|
||||
|
||||
Include the rendered content using the "include" shortcode.
|
||||
-->
|
@@ -1,7 +0,0 @@
|
||||
---
|
||||
_comment: Do not remove front matter.
|
||||
---
|
||||
|
||||
{{% note %}}
|
||||
Use this method with [global resources](g), [page resources](g), or [remote resources](g).
|
||||
{{% /note %}}
|
@@ -1,36 +0,0 @@
|
||||
---
|
||||
_comment: Do not remove front matter.
|
||||
---
|
||||
|
||||
## Process specification
|
||||
|
||||
The process specification is a space-delimited, case-insensitive list of one or more of the following in any sequence:
|
||||
|
||||
action
|
||||
: Applicable to the [`Process`](/methods/resource/process) method only. Specify zero or one of `crop`, `fill`, `fit`, or `resize`. If you specify an action you must also provide dimensions.
|
||||
|
||||
dimensions
|
||||
: Provide width _or_ height when using the [`Resize`](/methods/resource/resize) method, else provide both width _and_ height. See [details](/content-management/image-processing/#dimensions).
|
||||
|
||||
anchor
|
||||
: Use with the [`Crop`](/methods/resource/crop) and [`Fill`](/methods/resource/fill) methods. Specify zero or one of `TopLeft`, `Top`, `TopRight`, `Left`, `Center`, `Right`, `BottomLeft`, `Bottom`, `BottomRight`, or `Smart`. Default is `Smart`. See [details](/content-management/image-processing/#anchor).
|
||||
|
||||
rotation
|
||||
: Typically specify zero or one of `r90`, `r180`, or `r270`. Also supports arbitrary rotation angles. See [details](/content-management/image-processing/#rotation).
|
||||
|
||||
target format
|
||||
: Specify zero or one of `gif`, `jpeg`, `png`, `tiff`, or `webp`. See [details](/content-management/image-processing/#target-format).
|
||||
|
||||
quality
|
||||
: Applicable to JPEG and WebP images. Optionally specify `qN` where `N` is an integer in the range [0, 100]. Default is `75`. See [details](/content-management/image-processing/#quality).
|
||||
|
||||
hint
|
||||
: Applicable to WebP images and equivalent to the `-preset` flag for the [`cwebp`] encoder. Specify zero or one of `drawing`, `icon`, `photo`, `picture`, or `text`. Default is `photo`. See [details](/content-management/image-processing/#hint).
|
||||
|
||||
[`cwebp`]: https://developers.google.com/speed/webp/docs/cwebp
|
||||
|
||||
background color
|
||||
: When converting a PNG or WebP with transparency to a format that does not support transparency, optionally specify a background color using a 3-digit or a 6-digit hexadecimal color code. Default is `#ffffff` (white). See [details](/content-management/image-processing/#background-color).
|
||||
|
||||
resampling filter
|
||||
: Typically specify zero or one of `Box`, `Lanczos`, `CatmullRom`, `MitchellNetravali`, `Linear`, or `NearestNeighbor`. Other resampling filters are available. See [details](/content-management/image-processing/#resampling-filter).
|
@@ -4,9 +4,4 @@ linkTitle: Resource
|
||||
description: Use these methods with global, page, and remote Resource objects.
|
||||
categories: []
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: methods
|
||||
---
|
||||
|
||||
Use these methods with global, page, and remote Resource objects.
|
||||
|
Reference in New Issue
Block a user