Skip to content

Commit

Permalink
Update RESOURCE.Name examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jmooring authored Feb 21, 2024
1 parent 8cf5046 commit 6a4f38f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
1 change: 0 additions & 1 deletion content/en/content-management/diagrams.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ menu:
weight: 260
toc: true
---
{{< new-in 0.93.0 >}}

## GoAT diagrams (ASCII)

Expand Down
2 changes: 1 addition & 1 deletion content/en/getting-started/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion content/en/methods/page/Path.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
45 changes: 23 additions & 22 deletions content/en/methods/resource/Name.md
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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/
Expand All @@ -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

0 comments on commit 6a4f38f

Please sign in to comment.