mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-21 21:35:28 +02:00
@@ -17,6 +17,7 @@ package internal
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"go/doc"
|
||||
@@ -49,7 +50,7 @@ type TemplateFuncsNamespace struct {
|
||||
Name string
|
||||
|
||||
// This is the method receiver.
|
||||
Context func(v ...any) (any, error)
|
||||
Context func(ctx context.Context, v ...any) (any, error)
|
||||
|
||||
// Additional info, aliases and examples, per method name.
|
||||
MethodMappings map[string]TemplateFuncMethodMapping
|
||||
@@ -172,7 +173,7 @@ func (namespaces TemplateFuncsNamespaces) MarshalJSON() ([]byte, error) {
|
||||
if i != 0 {
|
||||
buf.WriteString(",")
|
||||
}
|
||||
b, err := ns.toJSON()
|
||||
b, err := ns.toJSON(context.TODO())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -188,7 +189,7 @@ var ignoreFuncs = map[string]bool{
|
||||
"Reset": true,
|
||||
}
|
||||
|
||||
func (t *TemplateFuncsNamespace) toJSON() ([]byte, error) {
|
||||
func (t *TemplateFuncsNamespace) toJSON(ctx context.Context) ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
|
||||
godoc := getGetTplPackagesGoDoc()[t.Name]
|
||||
@@ -197,11 +198,11 @@ func (t *TemplateFuncsNamespace) toJSON() ([]byte, error) {
|
||||
|
||||
buf.WriteString(fmt.Sprintf(`%q: {`, t.Name))
|
||||
|
||||
ctx, err := t.Context()
|
||||
tctx, err := t.Context(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ctxType := reflect.TypeOf(ctx)
|
||||
ctxType := reflect.TypeOf(tctx)
|
||||
for i := 0; i < ctxType.NumMethod(); i++ {
|
||||
method := ctxType.Method(i)
|
||||
if ignoreFuncs[method.Name] {
|
||||
|
Reference in New Issue
Block a user