summaryrefslogtreecommitdiffstats
path: root/resource/resource.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-02-27 18:29:15 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-02-27 18:29:15 +0100
commitba94abbf5dd90f989242af8a7027d67a572a6128 (patch)
treeeb9bd09e1ac8c38a551cec0b5f681ca0d8bef0b0 /resource/resource.go
parent55fb0eac2019cfa22d0e6a9770d36a14be8e4d99 (diff)
resource: Fix SVG and similar resource handling
The validation of if we could process the image (resize etc.) was moved up in Hugo 0.37, which meant SVG and other "non-processable" images would fail. This commit fixes that by creating a regular resource for these image formats. They will not have `.Resize` or any of the other image methods. Fixes #4455
Diffstat (limited to 'resource/resource.go')
-rw-r--r--resource/resource.go18
1 files changed, 9 insertions, 9 deletions
diff --git a/resource/resource.go b/resource/resource.go
index 67aed39c2..828b03da1 100644
--- a/resource/resource.go
+++ b/resource/resource.go
@@ -23,8 +23,6 @@ import (
"strings"
"sync"
- "github.com/disintegration/imaging"
-
"github.com/spf13/cast"
"github.com/gobwas/glob"
@@ -288,6 +286,15 @@ func (r *Spec) newResource(
gr := r.newGenericResource(targetPathBuilder, fi, absPublishDir, absSourceFilename, filepath.ToSlash(relTargetFilename), mimeType)
if mimeType == "image" {
+ ext := strings.ToLower(helpers.Ext(absSourceFilename))
+
+ imgFormat, ok := imageFormats[ext]
+ if !ok {
+ // This allows SVG etc. to be used as resources. They will not have the methods of the Image, but
+ // that would not (currently) have worked.
+ return gr, nil
+ }
+
f, err := r.Fs.Source.Open(absSourceFilename)
if err != nil {
return nil, err
@@ -299,13 +306,6 @@ func (r *Spec) newResource(
return nil, err
}
- ext := strings.ToLower(helpers.Ext(absSourceFilename))
-
- imgFormat, ok := imageFormats[ext]
- if !ok {
- return nil, imaging.ErrUnsupportedFormat
- }
-
return &Image{
hash: hash,
format: imgFormat,