ref: 196da49c9d906fbae6d389fdd32b80c27cb38de4
parent: 2aa4c009eec3375f56740f90917f5bee6a72c7f5
author: Bjørn Erik Pedersen <[email protected]>
date: Wed Jan 3 05:28:16 EST 2018
resource: Handle publish to /public on fresh build Fixes #4213
--- a/resource/image.go
+++ b/resource/image.go
@@ -450,9 +450,20 @@
target := filepath.Join(i.absPublishDir, filename)
file1, err := i.spec.Fs.Destination.Create(target)
- if err != nil {
+ if err != nil && os.IsNotExist(err) {
+ // When called from shortcodes, the target directory may not exist yet.
+ // See https://github.com/gohugoio/hugo/issues/4202
+ if err = i.spec.Fs.Destination.MkdirAll(filepath.Dir(target), os.FileMode(0755)); err != nil {
+ return err
+ }
+ file1, err = i.spec.Fs.Destination.Create(target)
+ if err != nil {
+ return err
+ }
+ } else if err != nil {
return err
}
+
defer file1.Close()
var w io.Writer