tpl: Fix legacy section mappings

Fixes #13584
This commit is contained in:
Bjørn Erik Pedersen
2025-04-11 11:20:03 +02:00
parent c19f1f2363
commit 1074e01152
4 changed files with 97 additions and 25 deletions

View File

@@ -3,7 +3,9 @@ package tplimpl
import (
"io"
"regexp"
"strconv"
"strings"
"sync/atomic"
"unicode"
"unicode/utf8"
@@ -49,11 +51,6 @@ func (t *templateNamespace) parseTemplate(ti *TemplInfo) error {
}
pi := ti.PathInfo
name := pi.PathNoLeadingSlash()
if ti.isLegacyMapped {
// When mapping the old taxonomy structure to the new one, we may map the same path to multiple templates per kind.
// Append the kind here to make the name unique.
name += ("-" + ti.D.Kind)
}
var (
templ tpl.Template
@@ -62,12 +59,18 @@ func (t *templateNamespace) parseTemplate(ti *TemplInfo) error {
if ti.D.IsPlainText {
prototype := t.parseText
if prototype.Lookup(name) != nil {
name += "-" + strconv.FormatUint(t.nameCounter.Add(1), 10)
}
templ, err = prototype.New(name).Parse(ti.content)
if err != nil {
return err
}
} else {
prototype := t.parseHTML
if prototype.Lookup(name) != nil {
name += "-" + strconv.FormatUint(t.nameCounter.Add(1), 10)
}
templ, err = prototype.New(name).Parse(ti.content)
if err != nil {
return err
@@ -296,6 +299,8 @@ type templateNamespace struct {
prototypeText *texttemplate.Template
prototypeHTML *htmltemplate.Template
nameCounter atomic.Uint64
standaloneText *texttemplate.Template
baseofTextClones []*texttemplate.Template