mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-15 20:44:01 +02:00
resources/page: Revise the new contentbasename permalinks tokens
* Make it work for all pages, including those created from content adapters and not backed by a file. * Allow the `slug` to win, so the new tokens are: `:contentbasename`: 1. ContentBaseName `:slugorcontentbasename`: 1. Slug 2. ContentBaseName Note that a page will always have a `ContentBaseName`, so no need to fall back to e.g. the title. Closes #11722
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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))
|
||||
|
Reference in New Issue
Block a user