Page context handling in i18n

This is a workaround. We need to improve on this, but not today.

Fixes #10782
This commit is contained in:
Bjørn Erik Pedersen
2023-03-04 14:43:23 +01:00
parent ec1c97e7e9
commit 6c798eba60
6 changed files with 115 additions and 9 deletions

View File

@@ -471,3 +471,45 @@ type DeprecatedWarningPageMethods any // This was emptied in Hugo 0.93.0.
// Move here to trigger ERROR instead of WARNING.
// TODO(bep) create wrappers and put into the Page once it has some methods.
type DeprecatedErrorPageMethods any
// PageWithContext is a Page with a context.Context.
type PageWithContext struct {
Page
Ctx context.Context
}
func (p PageWithContext) Content() (any, error) {
return p.Page.Content(p.Ctx)
}
func (p PageWithContext) Plain() string {
return p.Page.Plain(p.Ctx)
}
func (p PageWithContext) PlainWords() []string {
return p.Page.PlainWords(p.Ctx)
}
func (p PageWithContext) Summary() template.HTML {
return p.Page.Summary(p.Ctx)
}
func (p PageWithContext) Truncated() bool {
return p.Page.Truncated(p.Ctx)
}
func (p PageWithContext) FuzzyWordCount() int {
return p.Page.FuzzyWordCount(p.Ctx)
}
func (p PageWithContext) WordCount() int {
return p.Page.WordCount(p.Ctx)
}
func (p PageWithContext) ReadingTime() int {
return p.Page.ReadingTime(p.Ctx)
}
func (p PageWithContext) Len() int {
return p.Page.Len(p.Ctx)
}