Skip to content

Commit

Permalink
resource: Handle publish to /public on fresh build
Browse files Browse the repository at this point in the history
Fixes #4213
  • Loading branch information
bep committed Jan 3, 2018
1 parent 2aa4c00 commit 196da49
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion resource/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 196da49

Please sign in to comment.