Reimplement and simplify Hugo's template system

See #13541 for details.

Fixes #13545
Fixes #13515
Closes #7964
Closes #13365
Closes #12988
Closes #4891
This commit is contained in:
Bjørn Erik Pedersen
2025-04-06 19:55:35 +02:00
parent 812ea0b325
commit 83cfdd78ca
138 changed files with 5342 additions and 4396 deletions

View File

@@ -43,7 +43,7 @@ import (
"github.com/gohugoio/hugo/resources"
"github.com/gohugoio/hugo/resources/resource"
"github.com/gohugoio/hugo/resources/resource_factories/create"
"github.com/gohugoio/hugo/tpl"
"github.com/gohugoio/hugo/tpl/tplimpl"
"github.com/mitchellh/mapstructure"
"github.com/spf13/cast"
)
@@ -192,7 +192,7 @@ type BatcherClient struct {
d *deps.Deps
once sync.Once
runnerTemplate tpl.Template
runnerTemplate *tplimpl.TemplInfo
createClient *create.Client
buildClient *BuildClient
@@ -208,7 +208,7 @@ func (c *BatcherClient) New(id string) (js.Batcher, error) {
c.once.Do(func() {
// We should fix the initialization order here (or use the Go template package directly), but we need to wait
// for the Hugo templates to be ready.
tmpl, err := c.d.TextTmpl().Parse("batch-esm-runner", runnerTemplateStr)
tmpl, err := c.d.TemplateStore.TextParse("batch-esm-runner", runnerTemplateStr)
if err != nil {
initErr = err
return
@@ -287,7 +287,7 @@ func (c *BatcherClient) Store() *maps.Cache[string, js.Batcher] {
func (c *BatcherClient) buildBatchGroup(ctx context.Context, t *batchGroupTemplateContext) (resource.Resource, string, error) {
var buf bytes.Buffer
if err := c.d.Tmpl().ExecuteWithContext(ctx, c.runnerTemplate, &buf, t); err != nil {
if err := c.d.GetTemplateStore().ExecuteWithContext(ctx, c.runnerTemplate, &buf, t); err != nil {
return nil, "", err
}