Implement defer

Closes #8086
Closes #12589
This commit is contained in:
Bjørn Erik Pedersen
2024-06-08 11:52:22 +02:00
parent 8731d88222
commit 6cd0784e44
33 changed files with 1033 additions and 148 deletions

View File

@@ -20,11 +20,13 @@ import (
"reflect"
"regexp"
"strings"
"sync"
"unicode"
bp "github.com/gohugoio/hugo/bufferpool"
"github.com/gohugoio/hugo/common/hcontext"
"github.com/gohugoio/hugo/identity"
"github.com/gohugoio/hugo/langs"
"github.com/gohugoio/hugo/output/layouts"
"github.com/gohugoio/hugo/output"
@@ -160,6 +162,11 @@ type TemplateFuncGetter interface {
GetFunc(name string) (reflect.Value, bool)
}
type RenderingContext struct {
Site site
SiteOutIdx int
}
type contextKey string
// Context manages values passed in the context to templates.
@@ -191,6 +198,15 @@ type page interface {
IsNode() bool
}
type site interface {
Language() *langs.Language
}
const (
HugoDeferredTemplatePrefix = "__hdeferred/"
HugoDeferredTemplateSuffix = "__d="
)
const hugoNewLinePlaceholder = "___hugonl_"
var stripHTMLReplacerPre = strings.NewReplacer("\n", " ", "</p>", hugoNewLinePlaceholder, "<br>", hugoNewLinePlaceholder, "<br />", hugoNewLinePlaceholder)
@@ -228,3 +244,13 @@ func StripHTML(s string) string {
return s
}
type DeferredExecution struct {
Mu sync.Mutex
Ctx context.Context
TemplateName string
Data any
Executed bool
Result string
}