diff options
author | Bjørn Erik Pedersen <[email protected]> | 2018-01-03 10:28:16 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2018-01-03 10:28:16 +0100 |
commit | 196da49c9d906fbae6d389fdd32b80c27cb38de4 (patch) | |
tree | d878960a9890df6b009d44e0186dba34be9d64c6 /resource | |
parent | 2aa4c009eec3375f56740f90917f5bee6a72c7f5 (diff) | |
download | hugo-196da49c9d906fbae6d389fdd32b80c27cb38de4.tar.gz hugo-196da49c9d906fbae6d389fdd32b80c27cb38de4.zip |
resource: Handle publish to /public on fresh build
Fixes #4213
Diffstat (limited to 'resource')
-rw-r--r-- | resource/image.go | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/resource/image.go b/resource/image.go index c638a995e..159161de2 100644 --- a/resource/image.go +++ b/resource/image.go @@ -450,9 +450,20 @@ func (i *Image) encodeToDestinations(img image.Image, conf imageConfig, resource 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 |