summaryrefslogtreecommitdiffstats
path: root/helpers
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-08-13 11:01:57 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-08-13 19:00:51 +0200
commit78f8475a054a6277d37f13329afd240b00dc9408 (patch)
tree92c30c046d64f4b4baa4a99a2183deb9c4dee1fe /helpers
parentc09ee78fd235599d3fb794110cd75c024d80cfca (diff)
Fix Resource output in multihost setups
In Hugo 0.46 we made the output of what you get from resources.Get and similar static, i.e. language agnostic. This makes total sense, as it is wasteful and time-consuming to do SASS/SCSS/PostCSS processing for lots of languages when the output is lots of duplicates with different filenames. But since we now output the result once only, this had a negative side effect for multihost setups: We publish the resource once only to the root folder (i.e. not to the language "domain folder"). This commit removes the language code from the processed image keys. This creates less duplication in the file cache, but it means that you should do a `hugo --gc` to clean up stale files. Fixes #5058
Diffstat (limited to 'helpers')
-rw-r--r--helpers/path.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/helpers/path.go b/helpers/path.go
index 134a20527..3586c5744 100644
--- a/helpers/path.go
+++ b/helpers/path.go
@@ -24,6 +24,7 @@ import (
"strings"
"unicode"
+ "github.com/gohugoio/hugo/common/hugio"
"github.com/spf13/afero"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
@@ -515,6 +516,24 @@ func WriteToDisk(inpath string, r io.Reader, fs afero.Fs) (err error) {
return afero.WriteReader(fs, inpath, r)
}
+// OpenFileForWriting opens all the given filenames for writing.
+func OpenFilesForWriting(fs afero.Fs, filenames ...string) (io.WriteCloser, error) {
+ var writeClosers []io.WriteCloser
+ for _, filename := range filenames {
+ f, err := OpenFileForWriting(fs, filename)
+ if err != nil {
+ for _, wc := range writeClosers {
+ wc.Close()
+ }
+ return nil, err
+ }
+ writeClosers = append(writeClosers, f)
+ }
+
+ return hugio.NewMultiWriteCloser(writeClosers...), nil
+
+}
+
// OpenFileForWriting opens or creates the given file. If the target directory
// does not exist, it gets created.
func OpenFileForWriting(fs afero.Fs, filename string) (afero.File, error) {