resource: Revert the normalization of Resource.Name

Which means that .Name now returns the same as it did in 0.122.0.

Closes #12142
This commit is contained in:
Bjørn Erik Pedersen
2024-02-25 10:24:46 +01:00
parent 049dd1d7e0
commit d310595a2b
10 changed files with 42 additions and 49 deletions

View File

@@ -18,7 +18,6 @@ import (
"fmt"
"strings"
"github.com/gohugoio/hugo/common/paths"
"github.com/gohugoio/hugo/hugofs/glob"
"github.com/spf13/cast"
)
@@ -73,10 +72,10 @@ func (r Resources) Get(name any) Resource {
}
}
// Finally, check the original name.
// Finally, check the normalized name.
for _, resource := range r {
if nop, ok := resource.(NameOriginalProvider); ok {
if strings.EqualFold(namestr, nop.NameOriginal()) {
if nop, ok := resource.(NameNormalizedProvider); ok {
if strings.EqualFold(namestr, nop.NameNormalized()) {
return resource
}
}
@@ -93,23 +92,21 @@ func (r Resources) GetMatch(pattern any) Resource {
panic(err)
}
patternstr = paths.NormalizePathStringBasic(patternstr)
g, err := glob.GetGlob(patternstr)
if err != nil {
panic(err)
}
for _, resource := range r {
if g.Match(paths.NormalizePathStringBasic(resource.Name())) {
if g.Match(resource.Name()) {
return resource
}
}
// Finally, check the original name.
for _, resource := range r {
if nop, ok := resource.(NameOriginalProvider); ok {
if g.Match(paths.NormalizePathStringBasic(nop.NameOriginal())) {
if nop, ok := resource.(NameNormalizedProvider); ok {
if g.Match(nop.NameNormalized()) {
return resource
}
}
@@ -140,15 +137,15 @@ func (r Resources) Match(pattern any) Resources {
var matches Resources
for _, resource := range r {
if g.Match(strings.ToLower(resource.Name())) {
if g.Match(resource.Name()) {
matches = append(matches, resource)
}
}
if len(matches) == 0 {
// Fall back to the original name.
// Fall back to the normalized name.
for _, resource := range r {
if nop, ok := resource.(NameOriginalProvider); ok {
if g.Match(strings.ToLower(nop.NameOriginal())) {
if nop, ok := resource.(NameNormalizedProvider); ok {
if g.Match(nop.NameNormalized()) {
matches = append(matches, resource)
}
}

View File

@@ -127,20 +127,16 @@ type ResourceNameTitleProvider interface {
// So, for the image "/some/path/sunset.jpg" this will be "sunset.jpg".
// The value returned by this method will be used in the GetByPrefix and ByPrefix methods
// on Resources.
// Note that for bundled content resources with language code in the filename, this will
// be the name without the language code.
Name() string
// Title returns the title if set in front matter. For content pages, this will be the expected value.
Title() string
}
type NameOriginalProvider interface {
// NameOriginal is the original name of this resource.
// Note that for bundled content resources with language code in the filename, this will
// be the name with the language code.
type NameNormalizedProvider interface {
// NameNormalized is the normalized name of this resource.
// For internal use (for now).
NameOriginal() string
NameNormalized() string
}
type ResourceParamsProvider interface {