summaryrefslogtreecommitdiffstats
path: root/tpl/resources
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-02-25 09:24:59 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-02-25 19:53:18 +0100
commitce524d0b5ebaef05d29fa368465f31358f26dcda (patch)
treee5df54a5deeefacbff4916d3619f85c2cb341b01 /tpl/resources
parent2662faf61ff0240be1ee0d6c496b6b4a6ed55fb4 (diff)
Add a page template func
Fixes #9339
Diffstat (limited to 'tpl/resources')
-rw-r--r--tpl/resources/init.go4
-rw-r--r--tpl/resources/resources.go8
2 files changed, 6 insertions, 6 deletions
diff --git a/tpl/resources/init.go b/tpl/resources/init.go
index 73a7b8f42..db51b0287 100644
--- a/tpl/resources/init.go
+++ b/tpl/resources/init.go
@@ -14,6 +14,8 @@
package resources
import (
+ "context"
+
"github.com/gohugoio/hugo/deps"
"github.com/gohugoio/hugo/tpl/internal"
)
@@ -30,7 +32,7 @@ func init() {
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func(args ...any) (any, error) { return ctx, nil },
+ Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil },
}
ns.AddMethodMapping(ctx.Get,
diff --git a/tpl/resources/resources.go b/tpl/resources/resources.go
index 85323f057..cc5310277 100644
--- a/tpl/resources/resources.go
+++ b/tpl/resources/resources.go
@@ -15,11 +15,10 @@
package resources
import (
+ "context"
"fmt"
"sync"
- "github.com/gohugoio/hugo/common/herrors"
-
"errors"
"github.com/gohugoio/hugo/common/maps"
@@ -227,7 +226,6 @@ func (ns *Namespace) ByType(typ any) resource.Resources {
//
// See Match for a more complete explanation about the rules used.
func (ns *Namespace) Match(pattern any) resource.Resources {
- defer herrors.Recover()
patternStr, err := cast.ToStringE(pattern)
if err != nil {
panic(err)
@@ -283,7 +281,7 @@ func (ns *Namespace) FromString(targetPathIn, contentIn any) (resource.Resource,
// ExecuteAsTemplate creates a Resource from a Go template, parsed and executed with
// the given data, and published to the relative target path.
-func (ns *Namespace) ExecuteAsTemplate(args ...any) (resource.Resource, error) {
+func (ns *Namespace) ExecuteAsTemplate(ctx context.Context, args ...any) (resource.Resource, error) {
if len(args) != 3 {
return nil, fmt.Errorf("must provide targetPath, the template data context and a Resource object")
}
@@ -298,7 +296,7 @@ func (ns *Namespace) ExecuteAsTemplate(args ...any) (resource.Resource, error) {
return nil, fmt.Errorf("type %T not supported in Resource transformations", args[2])
}
- return ns.templatesClient.ExecuteAsTemplate(r, targetPath, data)
+ return ns.templatesClient.ExecuteAsTemplate(ctx, r, targetPath, data)
}
// Fingerprint transforms the given Resource with a MD5 hash of the content in