mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
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:
parent
049dd1d7e0
commit
d310595a2b
10 changed files with 42 additions and 49 deletions
|
@ -542,7 +542,7 @@ func (m *pageMap) getOrCreateResourcesForPage(ps *pageState) resource.Resources
|
||||||
for _, r := range res2 {
|
for _, r := range res2 {
|
||||||
var found bool
|
var found bool
|
||||||
for _, r2 := range res {
|
for _, r2 := range res {
|
||||||
if r2.Name() == r.Name() {
|
if r2.(resource.NameNormalizedProvider).NameNormalized() == r.(resource.NameNormalizedProvider).NameNormalized() {
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -1633,7 +1633,7 @@ func (sa *sitePagesAssembler) assembleResources() error {
|
||||||
TargetBasePaths: targetBasePaths,
|
TargetBasePaths: targetBasePaths,
|
||||||
BasePathRelPermalink: targetPaths.SubResourceBaseLink,
|
BasePathRelPermalink: targetPaths.SubResourceBaseLink,
|
||||||
BasePathTargetPath: baseTarget,
|
BasePathTargetPath: baseTarget,
|
||||||
Name: relPath,
|
NameNormalized: relPath,
|
||||||
NameOriginal: relPathOriginal,
|
NameOriginal: relPathOriginal,
|
||||||
LazyPublish: !ps.m.pageConfig.Build.PublishResources,
|
LazyPublish: !ps.m.pageConfig.Build.PublishResources,
|
||||||
}
|
}
|
||||||
|
|
|
@ -871,7 +871,7 @@ RegularPages: {{ range .RegularPages }}{{ .RelPermalink }}|File LogicalName: {{
|
||||||
b := Test(t, files)
|
b := Test(t, files)
|
||||||
|
|
||||||
// Note that the sort order gives us the most specific data file for the en language (the data.en.json).
|
// Note that the sort order gives us the most specific data file for the en language (the data.en.json).
|
||||||
b.AssertFileContent("public/mysection/mybundle/index.html", `Single:|/mysection/mybundle|File LogicalName: index.md||/mysection/mybundle/|page|Resources: data.json: Data JSON.|foo/p1.html: |p1.html: |p1.md: |data.txt: Data en txt.|$`)
|
b.AssertFileContent("public/mysection/mybundle/index.html", `Single:|/mysection/mybundle|File LogicalName: index.md||/mysection/mybundle/|page|Resources: data.en.txt: Data en txt.|data.json: Data JSON.|foo/p1.html: |p1.html: |p1.md: |$`)
|
||||||
b.AssertFileContent("public/mysection/index.html",
|
b.AssertFileContent("public/mysection/index.html",
|
||||||
"List: |/mysection|File LogicalName: _index.md|/mysection/|section|Resources: sectiondata.json: Secion data JSON.|sectiondata.txt: Section data TXT.|$",
|
"List: |/mysection|File LogicalName: _index.md|/mysection/|section|Resources: sectiondata.json: Secion data JSON.|sectiondata.txt: Section data TXT.|$",
|
||||||
"RegularPages: /mysection/foo/p2/|File LogicalName: p2.md|/mysection/mybundle/|File LogicalName: index.md|/mysection/p2/|File LogicalName: p2.md|$")
|
"RegularPages: /mysection/foo/p2/|File LogicalName: p2.md|/mysection/mybundle/|File LogicalName: index.md|/mysection/p2/|File LogicalName: p2.md|$")
|
||||||
|
@ -886,12 +886,12 @@ baseURL = "https://example.com"
|
||||||
F1.
|
F1.
|
||||||
-- layouts/_default/single.html --
|
-- layouts/_default/single.html --
|
||||||
GetMatch: {{ with .Resources.GetMatch "f1.en.*" }}{{ .Name }}: {{ .Content }}|{{ end }}
|
GetMatch: {{ with .Resources.GetMatch "f1.en.*" }}{{ .Name }}: {{ .Content }}|{{ end }}
|
||||||
Match: {{ range .Resources.Match "f1.en.*" }}{{ .Name }}: {{ .Content }}|{{ end }}
|
Match: {{ range .Resources.Match "f1.En.*" }}{{ .Name }}: {{ .Content }}|{{ end }}
|
||||||
`
|
`
|
||||||
|
|
||||||
b := Test(t, files)
|
b := Test(t, files)
|
||||||
|
|
||||||
b.AssertFileContent("public/mybundle/index.html", "GetMatch: f1.txt: F1.|", "Match: f1.txt: F1.|")
|
b.AssertFileContent("public/mybundle/index.html", "GetMatch: f1.en.txt: F1.|", "Match: f1.en.txt: F1.|")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBundleResourcesWhenLanguageVariantIsDraft(t *testing.T) {
|
func TestBundleResourcesWhenLanguageVariantIsDraft(t *testing.T) {
|
||||||
|
@ -917,5 +917,5 @@ GetMatch: {{ with .Resources.GetMatch "f1.*" }}{{ .Name }}: {{ .Content }}|{{ en
|
||||||
|
|
||||||
b := Test(t, files)
|
b := Test(t, files)
|
||||||
|
|
||||||
b.AssertFileContent("public/mybundle/index.html", "GetMatch: f1.txt: F1.|")
|
b.AssertFileContent("public/mybundle/index.html", "GetMatch: f1.en.txt: F1.|")
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,10 +48,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_ images.ImageResource = (*imageResource)(nil)
|
_ images.ImageResource = (*imageResource)(nil)
|
||||||
_ resource.Source = (*imageResource)(nil)
|
_ resource.Source = (*imageResource)(nil)
|
||||||
_ resource.Cloner = (*imageResource)(nil)
|
_ resource.Cloner = (*imageResource)(nil)
|
||||||
_ resource.NameOriginalProvider = (*imageResource)(nil)
|
_ resource.NameNormalizedProvider = (*imageResource)(nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
// imageResource represents an image resource.
|
// imageResource represents an image resource.
|
||||||
|
|
|
@ -59,8 +59,8 @@ type ResourceSourceDescriptor struct {
|
||||||
// The canonical source path.
|
// The canonical source path.
|
||||||
Path *paths.Path
|
Path *paths.Path
|
||||||
|
|
||||||
// The name of the resource.
|
// The normalized name of the resource.
|
||||||
Name string
|
NameNormalized string
|
||||||
|
|
||||||
// The name of the resource as it was read from the source.
|
// The name of the resource as it was read from the source.
|
||||||
NameOriginal string
|
NameOriginal string
|
||||||
|
@ -135,12 +135,12 @@ func (fd *ResourceSourceDescriptor) init(r *Spec) error {
|
||||||
fd.TargetBasePaths[i] = dir
|
fd.TargetBasePaths[i] = dir
|
||||||
}
|
}
|
||||||
|
|
||||||
if fd.Name == "" {
|
if fd.NameNormalized == "" {
|
||||||
fd.Name = fd.TargetPath
|
fd.NameNormalized = fd.TargetPath
|
||||||
}
|
}
|
||||||
|
|
||||||
if fd.NameOriginal == "" {
|
if fd.NameOriginal == "" {
|
||||||
fd.NameOriginal = fd.Name
|
fd.NameOriginal = fd.NameNormalized
|
||||||
}
|
}
|
||||||
|
|
||||||
mediaType := fd.MediaType
|
mediaType := fd.MediaType
|
||||||
|
@ -228,7 +228,7 @@ type baseResourceResource interface {
|
||||||
|
|
||||||
type baseResourceInternal interface {
|
type baseResourceInternal interface {
|
||||||
resource.Source
|
resource.Source
|
||||||
resource.NameOriginalProvider
|
resource.NameNormalizedProvider
|
||||||
|
|
||||||
fileInfo
|
fileInfo
|
||||||
mediaTypeAssigner
|
mediaTypeAssigner
|
||||||
|
@ -457,8 +457,8 @@ func (l *genericResource) Name() string {
|
||||||
return l.name
|
return l.name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *genericResource) NameOriginal() string {
|
func (l *genericResource) NameNormalized() string {
|
||||||
return l.sd.NameOriginal
|
return l.sd.NameNormalized
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *genericResource) Params() maps.Params {
|
func (l *genericResource) Params() maps.Params {
|
||||||
|
|
|
@ -18,7 +18,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/common/paths"
|
|
||||||
"github.com/gohugoio/hugo/hugofs/glob"
|
"github.com/gohugoio/hugo/hugofs/glob"
|
||||||
"github.com/spf13/cast"
|
"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 {
|
for _, resource := range r {
|
||||||
if nop, ok := resource.(NameOriginalProvider); ok {
|
if nop, ok := resource.(NameNormalizedProvider); ok {
|
||||||
if strings.EqualFold(namestr, nop.NameOriginal()) {
|
if strings.EqualFold(namestr, nop.NameNormalized()) {
|
||||||
return resource
|
return resource
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,23 +92,21 @@ func (r Resources) GetMatch(pattern any) Resource {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
patternstr = paths.NormalizePathStringBasic(patternstr)
|
|
||||||
|
|
||||||
g, err := glob.GetGlob(patternstr)
|
g, err := glob.GetGlob(patternstr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, resource := range r {
|
for _, resource := range r {
|
||||||
if g.Match(paths.NormalizePathStringBasic(resource.Name())) {
|
if g.Match(resource.Name()) {
|
||||||
return resource
|
return resource
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, check the original name.
|
// Finally, check the original name.
|
||||||
for _, resource := range r {
|
for _, resource := range r {
|
||||||
if nop, ok := resource.(NameOriginalProvider); ok {
|
if nop, ok := resource.(NameNormalizedProvider); ok {
|
||||||
if g.Match(paths.NormalizePathStringBasic(nop.NameOriginal())) {
|
if g.Match(nop.NameNormalized()) {
|
||||||
return resource
|
return resource
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,15 +137,15 @@ func (r Resources) Match(pattern any) Resources {
|
||||||
|
|
||||||
var matches Resources
|
var matches Resources
|
||||||
for _, resource := range r {
|
for _, resource := range r {
|
||||||
if g.Match(strings.ToLower(resource.Name())) {
|
if g.Match(resource.Name()) {
|
||||||
matches = append(matches, resource)
|
matches = append(matches, resource)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(matches) == 0 {
|
if len(matches) == 0 {
|
||||||
// Fall back to the original name.
|
// Fall back to the normalized name.
|
||||||
for _, resource := range r {
|
for _, resource := range r {
|
||||||
if nop, ok := resource.(NameOriginalProvider); ok {
|
if nop, ok := resource.(NameNormalizedProvider); ok {
|
||||||
if g.Match(strings.ToLower(nop.NameOriginal())) {
|
if g.Match(nop.NameNormalized()) {
|
||||||
matches = append(matches, resource)
|
matches = append(matches, resource)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,20 +127,16 @@ type ResourceNameTitleProvider interface {
|
||||||
// So, for the image "/some/path/sunset.jpg" this will be "sunset.jpg".
|
// 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
|
// The value returned by this method will be used in the GetByPrefix and ByPrefix methods
|
||||||
// on Resources.
|
// 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
|
Name() string
|
||||||
|
|
||||||
// Title returns the title if set in front matter. For content pages, this will be the expected value.
|
// Title returns the title if set in front matter. For content pages, this will be the expected value.
|
||||||
Title() string
|
Title() string
|
||||||
}
|
}
|
||||||
|
|
||||||
type NameOriginalProvider interface {
|
type NameNormalizedProvider interface {
|
||||||
// NameOriginal is the original name of this resource.
|
// NameNormalized is the normalized 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.
|
|
||||||
// For internal use (for now).
|
// For internal use (for now).
|
||||||
NameOriginal() string
|
NameNormalized() string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResourceParamsProvider interface {
|
type ResourceParamsProvider interface {
|
||||||
|
|
|
@ -28,10 +28,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_ mediaTypeAssigner = (*genericResource)(nil)
|
_ mediaTypeAssigner = (*genericResource)(nil)
|
||||||
_ mediaTypeAssigner = (*imageResource)(nil)
|
_ mediaTypeAssigner = (*imageResource)(nil)
|
||||||
_ resource.Staler = (*genericResource)(nil)
|
_ resource.Staler = (*genericResource)(nil)
|
||||||
_ resource.NameOriginalProvider = (*genericResource)(nil)
|
_ resource.NameNormalizedProvider = (*genericResource)(nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
// metaAssigner allows updating metadata in resources that supports it.
|
// metaAssigner allows updating metadata in resources that supports it.
|
||||||
|
|
|
@ -170,8 +170,8 @@ func (r *Spec) NewResource(rd ResourceSourceDescriptor) (resource.Resource, erro
|
||||||
spec: r,
|
spec: r,
|
||||||
sd: rd,
|
sd: rd,
|
||||||
params: make(map[string]any),
|
params: make(map[string]any),
|
||||||
name: rd.Name,
|
name: rd.NameOriginal,
|
||||||
title: rd.Name,
|
title: rd.NameOriginal,
|
||||||
}
|
}
|
||||||
|
|
||||||
if rd.MediaType.MainType == "image" {
|
if rd.MediaType.MainType == "image" {
|
||||||
|
|
|
@ -117,8 +117,8 @@ func fetchResourceForSpec(spec *resources.Spec, c *qt.C, name string, targetPath
|
||||||
targetPath := name
|
targetPath := name
|
||||||
base := "/a/"
|
base := "/a/"
|
||||||
r, err := spec.NewResource(resources.ResourceSourceDescriptor{
|
r, err := spec.NewResource(resources.ResourceSourceDescriptor{
|
||||||
LazyPublish: true,
|
LazyPublish: true,
|
||||||
Name: name, TargetPath: targetPath, BasePathRelPermalink: base, BasePathTargetPath: base, OpenReadSeekCloser: open,
|
NameNormalized: name, TargetPath: targetPath, BasePathRelPermalink: base, BasePathTargetPath: base, OpenReadSeekCloser: open,
|
||||||
GroupIdentity: identity.Anonymous,
|
GroupIdentity: identity.Anonymous,
|
||||||
})
|
})
|
||||||
c.Assert(err, qt.IsNil)
|
c.Assert(err, qt.IsNil)
|
||||||
|
|
|
@ -55,7 +55,7 @@ var (
|
||||||
_ resource.WithResourceMetaProvider = (*resourceAdapter)(nil)
|
_ resource.WithResourceMetaProvider = (*resourceAdapter)(nil)
|
||||||
_ identity.DependencyManagerProvider = (*resourceAdapter)(nil)
|
_ identity.DependencyManagerProvider = (*resourceAdapter)(nil)
|
||||||
_ identity.IdentityGroupProvider = (*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
|
// 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()
|
return r.metaProvider.Name()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *resourceAdapter) NameOriginal() string {
|
func (r *resourceAdapter) NameNormalized() string {
|
||||||
r.init(false, false)
|
r.init(false, false)
|
||||||
return r.target.(resource.NameOriginalProvider).NameOriginal()
|
return r.target.(resource.NameNormalizedProvider).NameNormalized()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *resourceAdapter) Params() maps.Params {
|
func (r *resourceAdapter) Params() maps.Params {
|
||||||
|
|
Loading…
Reference in a new issue