diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-08-13 12:35:04 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-08-13 18:09:46 +0200 |
commit | cd575023af846aa18ffa709f37bc70277e98cad3 (patch) | |
tree | b3eb6fcd3ab7b9073699df0486210cec00f877a1 /hugofs/glob/glob.go | |
parent | 6315098104ff80f8be6d5ae812835b4b4079582e (diff) |
Improve the server assets cache invalidation logic
Fixes #6199
Diffstat (limited to 'hugofs/glob/glob.go')
-rw-r--r-- | hugofs/glob/glob.go | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/hugofs/glob/glob.go b/hugofs/glob/glob.go index 18d8d44cb..124a3d50e 100644 --- a/hugofs/glob/glob.go +++ b/hugofs/glob/glob.go @@ -51,7 +51,7 @@ func GetGlob(pattern string) (glob.Glob, error) { } func NormalizePath(p string) string { - return strings.Trim(filepath.ToSlash(strings.ToLower(p)), "/.") + return strings.Trim(path.Clean(filepath.ToSlash(strings.ToLower(p))), "/.") } // ResolveRootDir takes a normalized path on the form "assets/**.json" and @@ -60,14 +60,7 @@ func ResolveRootDir(p string) string { parts := strings.Split(path.Dir(p), "/") var roots []string for _, part := range parts { - isSpecial := false - for i := 0; i < len(part); i++ { - if syntax.Special(part[i]) { - isSpecial = true - break - } - } - if isSpecial { + if HasGlobChar(part) { break } roots = append(roots, part) @@ -79,3 +72,25 @@ func ResolveRootDir(p string) string { return strings.Join(roots, "/") } + +// FilterGlobParts removes any string with glob wildcard. +func FilterGlobParts(a []string) []string { + b := a[:0] + for _, x := range a { + if !HasGlobChar(x) { + b = append(b, x) + } + } + return b +} + +// HasGlobChar returns whether s contains any glob wildcards. +func HasGlobChar(s string) bool { + for i := 0; i < len(s); i++ { + if syntax.Special(s[i]) { + return true + } + } + return false + +} |