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:
Bjørn Erik Pedersen 2025-02-12 22:36:24 +01:00
parent cb7a4339b7
commit 7b7a0f3624
6 changed files with 145 additions and 60 deletions

View file

@ -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",
@ -67,9 +67,10 @@ func newTestPageWithFile(filename string) *testPage {
}
return &testPage{
params: make(map[string]any),
data: make(map[string]any),
file: file,
params: make(map[string]any),
data: make(map[string]any),
file: file,
pathInfo: file.FileInfo().Meta().PathInfo,
currentSection: &testPage{
sectionEntries: []string{"a", "b", "c"},
},
@ -90,7 +91,8 @@ type testPage struct {
fuzzyWordCount int
path string
path string
pathInfo *paths.Path
slug string
@ -406,7 +408,7 @@ func (p *testPage) Path() string {
}
func (p *testPage) PathInfo() *paths.Path {
panic("testpage: not implemented")
return p.pathInfo
}
func (p *testPage) Permalink() string {