mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-21 21:35:28 +02: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:
@@ -411,10 +411,22 @@ func (i *Image) copyToDestination(src string) error {
|
|||||||
defer in.Close()
|
defer in.Close()
|
||||||
|
|
||||||
out, err := i.spec.Fs.Destination.Create(target)
|
out, err := i.spec.Fs.Destination.Create(target)
|
||||||
|
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 {
|
if err != nil {
|
||||||
res = err
|
res = err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else if err != nil {
|
||||||
|
res = err
|
||||||
|
return
|
||||||
|
}
|
||||||
defer out.Close()
|
defer out.Close()
|
||||||
|
|
||||||
_, err = io.Copy(out, in)
|
_, err = io.Copy(out, in)
|
||||||
|
Reference in New Issue
Block a user