Skip to content

Commit

Permalink
Fix path vs name
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed May 13, 2024
1 parent 1d7fd9f commit d413cb6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions hugolib/content_map_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,9 @@ func (sa *sitePagesAssembler) assembleResources() error {
}

if rs.rc != nil && rs.rc.Content.IsResourceValue() {
if rs.rc.Name == "" {
rs.rc.Name = relPathOriginal
}
r, err := ps.m.s.ResourceSpec.NewResourceWrapperFromResourceConfig(rs.rc)
if err != nil {
return false, err
Expand Down
8 changes: 6 additions & 2 deletions hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ Pfile Content
{{ $resourceContent := dict "value" $dataResource }}
{{ $.AddResource (dict "path" "p1/data1.yaml" "content" $resourceContent) }}
{{ $.AddResource (dict "path" "p1/mytext.txt" "content" (dict "value" "some text") "name" "textresource" "title" "My Text Resource" "params" (dict "param1" "param1v") )}}
{{ $.AddResource (dict "path" "p1/sub/mytex2.txt" "content" (dict "value" "some text") "title" "My Text Sub Resource" ) }}
{{ $.AddResource (dict "path" "p1/sub/data1.yaml" "content" $resourceContent "title" "Sub data") }}
{{ $resourceParams := dict "data2ParaM1" "data2Param1v" }}
{{ $.AddResource (dict "path" "p1/data2.yaml" "name" "data2.yaml" "title" "My data 2" "params" $resourceParams "content" $resourceContent) }}
{{ $.AddResource (dict "path" "p1/featuredimage.png" "name" "featured.png" "title" "My Featured Image" "params" $resourceParams "content" (dict "value" $pixel ))}}
Expand All @@ -96,10 +98,12 @@ func TestPagesFromGoTmplBasic(t *testing.T) {
"Path: /docs/p1|",
"<strong>Hello World</strong>",
"Params: param1v|",
"Len Resources: 4",
"RelPermalink: /mydata.yaml|Name: /mydata.yaml|Title: /mydata.yaml|Params: map[]|",
"Len Resources: 6",
"RelPermalink: /mydata.yaml|Name: data1.yaml|Title: data1.yaml|Params: map[]|",
"RelPermalink: /mydata.yaml|Name: data2.yaml|Title: My data 2|Params: map[data2param1:data2Param1v]|",
"RelPermalink: /a/pixel.png|Name: featured.png|Title: My Featured Image|Params: map[data2param1:data2Param1v]|",
"RelPermalink: /docs/p1/sub/mytex2.txt|Name: sub/mytex2.txt|",
"RelPermalink: /mydata.yaml|Name: sub/data1.yaml|Title: Sub data|Params: map[]|",
"Featured Image: /a/pixel.png|featured.png|",
"Resized Featured Image: /a/pixel_hu8aa3346827e49d756ff4e630147c42b5_70_10x10_resize_box_3.png|10|",
// Resource from string
Expand Down
4 changes: 4 additions & 0 deletions resources/resource_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ func cloneWithMetadataFromResourceConfigIfNeeded(rc *pagemeta.ResourceConfig, r
return r
}

if rc.Title == "" {
rc.Title = rc.Name
}

wrapped := &metaResource{
name: rc.Name,
title: rc.Title,
Expand Down

0 comments on commit d413cb6

Please sign in to comment.