URI: 
       tpl: Fix some baseof lookup issues - 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 9221cbca496752fb1d06d664871e3d4532f473f5
   DIR parent e3e3f9ae17395220e2c13ddc8afa7000a5a7e21e
  HTML Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
       Date:   Fri, 11 Apr 2025 10:16:28 +0200
       
       tpl: Fix some baseof lookup issues
       
       We were mistakingly using the templates (e.g. list.html) descriptor to resolve the base template and not the page,
       which worked fine in most cases, but not all.
       
       Fixes #13583
       
       Diffstat:
         M tpl/templates/templates_integratio… |      28 ++++++++++++++++++++++++++++
         M tpl/tplimpl/templatestore.go        |      10 +++++-----
       
       2 files changed, 33 insertions(+), 5 deletions(-)
       ---
   DIR diff --git a/tpl/templates/templates_integration_test.go b/tpl/templates/templates_integration_test.go
       @@ -166,3 +166,31 @@ p3.current.Ancestors.Reverse: {{ with templates.Current }}{{ range .Ancestors.Re
                        "p2.current.Ancestors: _partials/p1.html|all.html",
                )
        }
       +
       +func TestBaseOfIssue13583(t *testing.T) {
       +        t.Parallel()
       +
       +        files := `
       +-- hugo.toml --
       +-- content/_index.md --
       +---
       +title: "Home"
       +outputs: ["html", "amp"]
       +---
       +title: "Home"
       +-- layouts/baseof.html --
       +layouts/baseof.html
       +{{ block "main" . }}{{ end }}
       +-- layouts/baseof.amp.html --
       +layouts/baseof.amp.html
       +{{ block "main" . }}{{ end }}
       +-- layouts/home.html --
       +{{ define "main" }}
       +Home.
       +{{ end }}
       +
       +`
       +        b := hugolib.Test(t, files)
       +        b.AssertFileContent("public/index.html", "layouts/baseof.html")
       +        b.AssertFileContent("public/amp/index.html", "layouts/baseof.amp.html")
       +}
   DIR diff --git a/tpl/tplimpl/templatestore.go b/tpl/tplimpl/templatestore.go
       @@ -301,7 +301,7 @@ func (ti *TemplInfo) String() string {
                return ti.PathInfo.String()
        }
        
       -func (ti *TemplInfo) findBestMatchBaseof(s *TemplateStore, k1 string, slashCountK1 int, best *bestMatch) {
       +func (ti *TemplInfo) findBestMatchBaseof(s *TemplateStore, d1 TemplateDescriptor, k1 string, slashCountK1 int, best *bestMatch) {
                if ti.baseVariants == nil {
                        return
                }
       @@ -310,11 +310,11 @@ func (ti *TemplInfo) findBestMatchBaseof(s *TemplateStore, k1 string, slashCount
                        slashCountK2 := strings.Count(k2, "/")
                        distance := slashCountK1 - slashCountK2
        
       -                for d, vv := range v {
       -                        weight := s.dh.compareDescriptors(CategoryBaseof, ti.D, d)
       +                for d2, vv := range v {
       +                        weight := s.dh.compareDescriptors(CategoryBaseof, d1, d2)
                                weight.distance = distance
                                if best.isBetter(weight, vv.Template) {
       -                                best.updateValues(weight, k2, d, vv.Template)
       +                                best.updateValues(weight, k2, d2, vv.Template)
                                }
                        }
                        return false, nil
       @@ -538,7 +538,7 @@ func (s *TemplateStore) LookupPagesLayout(q TemplateQuery) *TemplInfo {
                        return m
                }
                best1.reset()
       -        m.findBestMatchBaseof(s, key, slashCountKey, best1)
       +        m.findBestMatchBaseof(s, q.Desc, key, slashCountKey, best1)
                if best1.w.w1 <= 0 {
                        return nil
                }