Update RESOURCE.Name examples

This commit is contained in:
Joe Mooring 2024-02-21 06:41:02 -08:00 committed by GitHub
parent 8cf5046f5d
commit 6a4f38fc39
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 25 additions and 25 deletions

View File

@ -10,7 +10,6 @@ menu:
weight: 260
toc: true
---
{{< new-in 0.93.0 >}}
## GoAT diagrams (ASCII)

View File

@ -206,7 +206,7 @@ Adaptation of a site to meet language and regional requirements. This includes t
{{< new-in 0.123.0 >}}
A page or page resource identifier derived from the file path, excluding its extension and language identifier. This value is neither a file path nor a URL. <!-- You may also set this value using the `path` front matter field. --> See [details](/methods/page/path).
A page or page resource identifier derived from the file path, excluding its extension and language identifier. This value is neither a file path nor a URL. Starting with a file path relative to the content directory, Hugo determines the logical path by stripping the file extension and language identifier, converting to lower case, then replacing spaces with hyphens. <!-- You may also set this value using the `path` front matter field. --> See [examples](/methods/page/path/#examples).
###### map

View File

@ -38,7 +38,7 @@ To determine the logical path for pages backed by a file, Hugo starts with the f
1. Strips the file extension
2. Strips the language identifier
3. Converts the result to lower case
4. Replaces all spaces with hyphens
4. Replaces spaces with hyphens
The value returned by the `Path` method on a `Page` object is independent of content format, language, and URL modifiers such as the `slug` and `url` front matter fields.

View File

@ -1,6 +1,6 @@
---
title: Name
description: Returns the name of the given resource as optionally defined in front matter, falling back to a relative path or hashed file name depending on resource type.
description: Returns the name of the given resource as optionally defined in front matter, falling back to its path.
categories: []
keywords: []
action:
@ -25,13 +25,31 @@ assets/
```go-html-template
{{ with resources.Get "images/a.jpg" }}
{{ .Name }} → images/a.jpg
{{ .Name }} → /images/a.jpg
{{ end }}
```
## Page resource
With a [page resource], the `Name` method returns the path to the resource, relative to the page bundle.
With a [page resource], if you create an element in the `resources` array in front matter, the `Name` method returns the value of the `name` parameter:
{{< code-toggle file=content/posts/post-1.md fm=true >}}
title = 'Post 1'
[[resources]]
src = 'images/a.jpg'
name = 'cat'
title = 'Felix the cat'
[resources.params]
temperament = 'malicious'
{{< /code-toggle >}}
```go-html-template
{{ with .Resources.Get "cat" }}
{{ .Name }} → cat
{{ end }}
```
If you do not create an element in the `resources` array in front matter, the `Name` method returns the [logical path] to the resource, relative to the page bundle.
```text
content/
@ -49,34 +67,17 @@ content/
{{ .Name }} → images/a.jpg
{{ end }}
```
If you create an element in the `resources` array in front matter, the `Name` method returns the value of the `name` parameter:
{{< code-toggle file=content/posts/post-1.md fm=true >}}
title = 'Post 1'
[[resources]]
src = 'images/a.jpg'
name = 'cat'
title = 'Felix the cat'
[resources.params]
temperament = 'malicious'
{{< /code-toggle >}}
```go-html-template
{{ with .Resources.Get "cat" }}
{{ .Name }} → cat
{{ end }}
```
## Remote resource
With a [remote resource], the `Name` method returns a hashed file name.
```go-html-template
{{ with resources.GetRemote "https://example.org/images/a.jpg" }}
{{ .Name }} → a_18432433023265451104.jpg
{{ .Name }} → /a_18432433023265451104.jpg
{{ end }}
```
[global resource]: /getting-started/glossary/#global-resource
[logical path]: /getting-started/glossary/#logical-path
[page resource]: /getting-started/glossary/#page-resource
[remote resource]: /getting-started/glossary/#remote-resource