Merge commit '346b60358dd8ec2ca228e6635bff9d7914b398b7'

This commit is contained in:
Bjørn Erik Pedersen
2025-01-23 09:47:46 +01:00
384 changed files with 3305 additions and 3271 deletions

View File

@@ -24,7 +24,7 @@ The [media type] is typically one of `image`, `text`, `audio`, `video`, or `appl
```
{{% note %}}
This function operates on global resources. A global resource is a file within the assets directory, or within any directory mounted to the assets directory.
This function operates on global resources. A global resource is a file within the `assets` directory, or within any directory mounted to the `assets` directory.
For page resources, use the [`Resources.ByType`] method on a `Page` object.

View File

@@ -12,7 +12,7 @@ action:
The `resources.Concat` function returns a concatenated slice of resources, caching the result using the target path as its cache key. Each resource must have the same [media type].
Hugo publishes the resource to the target path when you call its [`Publish`], [`Permalink`], or [`RelPermalink`] methods.
Hugo publishes the resource to the target path when you call its [`Publish`], [`Permalink`], or [`RelPermalink`] method.
[media type]: https://en.wikipedia.org/wiki/Media_type
[`publish`]: /methods/resource/publish/

View File

@@ -49,8 +49,8 @@ Place this in your baseof.html template:
The example above:
1. Captures the template as a resource
2. Executes the resource as a template, passing the current page in context
3. Publishes the resource to css/main.css
1. Executes the resource as a template, passing the current page in context
1. Publishes the resource to css/main.css
The result is:

View File

@@ -36,6 +36,6 @@ The hash algorithm may be one of `md5`, `sha256` (default), `sha384`, or `sha512
After cryptographically hashing the resource content:
1. The values returned by the `.Permalink` and `.RelPermalink` methods include the hash sum
2. The resource's `.Data.Integrity` method returns a [Subresource Integrity] (SRI) value consisting of the name of the hash algorithm, one hyphen, and the base64-encoded hash sum
1. The resource's `.Data.Integrity` method returns a [Subresource Integrity] (SRI) value consisting of the name of the hash algorithm, one hyphen, and the base64-encoded hash sum
[Subresource Integrity]: https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity

View File

@@ -19,13 +19,13 @@ Hugo publishes the resource to the target path when you call its [`Publish`], [`
[`permalink`]: /methods/resource/permalink/
[`relpermalink`]: /methods/resource/relpermalink/
Let's say you need to publish a file named "site.json" in the root of your public directory, containing the build date, the Hugo version used to build the site, and the date that the content was last modified. For example:
Let's say you need to publish a file named "site.json" in the root of your `public` directory, containing the build date, the Hugo version used to build the site, and the date that the content was last modified. For example:
```json
{
"build_date": "2024-02-19T12:27:05-08:00",
"hugo_version": "0.137.1",
"last_modified": "2024-02-19T12:01:42-08:00"
"build_date": "2025-01-16T19:14:41-08:00",
"hugo_version": "0.141.0",
"last_modified": "2025-01-16T19:14:46-08:00"
}
```
@@ -48,9 +48,9 @@ Place this in your baseof.html template:
The example above:
1. Creates a map with the relevant key-value pairs using the [`dict`] function
2. Encodes the map as a JSON string using the [`jsonify`] function
3. Creates a resource from the JSON string using the `resources.FromString` function
4. Publishes the file to the root of the public directory using the resource's `.Publish` method
1. Encodes the map as a JSON string using the [`jsonify`] function
1. Creates a resource from the JSON string using the `resources.FromString` function
1. Publishes the file to the root of the `public` directory using the resource's `.Publish` method
Combine `resources.FromString` with [`resources.ExecuteAsTemplate`] if your string contains template actions. Rewriting the example above:

View File

@@ -22,7 +22,7 @@ action:
```
{{% note %}}
This function operates on global resources. A global resource is a file within the assets directory, or within any directory mounted to the assets directory.
This function operates on global resources. A global resource is a file within the `assets` directory, or within any directory mounted to the `assets` directory.
For page resources, use the [`Resources.Get`] method on a `Page` object.

View File

@@ -22,7 +22,7 @@ action:
```
{{% note %}}
This function operates on global resources. A global resource is a file within the assets directory, or within any directory mounted to the assets directory.
This function operates on global resources. A global resource is a file within the `assets` directory, or within any directory mounted to the `assets` directory.
For page resources, use the [`Resources.GetMatch`] method on a `Page` object.

View File

@@ -20,14 +20,14 @@ toc: true
```go-html-template
{{ $url := "https://example.org/images/a.jpg" }}
{{ with resources.GetRemote $url }}
{{ with try (resources.GetRemote $url) }}
{{ with .Err }}
{{ errorf "%s" . }}
{{ else }}
{{ else with .Value }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
{{ else }}
{{ errorf "Unable to get remote resource %q" $url }}
{{ end }}
{{ else }}
{{ errorf "Unable to get remote resource %q" $url }}
{{ end }}
```
@@ -67,22 +67,21 @@ You can also change the request method and set the request body:
## Remote data
When retrieving remote data, use the [`transform.Unmarshal`] function to [unmarshal] the response.
When retrieving remote data, use the [`transform.Unmarshal`] function to [unmarshal](g) the response.
[`transform.Unmarshal`]: /functions/transform/unmarshal/
[unmarshal]: /getting-started/glossary/#unmarshal
```go-html-template
{{ $data := dict }}
{{ $url := "https://example.org/books.json" }}
{{ with resources.GetRemote $url }}
{{ with try (resources.GetRemote $url) }}
{{ with .Err }}
{{ errorf "%s" . }}
{{ else }}
{{ else with .Value }}
{{ $data = . | transform.Unmarshal }}
{{ else }}
{{ errorf "Unable to get remote resource %q" $url }}
{{ end }}
{{ else }}
{{ errorf "Unable to get remote resource %q" $url }}
{{ end }}
```
@@ -98,24 +97,24 @@ In these cases, pass the resource `Content` through the `transform.Unmarshal` fu
## Error handling
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.
Use the [`try`] statement to capture HTTP request errors. If you do not handle the error yourself, Hugo will fail the build.
[`Err`]: /methods/resource/err/
[`try`]: /functions/go-template/try
{{% note %}}
Hugo does not classify an HTTP response with status code 404 as an error. In this case the function returns nil.
Hugo does not classify an HTTP response with status code 404 as an error. In this case `resources.GetRemote` returns nil.
{{% /note %}}
```go-html-template
{{ $url := "https://broken-example.org/images/a.jpg" }}
{{ with resources.GetRemote $url }}
{{ with try (resources.GetRemote $url) }}
{{ with .Err }}
{{ errorf "%s" . }}
{{ else }}
{{ else with .Value }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
{{ else }}
{{ errorf "Unable to get remote resource %q" $url }}
{{ end }}
{{ else }}
{{ errorf "Unable to get remote resource %q" $url }}
{{ end }}
```
@@ -123,14 +122,14 @@ To log an error as a warning instead of an error:
```go-html-template
{{ $url := "https://broken-example.org/images/a.jpg" }}
{{ with resources.GetRemote $url }}
{{ with try (resources.GetRemote $url) }}
{{ with .Err }}
{{ warnf "%s" . }}
{{ else }}
{{ else with .Value }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
{{ else }}
{{ warnf "Unable to get remote resource %q" $url }}
{{ end }}
{{ else }}
{{ errorf "Unable to get remote resource %q" $url }}
{{ end }}
```
@@ -142,10 +141,10 @@ The [`Data`] method on a resource returned by the `resources.GetRemote` function
```go-html-template
{{ $url := "https://example.org/images/a.jpg" }}
{{ with resources.GetRemote $url }}
{{ with try (resources.GetRemote $url) }}
{{ with .Err }}
{{ errorf "%s" . }}
{{ else }}
{{ else with .Value }}
{{ with .Data }}
{{ .ContentLength }} → 42764
{{ .ContentType }} → image/jpeg
@@ -153,9 +152,9 @@ The [`Data`] method on a resource returned by the `resources.GetRemote` function
{{ .StatusCode }} → 200
{{ .TransferEncoding }} → []
{{ end }}
{{ else }}
{{ errorf "Unable to get remote resource %q" $url }}
{{ end }}
{{ else }}
{{ errorf "Unable to get remote resource %q" $url }}
{{ end }}
```

View File

@@ -22,7 +22,7 @@ action:
```
{{% note %}}
This function operates on global resources. A global resource is a file within the assets directory, or within any directory mounted to the assets directory.
This function operates on global resources. A global resource is a file within the `assets` directory, or within any directory mounted to the `assets` directory.
For page resources, use the [`Resources.Match`] method on a `Page` object.

View File

@@ -79,7 +79,7 @@ module.exports = {
{{% /note %}}
Step 4
: Enable creation of the `hugo_stats.json` file when building the site. If you are only using this for the production build, consider placing it below [config/production].
: Enable creation of the `hugo_stats.json` file when building the site. If you are only using this for the production build, consider placing it below [`config/production`].
{{< code-toggle file=hugo >}}
[build.buildStats]
@@ -122,7 +122,7 @@ HUGO_ENVIRONMENT
Default is `production` for `hugo` and `development` for `hugo server`.
HUGO_PUBLISHDIR
: The absolute path to the publish directory (the `public` directory). Note that the value will always point to a directory on disk even when running `hugo server` in memory mode. If you write to this folder from PostCSS when running the server, you could run the server with one of these flags:
: The absolute path to the publish directory (the `public` directory). Note that the value will always point to a directory on disk even when running `hugo server` in memory mode. If you write to this directory from PostCSS when running the server, you could run the server with one of these flags:
```sh
hugo server --renderToDisk
@@ -153,6 +153,6 @@ You cannot manipulate the values returned from the resources methods. For exa
[node.js]: https://nodejs.org/en/download
[supported file name]: https://github.com/postcss/postcss-load-config#usage
[config/production]: /getting-started/configuration/#configuration-directory
[`config/production`]: /getting-started/configuration/#configuration-directory
[configure build]: /getting-started/configuration/#configure-build
[purgecss]: https://github.com/FullHuman/purgecss#readme

View File

@@ -126,7 +126,7 @@ Run `hugo env` to list the active transpilers.
For [CI/CD] deployments (e.g., GitHub Pages, GitLab Pages, Netlify, etc.) you must edit the workflow to install Dart Sass before Hugo builds the site[^2]. Some providers allow you to use one of the package managers above, or you can download and extract one of the prebuilt binaries.
[^2]: You do not have to do this if (a) you have not modified the assets cache location, and (b) you have not set `useResourceCacheWhen` to `never` in your [site configuration], and (c) you add and commit your resources directory to your repository.
[^2]: You do not have to do this if (a) you have not modified the assets cache location, and (b) you have not set `useResourceCacheWhen` to `never` in your [site configuration], and (c) you add and commit your `resources` directory to your repository.
#### GitHub Pages
@@ -145,8 +145,8 @@ To install Dart Sass for your builds on GitLab Pages, the `.gitlab-ci.yml` file
```yaml
variables:
HUGO_VERSION: 0.137.1
DART_SASS_VERSION: 1.80.6
HUGO_VERSION: 0.141.0
DART_SASS_VERSION: 1.83.4
GIT_DEPTH: 0
GIT_STRATEGY: clone
GIT_SUBMODULE_STRATEGY: recursive
@@ -179,8 +179,9 @@ To install Dart Sass for your builds on Netlify, the `netlify.toml` file should
```toml
[build.environment]
HUGO_VERSION = "0.137.1"
DART_SASS_VERSION = "1.80.6"
HUGO_VERSION = "0.141.0"
DART_SASS_VERSION = "1.83.4"
NODE_VERSION = "22"
TZ = "America/Los_Angeles"
[build]