Skip to content

Commit

Permalink
resources/page: Adjust permalinks tests
Browse files Browse the repository at this point in the history
See #11722
  • Loading branch information
bep committed Feb 12, 2025
1 parent 7afd74d commit 0700e01
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions resources/page/permalinks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ var testdataPermalinks = []struct {
{"/:sections[0]/:sections[last]/", true, "/a/c/"}, // Sections
{"/\\:filename", true, "/:filename"}, // Escape sequence
{"/special\\::slug/", true, "/special:the-slug/"}, // Escape sequence
{"/:contentbasename/", true, "/index/"}, // Content base name
{"/:contentbasenameorslug/", true, "/index/"}, // Content base name or slug
{"/:contentbasename/", true, "/test-page/"}, // Content base name
{"/:contentbasenameorslug/", true, "/test-page/"}, // Content base name or slug

// Failures
{"/blog/:fred", false, ""},
Expand Down
2 changes: 1 addition & 1 deletion resources/page/testhelpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func newTestPage() *testPage {

func newTestPageWithFile(filename string) *testPage {
filename = filepath.FromSlash(filename)
file := source.NewFileInfoFrom(filename, filename)
file := source.NewContentFileInfoFrom(filename, filename)

l, err := langs.NewLanguage(
"en",
Expand Down
12 changes: 9 additions & 3 deletions source/fileInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/gohugoio/hugo/common/hashing"
"github.com/gohugoio/hugo/common/hugo"
"github.com/gohugoio/hugo/common/paths"
"github.com/gohugoio/hugo/media"
"github.com/gohugoio/hugo/hugofs/files"

"github.com/gohugoio/hugo/common/hugio"

Expand Down Expand Up @@ -132,11 +132,17 @@ func (fi *File) p() *paths.Path {
return fi.fim.Meta().PathInfo.Unnormalized()
}

var contentPathParser = &paths.PathParser{
IsContentExt: func(ext string) bool {
return true
},
}

// Used in tests.
func NewFileInfoFrom(path, filename string) *File {
func NewContentFileInfoFrom(path, filename string) *File {
meta := &hugofs.FileMeta{
Filename: filename,
PathInfo: media.DefaultPathParser.Parse("", filepath.ToSlash(path)),
PathInfo: contentPathParser.Parse(files.ComponentFolderContent, filepath.ToSlash(path)),
}

return NewFileInfo(hugofs.NewFileMetaInfo(nil, meta))
Expand Down

0 comments on commit 0700e01

Please sign in to comment.