mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-28 22:21:46 -05:00
resource: Create target dir if not exists
This is the case where image processing is triggered from shortcodes, i.e. before the target page's folder in /public is created. Fixes #4202
This commit is contained in:
parent
bf8a61fde5
commit
16e1d99c6d
1 changed files with 13 additions and 1 deletions
|
@ -411,7 +411,19 @@ func (i *Image) copyToDestination(src string) error {
|
|||
defer in.Close()
|
||||
|
||||
out, 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.Source.MkdirAll(filepath.Dir(target), os.FileMode(0755)); err != nil {
|
||||
res = err
|
||||
return
|
||||
}
|
||||
out, err = i.spec.Fs.Destination.Create(target)
|
||||
if err != nil {
|
||||
res = err
|
||||
return
|
||||
}
|
||||
} else if err != nil {
|
||||
res = err
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue