URI: 
       hugolib: Add Page.Equals - hugo - [fork] hugo port for 9front
  HTML git clone git@git.drkhsh.at/hugo.git
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
   DIR README
   DIR LICENSE
       ---
   DIR commit f0f49ed9b0c9b4545a45c95d56340fcbf4aafbef
   DIR parent 71ae9b4533083be185c5314c9c5b273cc3bd07bd
  HTML Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
       Date:   Wed, 16 Aug 2017 09:59:42 +0200
       
       hugolib: Add Page.Equals
       
       Diffstat:
         M hugolib/site_sections.go            |      12 ++++++++++++
         M hugolib/site_sections_test.go       |      10 ++++++++++
       
       2 files changed, 22 insertions(+), 0 deletions(-)
       ---
   DIR diff --git a/hugolib/site_sections.go b/hugolib/site_sections.go
       @@ -109,6 +109,18 @@ func (p *Page) IsAncestor(other interface{}) (bool, error) {
                return helpers.HasStringsPrefix(pp.sections, p.sections), nil
        }
        
       +// Equals returns whether the current page equals the given page.
       +// Note that this is more accurate than doing `{{ if eq $page $otherPage }}`
       +// since a Page can be embedded in another type.
       +func (p *Page) Equals(other interface{}) (bool, error) {
       +        pp, err := unwrapPage(other)
       +        if err != nil {
       +                return false, err
       +        }
       +
       +        return p == pp, nil
       +}
       +
        func unwrapPage(in interface{}) (*Page, error) {
                if po, ok := in.(*PageOutput); ok {
                        in = po.Page
   DIR diff --git a/hugolib/site_sections_test.go b/hugolib/site_sections_test.go
       @@ -149,6 +149,16 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
                                d := p.s.getPage(KindSection, "empty2", "b", "c", "d")
                                assert.NotNil(d)
                                assert.Equal("T41_-1", d.Title)
       +
       +                        equals, err := c.Equals(d)
       +                        assert.NoError(err)
       +                        assert.False(equals)
       +                        equals, err = c.Equals(c)
       +                        assert.NoError(err)
       +                        assert.True(equals)
       +                        _, err = c.Equals("asdf")
       +                        assert.Error(err)
       +
                        }},
                        {"empty3", func(p *Page) {
                                // b,c,d with regular page in b