Add a page template func

Fixes #9339
This commit is contained in:
Bjørn Erik Pedersen 2023-02-25 09:24:59 +01:00
parent 2662faf61f
commit ce524d0b5e
54 changed files with 436 additions and 108 deletions

View file

@ -69,6 +69,7 @@ func newResourceAdapter(spec *Spec, lazyPublish bool, target transformableResour
return &resourceAdapter{
resourceTransformations: &resourceTransformations{},
resourceAdapterInner: &resourceAdapterInner{
ctx: context.TODO(),
spec: spec,
publishOnce: po,
target: target,
@ -84,6 +85,9 @@ type ResourceTransformation interface {
}
type ResourceTransformationCtx struct {
// The context that started the transformation.
Ctx context.Context
// The content to transform.
From io.Reader
@ -180,6 +184,7 @@ func (r *resourceAdapter) Data() any {
func (r resourceAdapter) cloneTo(targetPath string) resource.Resource {
newtTarget := r.target.cloneTo(targetPath)
newInner := &resourceAdapterInner{
ctx: r.ctx,
spec: r.spec,
target: newtTarget.(transformableResource),
}
@ -278,11 +283,17 @@ func (r *resourceAdapter) Title() string {
}
func (r resourceAdapter) Transform(t ...ResourceTransformation) (ResourceTransformer, error) {
return r.TransformWithContext(context.Background(), t...)
}
func (r resourceAdapter) TransformWithContext(ctx context.Context, t ...ResourceTransformation) (ResourceTransformer, error) {
r.resourceTransformations = &resourceTransformations{
transformations: append(r.transformations, t...),
}
r.resourceAdapterInner = &resourceAdapterInner{
ctx: ctx,
spec: r.spec,
publishOnce: &publishOnce{},
target: r.target,
@ -377,6 +388,7 @@ func (r *resourceAdapter) transform(publish, setContent bool) error {
defer bp.PutBuffer(b2)
tctx := &ResourceTransformationCtx{
Ctx: r.ctx,
Data: make(map[string]any),
OpenResourcePublisher: r.target.openPublishFileForWriting,
}
@ -599,6 +611,9 @@ func (r *resourceAdapter) initTransform(publish, setContent bool) {
}
type resourceAdapterInner struct {
// The context that started this transformation.
ctx context.Context
target transformableResource
spec *Spec