Improve "watching for ..." logging

This commit is contained in:
Bjørn Erik Pedersen
2015-11-23 16:32:06 +01:00
parent 098a0c819a
commit 831e936846
5 changed files with 59 additions and 38 deletions

View File

@@ -450,37 +450,27 @@ func prettifyPath(in string, b filepathPathBridge) string {
return b.Join(b.Dir(in), name, "index"+ext)
}
// RemoveSubpaths takes a list of paths and removes everything that
// contains another path in the list as a prefix. Ignores any empty
// strings. Used mostly for logging.
//
// e.g. ["hello/world", "hello", "foo/bar", ""] -> ["hello", "foo/bar"]
func RemoveSubpaths(paths []string) []string {
a := make([]string, 0)
for _, cur := range paths {
// ignore trivial case
if cur == "" {
continue
}
isDupe := false
for i, old := range a {
if strings.HasPrefix(cur, old) {
isDupe = true
break
} else if strings.HasPrefix(old, cur) {
a[i] = cur
isDupe = true
break
// Extract the root paths from the supplied list of paths.
// The resulting root path will not contain any file separators, but there
// may be duplicates.
// So "/content/section/" becomes "content"
func ExtractRootPaths(paths []string) []string {
r := make([]string, len(paths))
for i, p := range paths {
root := filepath.ToSlash(p)
if strings.Contains(root, "/") {
sections := strings.Split(root, "/")
for _, section := range sections {
if section != "" {
root = section
break
}
}
}
if !isDupe {
a = append(a, cur)
}
r[i] = root
}
return r
return a
}
// FindCWD returns the current working directory from where the Hugo