mirror of
https://github.com/gohugoio/hugo.git
synced 2026-08-24 15:28:54 +00:00
@@ -90,6 +90,11 @@ func init() {
|
||||
[][2]string{},
|
||||
)
|
||||
|
||||
ns.AddMethodMapping(ctx.Publish,
|
||||
nil,
|
||||
[][2]string{},
|
||||
)
|
||||
|
||||
ns.AddMethodMapping(ctx.PostProcess,
|
||||
nil,
|
||||
[][2]string{},
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user