tpl/resources: Add resources.Publish

Closes #15208
This commit is contained in:
Bjørn Erik Pedersen
2026-08-15 12:03:21 +02:00
parent 49dceb19f5
commit a05736cb9f
3 changed files with 37 additions and 0 deletions
+5
View File
@@ -90,6 +90,11 @@ func init() {
[][2]string{},
)
ns.AddMethodMapping(ctx.Publish,
nil,
[][2]string{},
)
ns.AddMethodMapping(ctx.PostProcess,
nil,
[][2]string{},
+12
View File
@@ -296,6 +296,18 @@ func (ns *Namespace) Minify(r resources.ResourceTransformer) (resource.Resource,
return ns.minifyClient.Minify(r)
}
// Publish publishes r to the destination and returns it.
func (ns *Namespace) Publish(r resource.Resource) (resource.Resource, error) {
s, ok := r.(resource.Source)
if !ok {
return nil, fmt.Errorf("%T can not be published", r)
}
if err := s.Publish(); err != nil {
return nil, err
}
return r, nil
}
// PostProcess processes r after the build.
//
// Deprecated: Use templates.Defer instead.
@@ -278,6 +278,26 @@ disableKinds = ['page','section','rss','sitemap','taxonomy','term']
b.AssertLogContains("! WARN Dart Sass: hugo:vars")
}
// See issue 15208.
func TestPublish(t *testing.T) {
t.Parallel()
files := `
-- hugo.toml --
disableKinds = ["taxonomy", "term", "section", "RSS", "sitemap", "robotsTXT", "404"]
-- assets/js/main.js --
let foo;
-- layouts/home.html --
{{ $r := resources.Get "js/main.js" | minify | resources.Publish }}
Name: {{ $r.Name }}|
`
b := hugolib.Test(t, files)
b.AssertFileContent("public/index.html", "Name: /js/main.js|")
b.AssertFileExists("public/js/main.min.js", true)
}
// See issue 15086.
func TestPostProcessDeprecated(t *testing.T) {
t.Parallel()