aboutsummaryrefslogtreecommitdiffhomepage
path: root/resources
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2024-02-25 10:24:46 +0100
committerBjørn Erik Pedersen <[email protected]>2024-02-25 14:57:29 +0100
commitd310595a2ba672fa30dc9a9a2679542cfc919a35 (patch)
tree14ae73ab6bce20d236759d73e6181f006e4de8f4 /resources
parent049dd1d7e0e106d861c60e5417c907bc3a686dcb (diff)
downloadhugo-d310595a2ba672fa30dc9a9a2679542cfc919a35.tar.gz
hugo-d310595a2ba672fa30dc9a9a2679542cfc919a35.zip
resource: Revert the normalization of Resource.Name
Which means that .Name now returns the same as it did in 0.122.0. Closes #12142
Diffstat (limited to 'resources')
-rw-r--r--resources/image.go8
-rw-r--r--resources/resource.go16
-rw-r--r--resources/resource/resources.go23
-rw-r--r--resources/resource/resourcetypes.go10
-rw-r--r--resources/resource_metadata.go8
-rw-r--r--resources/resource_spec.go4
-rw-r--r--resources/testhelpers_test.go4
-rw-r--r--resources/transform.go6
8 files changed, 36 insertions, 43 deletions
diff --git a/resources/image.go b/resources/image.go
index 2e351bd28..78a57bb53 100644
--- a/resources/image.go
+++ b/resources/image.go
@@ -48,10 +48,10 @@ import (
)
var (
- _ images.ImageResource = (*imageResource)(nil)
- _ resource.Source = (*imageResource)(nil)
- _ resource.Cloner = (*imageResource)(nil)
- _ resource.NameOriginalProvider = (*imageResource)(nil)
+ _ images.ImageResource = (*imageResource)(nil)
+ _ resource.Source = (*imageResource)(nil)
+ _ resource.Cloner = (*imageResource)(nil)
+ _ resource.NameNormalizedProvider = (*imageResource)(nil)
)
// imageResource represents an image resource.
diff --git a/resources/resource.go b/resources/resource.go
index 73a0ad56e..867b262fb 100644
--- a/resources/resource.go
+++ b/resources/resource.go
@@ -59,8 +59,8 @@ type ResourceSourceDescriptor struct {
// The canonical source path.
Path *paths.Path
- // The name of the resource.
- Name string
+ // The normalized name of the resource.
+ NameNormalized string
// The name of the resource as it was read from the source.
NameOriginal string
@@ -135,12 +135,12 @@ func (fd *ResourceSourceDescriptor) init(r *Spec) error {
fd.TargetBasePaths[i] = dir
}
- if fd.Name == "" {
- fd.Name = fd.TargetPath
+ if fd.NameNormalized == "" {
+ fd.NameNormalized = fd.TargetPath
}
if fd.NameOriginal == "" {
- fd.NameOriginal = fd.Name
+ fd.NameOriginal = fd.NameNormalized
}
mediaType := fd.MediaType
@@ -228,7 +228,7 @@ type baseResourceResource interface {
type baseResourceInternal interface {
resource.Source
- resource.NameOriginalProvider
+ resource.NameNormalizedProvider
fileInfo
mediaTypeAssigner
@@ -457,8 +457,8 @@ func (l *genericResource) Name() string {
return l.name
}
-func (l *genericResource) NameOriginal() string {
- return l.sd.NameOriginal
+func (l *genericResource) NameNormalized() string {
+ return l.sd.NameNormalized
}
func (l *genericResource) Params() maps.Params {
diff --git a/resources/resource/resources.go b/resources/resource/resources.go
index fb5f9a5ee..aa01d4ce2 100644
--- a/resources/resource/resources.go
+++ b/resources/resource/resources.go
@@ -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)
}
}
diff --git a/resources/resource/resourcetypes.go b/resources/resource/resourcetypes.go
index 6b437023a..0766fe232 100644
--- a/resources/resource/resourcetypes.go
+++ b/resources/resource/resourcetypes.go
@@ -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 {
diff --git a/resources/resource_metadata.go b/resources/resource_metadata.go
index 869fc11bf..659ce81f8 100644
--- a/resources/resource_metadata.go
+++ b/resources/resource_metadata.go
@@ -28,10 +28,10 @@ import (
)
var (
- _ mediaTypeAssigner = (*genericResource)(nil)
- _ mediaTypeAssigner = (*imageResource)(nil)
- _ resource.Staler = (*genericResource)(nil)
- _ resource.NameOriginalProvider = (*genericResource)(nil)
+ _ mediaTypeAssigner = (*genericResource)(nil)
+ _ mediaTypeAssigner = (*imageResource)(nil)
+ _ resource.Staler = (*genericResource)(nil)
+ _ resource.NameNormalizedProvider = (*genericResource)(nil)
)
// metaAssigner allows updating metadata in resources that supports it.
diff --git a/resources/resource_spec.go b/resources/resource_spec.go
index 0bb507083..bd04846ed 100644
--- a/resources/resource_spec.go
+++ b/resources/resource_spec.go
@@ -170,8 +170,8 @@ func (r *Spec) NewResource(rd ResourceSourceDescriptor) (resource.Resource, erro
spec: r,
sd: rd,
params: make(map[string]any),
- name: rd.Name,
- title: rd.Name,
+ name: rd.NameOriginal,
+ title: rd.NameOriginal,
}
if rd.MediaType.MainType == "image" {
diff --git a/resources/testhelpers_test.go b/resources/testhelpers_test.go
index 028524619..60cfae0c5 100644
--- a/resources/testhelpers_test.go
+++ b/resources/testhelpers_test.go
@@ -117,8 +117,8 @@ func fetchResourceForSpec(spec *resources.Spec, c *qt.C, name string, targetPath
targetPath := name
base := "/a/"
r, err := spec.NewResource(resources.ResourceSourceDescriptor{
- LazyPublish: true,
- Name: name, TargetPath: targetPath, BasePathRelPermalink: base, BasePathTargetPath: base, OpenReadSeekCloser: open,
+ LazyPublish: true,
+ NameNormalized: name, TargetPath: targetPath, BasePathRelPermalink: base, BasePathTargetPath: base, OpenReadSeekCloser: open,
GroupIdentity: identity.Anonymous,
})
c.Assert(err, qt.IsNil)
diff --git a/resources/transform.go b/resources/transform.go
index b9cbab824..39a8aaccc 100644
--- a/resources/transform.go
+++ b/resources/transform.go
@@ -55,7 +55,7 @@ var (
_ resource.WithResourceMetaProvider = (*resourceAdapter)(nil)
_ identity.DependencyManagerProvider = (*resourceAdapter)(nil)
_ identity.IdentityGroupProvider = (*resourceAdapter)(nil)
- _ resource.NameOriginalProvider = (*resourceAdapter)(nil)
+ _ resource.NameNormalizedProvider = (*resourceAdapter)(nil)
)
// These are transformations that need special support in Hugo that may not
@@ -282,9 +282,9 @@ func (r *resourceAdapter) Name() string {
return r.metaProvider.Name()
}
-func (r *resourceAdapter) NameOriginal() string {
+func (r *resourceAdapter) NameNormalized() string {
r.init(false, false)
- return r.target.(resource.NameOriginalProvider).NameOriginal()
+ return r.target.(resource.NameNormalizedProvider).NameNormalized()
}
func (r *resourceAdapter) Params() maps.Params {