diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-11-23 09:16:42 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-11-23 21:09:00 +0100 |
commit | f9b4eb4f3968d32f45e0168c854e6b0c7f3a90b0 (patch) | |
tree | bca87a80e39fe35b57fcb36b75fa34e6a1da677a /cache/filecache/filecache_config.go | |
parent | e82b2dc8c1628f2da33e5fb0bae1b03e0594ad2c (diff) |
Handle themes in the new file cache (for images, assets)
In the newly consolidated file cache implementation, we forgot that we also look in the theme(s) for assets (SCSS transformations etc.), which is not good for Netlify and the demo sites.
Fixes #5460
Diffstat (limited to 'cache/filecache/filecache_config.go')
-rw-r--r-- | cache/filecache/filecache_config.go | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/cache/filecache/filecache_config.go b/cache/filecache/filecache_config.go index bb2cc36e7..c451eaf85 100644 --- a/cache/filecache/filecache_config.go +++ b/cache/filecache/filecache_config.go @@ -20,7 +20,6 @@ import ( "time" "github.com/gohugoio/hugo/helpers" - "github.com/gohugoio/hugo/hugolib/paths" "github.com/bep/mapstructure" "github.com/pkg/errors" @@ -68,6 +67,10 @@ type cacheConfig struct { // The directory where files are stored. Dir string + + // Will resources/_gen will get its own composite filesystem that + // also checks any theme. + isResourceDir bool } // GetJSONCache gets the file cache for getJSON. @@ -90,7 +93,7 @@ func (f Caches) AssetsCache() *Cache { return f[cacheKeyAssets] } -func decodeConfig(p *paths.Paths) (cachesConfig, error) { +func decodeConfig(p *helpers.PathSpec) (cachesConfig, error) { c := make(cachesConfig) valid := make(map[string]bool) // Add defaults @@ -145,10 +148,13 @@ func decodeConfig(p *paths.Paths) (cachesConfig, error) { for i, part := range parts { if strings.HasPrefix(part, ":") { - resolved, err := resolveDirPlaceholder(p, part) + resolved, isResource, err := resolveDirPlaceholder(p, part) if err != nil { return c, err } + if isResource { + v.isResourceDir = true + } parts[i] = resolved } } @@ -159,13 +165,15 @@ func decodeConfig(p *paths.Paths) (cachesConfig, error) { } v.Dir = filepath.Clean(filepath.FromSlash(dir)) - if isOsFs && !filepath.IsAbs(v.Dir) { - return c, errors.Errorf("%q must resolve to an absolute directory", v.Dir) - } + if !v.isResourceDir { + if isOsFs && !filepath.IsAbs(v.Dir) { + return c, errors.Errorf("%q must resolve to an absolute directory", v.Dir) + } - // Avoid cache in root, e.g. / (Unix) or c:\ (Windows) - if len(strings.TrimPrefix(v.Dir, filepath.VolumeName(v.Dir))) == 1 { - return c, errors.Errorf("%q is a root folder and not allowed as cache dir", v.Dir) + // Avoid cache in root, e.g. / (Unix) or c:\ (Windows) + if len(strings.TrimPrefix(v.Dir, filepath.VolumeName(v.Dir))) == 1 { + return c, errors.Errorf("%q is a root folder and not allowed as cache dir", v.Dir) + } } if disabled { @@ -179,15 +187,16 @@ func decodeConfig(p *paths.Paths) (cachesConfig, error) { } // Resolves :resourceDir => /myproject/resources etc., :cacheDir => ... -func resolveDirPlaceholder(p *paths.Paths, placeholder string) (string, error) { +func resolveDirPlaceholder(p *helpers.PathSpec, placeholder string) (cacheDir string, isResource bool, err error) { switch strings.ToLower(placeholder) { case ":resourcedir": - return p.AbsResourcesDir, nil + return "", true, nil case ":cachedir": - return helpers.GetCacheDir(p.Fs.Source, p.Cfg) + d, err := helpers.GetCacheDir(p.Fs.Source, p.Cfg) + return d, false, err case ":project": - return filepath.Base(p.WorkingDir), nil + return filepath.Base(p.WorkingDir), false, nil } - return "", errors.Errorf("%q is not a valid placeholder (valid values are :cacheDir or :resourceDir)", placeholder) + return "", false, errors.Errorf("%q is not a valid placeholder (valid values are :cacheDir or :resourceDir)", placeholder) } |