Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions content/en/_common/functions/go-html-template-package.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
_comment: Do not remove front matter.
---

Hugo uses Go's [text/template] and [html/template] packages.
Hugo uses Go's [`text/template`] and [`html/template`] packages.

The text/template package implements data-driven templates for generating textual output, while the html/template package implements data-driven templates for generating HTML output safe against code injection.
The `text/template` package implements data-driven templates for generating textual output, while the `html/template` package implements data-driven templates for generating HTML output safe against code injection.

By default, Hugo uses the html/template package when rendering HTML files.
By default, Hugo uses the `html/template` package when rendering HTML files.

To generate HTML output that is safe against code injection, the html/template package escapes strings in certain contexts.
To generate HTML output that is safe against code injection, the `html/template` package escapes strings in certain contexts.

[text/template]: https://pkg.go.dev/text/template
[html/template]: https://pkg.go.dev/html/template
[`text/template`]: https://pkg.go.dev/text/template
[`html/template`]: https://pkg.go.dev/html/template
4 changes: 2 additions & 2 deletions content/en/_common/functions/go-template/text-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
_comment: Do not remove front matter.
---

See Go's [text/template] documentation for more information.
See Go's [`text/template`] documentation for more information.

[text/template]: https://pkg.go.dev/text/template
[`text/template`]: https://pkg.go.dev/text/template
4 changes: 2 additions & 2 deletions content/en/_common/methods/resource/processing-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ action
: Specify one of `crop`, `fill`, `fit`, or `resize`. This is applicable to the [`Process`][] method and the [`images.Process`][] filter. If you specify an action, you must also provide dimensions.

anchor
: The focal point used when cropping or filling an image. Valid options include `TopLeft`, `Top`, `TopRight`, `Left`, `Center`, `Right`, `BottomLeft`, `Bottom`, `BottomRight`, or `Smart`. The `Smart` option utilizes the [`smartcrop.js`][] library to identify the most interesting area of the image. This defaults to the [`anchor`][] parameter in your project configuration.
: The focal point used when cropping or filling an image. Valid options include `TopLeft`, `Top`, `TopRight`, `Left`, `Center`, `Right`, `BottomLeft`, `Bottom`, `BottomRight`, or `Smart`. The `Smart` option utilizes the [`muesli/smartcrop`][] package to identify the most interesting area of the image. This defaults to the [`anchor`][] parameter in your project configuration.

background color
: The background color used when converting transparent images to formats that do not support transparency, such as PNG to JPEG. This color also fills the empty space created when rotating an image by a non-orthogonal angle if the space is not transparent and a background color is not specified in the processing specification. The value must be an RGB [hexadecimal color][]. This defaults to the [`bgColor`][] parameter in your project configuration.
Expand Down Expand Up @@ -62,12 +62,12 @@ rotation
[`bgcolor`]: /configuration/imaging/#bgcolor
[`compression`]: /configuration/imaging/#compression
[`cwebp`]: https://developers.google.com/speed/webp/docs/cwebp
[`muesli/smartcrop`]: https://github.com/muesli/smartcrop
[`hint`]: /configuration/imaging/#hint
[`images.AutoOrient`]: /functions/images/autoorient/
[`images.Process`]: /functions/images/process/
[`Process`]: /methods/resource/process
[`quality`]: /configuration/imaging/#quality
[`resampleFilter`]: /configuration/imaging/#resamplefilter
[`smartcrop.js`]: https://github.com/jwagner/smartcrop.js
[hexadecimal color]: https://developer.mozilla.org/en-US/docs/Web/CSS/hex-color
[source documentation]: https://github.com/disintegration/imaging#image-resizing
4 changes: 2 additions & 2 deletions content/en/commands/hugo_gen_chromastyles.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Generate CSS stylesheet for the Chroma code highlighter

Generate CSS stylesheet for the Chroma code highlighter for a given style. This stylesheet is needed if markup.highlight.noClasses is disabled in config.

See https://xyproto.github.io/splash/docs/all.html for a preview of the available styles
See https://gohugo.io/quick-reference/syntax-highlighting-styles/ for a preview of the available styles.

```
hugo gen chromastyles [flags] [args]
Expand All @@ -26,7 +26,7 @@ hugo gen chromastyles [flags] [args]
--lineNumbersTableStyle string foreground and background colors for table line numbers, e.g. --lineNumbersTableStyle "#fff000 bg:#000fff"
--omitClassComments omit CSS class comment prefixes in the generated CSS
--omitEmpty omit empty CSS rules (deprecated, no longer needed)
--style string highlighter style (see https://xyproto.github.io/splash/docs/) (default "friendly")
--style string highlighter style (default "friendly")
```

### Options inherited from parent commands
Expand Down
3 changes: 3 additions & 0 deletions content/en/configuration/caches.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ images
misc
: Caches miscellaneous data.

modulegitinfo
: Caches Git information for modules.

modulequeries
: Caches the results of module resolution queries.

Expand Down
90 changes: 32 additions & 58 deletions content/en/configuration/imaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,16 @@ categories: []
keywords: []
---

## Processing options

These are the default settings for processing images:

{{< code-toggle file=hugo >}}
[imaging]
anchor = 'Smart'
bgColor = '#ffffff'
compression = 'lossy'
quality = 75
resampleFilter = 'box'
{{< /code-toggle >}}
{{< code-toggle config=imaging />}}

## Top-level options

These global settings define how Hugo handles the fundamental aspects of image manipulation, such as cropping logic, background colors, and general output quality.

anchor
: (`string`) The focal point used when cropping or filling an image. Valid options include `TopLeft`, `Top`, `TopRight`, `Left`, `Center`, `Right`, `BottomLeft`, `Bottom`, `BottomRight`, or `Smart`. The `Smart` option utilizes the [`smartcrop.js`][] library to identify the most interesting area of the image. Default is `Smart`.
: (`string`) The focal point used when cropping or filling an image. Valid case-insensitive options include `TopLeft`, `Top`, `TopRight`, `Left`, `Center`, `Right`, `BottomLeft`, `Bottom`, `BottomRight`, or `Smart`. The `Smart` option utilizes the [`muesli/smartcrop`][] package to identify the most interesting area of the image. Default is `smart`.

bgColor
: (string) The background color used when converting transparent images to formats that do not support transparency, such as PNG to JPEG. This color also fills the empty space created when rotating an image by a non-orthogonal angle if the space is not transparent and a background color is not specified in the processing specification. The value must be an RGB [hexadecimal color][]. Default is `#ffffff`.
Expand All @@ -46,47 +41,9 @@ resampleFilter

Refer to the [source documentation][] for a complete list of available resampling filters. If you wish to improve image quality at the expense of performance, you may wish to experiment with the alternative filters.

## WebP images

{{< new-in 0.155.0 />}}

These are the default settings specific to processing WebP images:

{{< code-toggle file=hugo >}}
[imaging.webp]
hint = 'photo'
method = 4
useSharpYuv = true
{{< /code-toggle >}}

hint
: (`string`) The encoding preset used when processing WebP images, equivalent to the `-preset` flag for the [`cwebp`][] CLI. Valid options include `drawing`, `icon`, `photo`, `picture`, or `text`. Default is `photo`.

Value|Example
:--|:--
`drawing`|Hand or line drawing with high-contrast details
`icon`|Small colorful image
`photo`|Outdoor photograph with natural lighting
`picture`|Indoor photograph such as a portrait
`text`|Image that is primarily text

method
: (`int`) The effort level of the compression algorithm. Expressed as a whole number from `0` to `6`, inclusive, equivalent to the `-m` flag for the [`cwebp`][] CLI. Lower numbers prioritize processing speed, while higher numbers prioritize compression efficiency. Default is `4`.

useSharpYuv
: (`bool`) The conversion method used for RGB-to-YUV encoding, equivalent to the `-sharp_yuv` flag for the [`cwebp`][] CLI. Enabling this prioritizes image sharpness at the expense of processing speed. Default is `true`.

## Exif method

These are the default settings for the [`Exif`] method on an image `Resource` object:

{{< code-toggle file=hugo >}}
[imaging.exif]
disableDate = false
disableLatLong = false
excludeFields = ""
includeFields = ""
{{< /code-toggle >}}
The following parameters allow you to control how Hugo extracts and filters metadata when using the [`Exif`] method, helping you balance data granularity with build performance.

disableDate
: (`bool`) Whether to disable the [`Date`][] method by returning its zero value. Default is `false`.
Expand All @@ -107,13 +64,7 @@ includeFields

{{< new-in 0.155.0 />}}

These are the default settings for the [`Meta`] method on an image `Resource` object:

{{< code-toggle file=hugo >}}
[imaging.meta]
fields = []
sources = ['exif', 'iptc']
{{< /code-toggle >}}
The following parameters allow you to control how Hugo extracts and filters metadata when using the [`Meta`] method, helping you balance data granularity with build performance.

fields
: (`[]string`) A [glob slice](g) matching the fields to include when extracting metadata. If empty, a default set excluding technical metadata is used. Set&nbsp;to&nbsp;`['**']`&nbsp;to include all fields.
Expand All @@ -124,9 +75,32 @@ fields
sources
: (`[]string`) The metadata sources to include, one or more of `exif`, `iptc`, or `xmp`. Default is `['exif', 'iptc']`. The XMP metadata is excluded by default to improve performance.

## WebP images

{{< new-in 0.155.0 />}}

These specialized settings provide granular control over the WebP encoding process, allowing you to optimize compression based on the specific visual characteristics of your imagery.

hint
: (`string`) The encoding preset used when processing WebP images, equivalent to the `-preset` flag for the [`cwebp`][] CLI. Valid options include `drawing`, `icon`, `photo`, `picture`, or `text`. Default is `photo`.

Value|Example
:--|:--
`drawing`|Hand or line drawing with high-contrast details
`icon`|Small colorful image
`photo`|Outdoor photograph with natural lighting
`picture`|Indoor photograph such as a portrait
`text`|Image that is primarily text

method
: (`int`) The effort level of the compression algorithm. Expressed as a whole number from `0` to `6`, inclusive, equivalent to the `-m` flag for the [`cwebp`][] CLI. Lower numbers prioritize processing speed, while higher numbers prioritize compression efficiency. Default is `2`.

useSharpYuv
: (`bool`) The conversion method used for RGB-to-YUV encoding, equivalent to the `-sharp_yuv` flag for the [`cwebp`][] CLI. Enabling this prioritizes image sharpness at the expense of processing speed. Default is `false`.

[`cwebp`]: https://developers.google.com/speed/webp/docs/cwebp
[`Exif`]: /methods/resource/exif/
[`muesli/smartcrop`]: https://github.com/muesli/smartcrop
[`Meta`]: /methods/resource/meta/
[`smartcrop.js`]: https://github.com/jwagner/smartcrop.js
[hexadecimal color]: https://developer.mozilla.org/en-US/docs/Web/CSS/hex-color
[source documentation]: https://github.com/disintegration/imaging#image-resizing
4 changes: 2 additions & 2 deletions content/en/configuration/minify.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ This is the default configuration:

{{< code-toggle config=minify />}}

See the [tdewolff/minify] project page for details, but note the following:
See the [`tdewolff/minify`] project page for details, but note the following:

- `css.inline` is for internal use. Changing this setting has no effect.
- `html.keepConditionalComments` has been deprecated. Use `html.keepSpecialComments` instead.

[tdewolff/minify]: https://github.com/tdewolff/minify
[`tdewolff/minify`]: https://github.com/tdewolff/minify
6 changes: 3 additions & 3 deletions content/en/configuration/output-formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ isHTML
: (`bool`) Whether to classify the output format as HTML. This value determines when the LiveReload script is injected and, in conjunction with [`permalinkable`](#permalinkable), whether [alias redirects][] are generated. Default is `false`.

isPlainText
: (`bool`) Whether to parse templates for this output format with Go's [text/template][] package instead of the [html/template][] package. Default is `false`.
: (`bool`) Whether to parse templates for this output format with Go's [`text/template`][] package instead of the [`html/template`][] package. Default is `false`.

mediaType
: (`string`) The [media type](g) of the published file. This must match one of the [configured media types][].
Expand Down Expand Up @@ -202,6 +202,6 @@ Output format|Template path
[configured media types]: /configuration/media-types/
[default media types]: /configuration/media-types/
[embedded RSS template]: <{{% eturl rss %}}>
[html/template]: https://pkg.go.dev/html/template
[`html/template`]: https://pkg.go.dev/html/template
[template lookup order]: /templates/lookup-order/
[text/template]: https://pkg.go.dev/text/template
[`text/template`]: https://pkg.go.dev/text/template
4 changes: 2 additions & 2 deletions content/en/functions/go-template/try.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ params:

{{< new-in 0.141.0 />}}

The `try` statement is a non-standard extension to Go's [text/template] package. It introduces a mechanism for handling errors within templates, mimicking the `try-catch` constructs found in other programming languages.
The `try` statement is a non-standard extension to Go's [`text/template`] package. It introduces a mechanism for handling errors within templates, mimicking the `try-catch` constructs found in other programming languages.

## Methods

Expand Down Expand Up @@ -109,4 +109,4 @@ In the above, note that the [context](g) within the last conditional block is th

[`resources.GetRemote`]: /functions/resources/getremote/
[template context]: /templates/introduction/#template-context
[text/template]: https://pkg.go.dev/text/template
[`text/template`]: https://pkg.go.dev/text/template
2 changes: 1 addition & 1 deletion content/en/functions/images/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ See [image processing] for an overview of Hugo's image pipeline.
{{ $ic.Height }} → 400 (int)
```

Supported image formats include GIF, JPEG, PNG, TIFF, and WebP.
Supported image formats include AVIF, BMP, GIF, HEIC, HEIF, JPEG, PNG, TIFF, and WebP.

> [!note]
> This is a legacy function, superseded by the [`Width`] and [`Height`] methods for [global resources](g), [page resources](g), and [remote resources](g). See the [image processing] section for details.
Expand Down
62 changes: 9 additions & 53 deletions content/en/functions/reflect/IsImageResource.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: reflect.IsImageResource
description: Reports whether the given value is a Resource object representing a processable image.
description: Reports whether the given value is a Resource object representing an image as defined by its media type.
categories: []
keywords: []
params:
Expand All @@ -12,60 +12,16 @@ params:

{{< new-in 0.154.0 />}}

{{% glossary-term "processable image" %}}
The following example demonstrates how to check if a resource is categorized as an image.

With this project structure:

```text
project/
├── assets/
│ ├── a.json
│ ├── b.avif
│ └── c.jpg
└── content/
└── example/
├── index.md
├── d.json
├── e.avif
└── f.jpg
```

These are the values returned by the `reflect.IsImageResource` function:

```go-html-template {file="layouts/page.html"}
{{ with resources.Get "a.json" }}
{{ reflect.IsImageResource . }} → false
{{ end }}

{{ with resources.Get "b.avif" }}
{{ reflect.IsImageResource . }} → false
{{ end }}

{{ with resources.Get "c.jpg" }}
{{ reflect.IsImageResource . }} → true
{{ end }}
```

In the example above, the `b.avif` image is not a processable image because Hugo can neither decode nor encode the AVIF image format.

```go-html-template {file="layouts/page.html"}
{{ with .Resources.Get "d.json" }}
{{ reflect.IsImageResource . }} → false
{{ end }}

{{ with .Resources.Get "e.avif" }}
{{ reflect.IsImageResource . }} → false
```go-html-template
{{ with resources.Get "image.jpg" }}
{{ .MediaType.MainType }} → image
{{ reflect.IsImageResource . }} → true
{{ end }}

{{ with .Resources.Get "f.jpg" }}
{{ reflect.IsImageResource . }} → true
{{ end }}
```

In the example above, the `e.avif` image is not a processable image because Hugo can neither decode nor encode the AVIF image format.

```go-html-template {file="layouts/page.html"}
{{ with site.GetPage "/example" }}
{{ reflect.IsImageResource . }} → false
{{ with resources.Get "data.json" }}
{{ .MediaType.MainType }} → application
{{ reflect.IsImageResource . }} → false
{{ end }}
```
Loading