mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-18 21:11:19 +02:00
tpl: Add templates.Current
This commit also * Unexport all internal state in TemplateInfo. * Make the dispatcher keys used for passing context.Context into uint8 from string to save memory allocations. Co-authored-by: Joe Mooring <joe@mooring.com> Updates #13571
This commit is contained in:
@@ -667,7 +667,13 @@ func (c *cachedContentScope) mustContentToC(ctx context.Context) contentTableOfC
|
||||
return ct
|
||||
}
|
||||
|
||||
var setGetContentCallbackInContext = hcontext.NewContextDispatcher[func(*pageContentOutput, contentTableOfContents)]("contentCallback")
|
||||
type contextKey uint8
|
||||
|
||||
const (
|
||||
contextKeyContentCallback contextKey = iota
|
||||
)
|
||||
|
||||
var setGetContentCallbackInContext = hcontext.NewContextDispatcher[func(*pageContentOutput, contentTableOfContents)](contextKeyContentCallback)
|
||||
|
||||
func (c *cachedContentScope) contentToC(ctx context.Context) (contentTableOfContents, error) {
|
||||
cp := c.pco
|
||||
|
@@ -120,7 +120,7 @@ func (pco *pageContentOutput) Render(ctx context.Context, layout ...string) (tem
|
||||
// Make sure to send the *pageState and not the *pageContentOutput to the template.
|
||||
res, err := executeToString(ctx, pco.po.p.s.GetTemplateStore(), templ, pco.po.p)
|
||||
if err != nil {
|
||||
return "", pco.po.p.wrapError(fmt.Errorf("failed to execute template %s: %w", templ.Template.Name(), err))
|
||||
return "", pco.po.p.wrapError(fmt.Errorf("failed to execute template %s: %w", templ.Name(), err))
|
||||
}
|
||||
return template.HTML(res), nil
|
||||
}
|
||||
@@ -323,7 +323,7 @@ func (pco *pageContentOutput) initRenderHooks() error {
|
||||
return false
|
||||
}
|
||||
|
||||
if ignoreInternal && candidate.SubCategory == tplimpl.SubCategoryEmbedded {
|
||||
if ignoreInternal && candidate.SubCategory() == tplimpl.SubCategoryEmbedded {
|
||||
// Don't consider the internal hook templates.
|
||||
return false
|
||||
}
|
||||
|
@@ -168,7 +168,7 @@ func pageRenderer(
|
||||
|
||||
s.Log.Trace(
|
||||
func() string {
|
||||
return fmt.Sprintf("rendering outputFormat %q kind %q using layout %q to %q", p.pageOutput.f.Name, p.Kind(), templ.Template.Name(), targetPath)
|
||||
return fmt.Sprintf("rendering outputFormat %q kind %q using layout %q to %q", p.pageOutput.f.Name, p.Kind(), templ.Name(), targetPath)
|
||||
},
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user