resources: Improve error message on .Resize etc. on SVGs

Fixes #9875
This commit is contained in:
Bjørn Erik Pedersen
2022-05-25 18:06:20 +02:00
parent 3854a6fa6c
commit bb232a351a
2 changed files with 32 additions and 1 deletions

View File

@@ -17,11 +17,13 @@ import (
"strings"
"testing"
qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/hugolib"
)
// Issue 8931
func TestImageCache(t *testing.T) {
t.Parallel()
files := `
-- config.toml --
@@ -67,3 +69,28 @@ bmp: {{ $bmp.RelPermalink }}|{{ $bmp.MediaType }}|
assertImages()
}
func TestSVGError(t *testing.T) {
t.Parallel()
files := `
-- config.toml --
-- assets/circle.svg --
<svg height="100" width="100"><circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" /></svg>
-- layouts/index.html --
{{ $svg := resources.Get "circle.svg" }}
Width: {{ $svg.Width }}
`
b, err := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
TxtarString: files,
NeedsOsFS: true,
Running: true,
}).BuildE()
b.Assert(err, qt.IsNotNil)
b.Assert(err.Error(), qt.Contains, `error calling Width: this method is only available for raster images. To determine if an image is SVG, you can do {{ if eq .MediaType.SubType "svg" }}{{ end }}`)
}