diff --git a/hugolib/page__tree.go b/hugolib/page__tree.go index a99e6f16cf3..bddfde7c865 100644 --- a/hugolib/page__tree.go +++ b/hugolib/page__tree.go @@ -104,6 +104,10 @@ func (pt pageTree) InSection(other interface{}) (bool, error) { } +func (pt pageTree) Page() page.Page { + return pt.p +} + func (pt pageTree) Parent() page.Page { return pt.p.parent } diff --git a/resources/page/page.go b/resources/page/page.go index efbefb45610..1f6758542ad 100644 --- a/resources/page/page.go +++ b/resources/page/page.go @@ -340,6 +340,10 @@ type TreeProvider interface { // Sections returns this section's subsections, if any. // Note that for non-sections, this method will always return an empty list. Sections() Pages + + // Page returns a reference to the Page itself, kept here mostly + // for legacy reasons. + Page() Page } // DeprecatedWarningPageMethods lists deprecated Page methods that will trigger diff --git a/resources/page/page_generate/generate_page_wrappers.go b/resources/page/page_generate/generate_page_wrappers.go index af85cb429a5..54e1f272ea5 100644 --- a/resources/page/page_generate/generate_page_wrappers.go +++ b/resources/page/page_generate/generate_page_wrappers.go @@ -107,7 +107,12 @@ func generateMarshalJSON(c *codegen.Inspector) error { return errors.New("no methods found") } - marshalJSON, pkgImports := methods.ToMarshalJSON("Page", "github.com/gohugoio/hugo/resources/page") + marshalJSON, pkgImports := methods.ToMarshalJSON( + "Page", + "github.com/gohugoio/hugo/resources/page", + // Exclusion regexps. Matches method names. + `\bPage\b`, + ) fmt.Fprintf(f, `%s diff --git a/resources/page/page_nop.go b/resources/page/page_nop.go index 7afbee216c8..229bcb077e4 100644 --- a/resources/page/page_nop.go +++ b/resources/page/page_nop.go @@ -299,6 +299,10 @@ func (p *nopPage) Params() map[string]interface{} { return nil } +func (p *nopPage) Page() Page { + return p +} + func (p *nopPage) Parent() Page { return nil } diff --git a/resources/page/testhelpers_test.go b/resources/page/testhelpers_test.go index c2bcca0a5bc..60a6c0816fb 100644 --- a/resources/page/testhelpers_test.go +++ b/resources/page/testhelpers_test.go @@ -360,6 +360,10 @@ func (p *testPage) Params() map[string]interface{} { return p.params } +func (p *testPage) Page() Page { + return p +} + func (p *testPage) Parent() Page { panic("not implemented") }