summaryrefslogtreecommitdiffstats
path: root/hugolib/resource_chain_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-12-21 10:05:57 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-12-21 13:41:46 +0100
commit43f9df0194d229805d80b13c9e38a7a0fec12cf4 (patch)
treeac086fbbc172da6bbd93a2102748a57978d535fa /hugolib/resource_chain_test.go
parent1021714449a05ef85b2fdfaf65b354cbdee44f23 (diff)
Prevent resource publishing for transformed inline resources
That is, if only `.Content` is accessed. This means that, for a transformed resource to be published to `/public`, you need to access either `.RelPermalink` or `Permalink`. Fixes #4944
Diffstat (limited to 'hugolib/resource_chain_test.go')
-rw-r--r--hugolib/resource_chain_test.go28
1 files changed, 27 insertions, 1 deletions
diff --git a/hugolib/resource_chain_test.go b/hugolib/resource_chain_test.go
index 0335339a3..66a0a7ce6 100644
--- a/hugolib/resource_chain_test.go
+++ b/hugolib/resource_chain_test.go
@@ -168,6 +168,8 @@ T1: {{ $r.Content }}
func TestResourceChain(t *testing.T) {
t.Parallel()
+ assert := require.New(t)
+
tests := []struct {
name string
shouldRun func() bool
@@ -199,7 +201,7 @@ T6: {{ $bundle1.Permalink }}
b.AssertFileContent("public/index.html", `T5 RelPermalink: /sass/styles3.css|`)
b.AssertFileContent("public/index.html", `T6: http://example.com/styles/bundle1.css`)
- b.AssertFileContent("public/styles/templ.min.css", `.home{color:blue}`)
+ assert.False(b.CheckExists("public/styles/templ.min.css"))
b.AssertFileContent("public/styles/bundle1.css", `.home{color:blue}body{color:#333}`)
}},
@@ -313,6 +315,30 @@ T1: {{ $r1.Permalink }}|{{ $r1.RelPermalink }}
}},
+ // https://github.com/gohugoio/hugo/issues/4944
+ {"Prevent resource publish on .Content only", func() bool { return true }, func(b *sitesBuilder) {
+ b.WithTemplates("home.html", `
+{{ $cssInline := "body { color: green; }" | resources.FromString "inline.css" | minify }}
+{{ $cssPublish1 := "body { color: blue; }" | resources.FromString "external1.css" | minify }}
+{{ $cssPublish2 := "body { color: orange; }" | resources.FromString "external2.css" | minify }}
+
+Inline: {{ $cssInline.Content }}
+Publish 1: {{ $cssPublish1.Content }} {{ $cssPublish1.RelPermalink }}
+Publish 2: {{ $cssPublish2.Permalink }}
+`)
+
+ }, func(b *sitesBuilder) {
+ b.AssertFileContent("public/index.html",
+ `Inline: body{color:green}`,
+ "Publish 1: body{color:blue} /external1.min.css",
+ "Publish 2: http://example.com/external2.min.css",
+ )
+ assert.True(b.CheckExists("public/external2.min.css"), "Referenced content should be copied to /public")
+ assert.True(b.CheckExists("public/external1.min.css"), "Referenced content should be copied to /public")
+
+ assert.False(b.CheckExists("public/inline.min.css"), "Inline content should not be copied to /public")
+ }},
+
{"template", func() bool { return true }, func(b *sitesBuilder) {}, func(b *sitesBuilder) {
}},
}