resources: Return nil when not found in resources.Get
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 29 May 2019 20:33:03 +0000 (22:33 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 29 May 2019 20:33:03 +0000 (22:33 +0200)
Fixes #5999

hugolib/resource_chain_test.go
resources/resource.go

index e22121b7726a202deec958c07e8d28f43cafb469..5a8ac22d78ea129783d4eb7f139de823386916b6 100644 (file)
@@ -356,6 +356,11 @@ CSV2: {{ $csv2 }}
                                `CSV2: [[a b c]]`,
                        )
                }},
+               {"resources.Get", func() bool { return true }, func(b *sitesBuilder) {
+                       b.WithTemplates("home.html", `NOT FOUND: {{ if (resources.Get "this-does-not-exist") }}FAILED{{ else }}OK{{ end }}`)
+               }, func(b *sitesBuilder) {
+                       b.AssertFileContent("public/index.html", "NOT FOUND: OK")
+               }},
 
                {"template", func() bool { return true }, func(b *sitesBuilder) {}, func(b *sitesBuilder) {
                }},
index abd25154856ee49a2d13b9deb7dac2408f88691c..c120a8dd0902128b6c2a827b3b3478f196a63d87 100644 (file)
@@ -200,6 +200,9 @@ func (r *Spec) newResource(sourceFs afero.Fs, fd ResourceSourceDescriptor) (reso
                var err error
                fi, err = sourceFs.Stat(fd.SourceFilename)
                if err != nil {
+                       if os.IsNotExist(err) {
+                               return nil, nil
+                       }
                        return nil, err
                }
                sourceFilename = fd.SourceFilename