resources/page: Re-introduce .Page.Page
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 25 Mar 2019 06:54:10 +0000 (07:54 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 25 Mar 2019 06:55:46 +0000 (07:55 +0100)
It was removed in 597e418cb02883418f2cebb41400e8e61413f651 -- it's not documented, but it's used in too many real sites on the web.

See #5784

hugolib/page__tree.go
resources/page/page.go
resources/page/page_generate/generate_page_wrappers.go
resources/page/page_nop.go
resources/page/testhelpers_test.go

index a99e6f16cf3bd494f056dbb27bfc660a3b410f2d..bddfde7c865a16cdd490f2e6e48315531d01e2ca 100644 (file)
@@ -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
 }
index efbefb45610f0a139f310ca171df3ea440e59928..1f6758542ad07576078dbc29d7e78beda6e6f3ce 100644 (file)
@@ -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
index af85cb429a5b114c2ddfdc9f1606fa955bf3d2f3..54e1f272ea5b25efb34cf7aa613e3142cc1713c6 100644 (file)
@@ -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
 
index 7afbee216c87752b81c643471b2038b6e3dee213..229bcb077e47fbaa865e708871dc9fb890e40b0c 100644 (file)
@@ -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
 }
index c2bcca0a5bc35e71af6cb67569cf4eb449d513d4..60a6c0816fb8030e701cf771ca566e588207c7a7 100644 (file)
@@ -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")
 }