diff options
Diffstat (limited to 'helpers/general.go')
-rw-r--r-- | helpers/general.go | 54 |
1 files changed, 24 insertions, 30 deletions
diff --git a/helpers/general.go b/helpers/general.go index 5b46520e5..b442b1eb4 100644 --- a/helpers/general.go +++ b/helpers/general.go @@ -20,18 +20,20 @@ import ( "fmt" "io" "net" + "os" "path/filepath" "strings" "sync" "unicode" "unicode/utf8" + "github.com/gohugoio/hugo/hugofs" + "github.com/spf13/afero" "github.com/jdkato/prose/transform" bp "github.com/gohugoio/hugo/bufferpool" - "github.com/spf13/cast" jww "github.com/spf13/jwalterweatherman" "github.com/spf13/pflag" ) @@ -129,30 +131,6 @@ func ReaderToBytes(lines io.Reader) []byte { return bc } -// ToLowerMap makes all the keys in the given map lower cased and will do so -// recursively. -// Notes: -// * This will modify the map given. -// * Any nested map[interface{}]interface{} will be converted to map[string]interface{}. -func ToLowerMap(m map[string]interface{}) { - for k, v := range m { - switch v.(type) { - case map[interface{}]interface{}: - v = cast.ToStringMap(v) - ToLowerMap(v.(map[string]interface{})) - case map[string]interface{}: - ToLowerMap(v.(map[string]interface{})) - } - - lKey := strings.ToLower(k) - if k != lKey { - delete(m, k) - m[lKey] = v - } - - } -} - // ReaderToString is the same as ReaderToBytes, but returns a string. func ReaderToString(lines io.Reader) string { if lines == nil { @@ -255,11 +233,6 @@ func compareStringSlices(a, b []string) bool { return true } -// ThemeSet checks whether a theme is in use or not. -func (p *PathSpec) ThemeSet() bool { - return p.theme != "" -} - // LogPrinter is the common interface of the JWWs loggers. type LogPrinter interface { // Println is the only common method that works in all of JWWs loggers. @@ -477,3 +450,24 @@ func DiffStringSlices(slice1 []string, slice2 []string) []string { func DiffStrings(s1, s2 string) []string { return DiffStringSlices(strings.Fields(s1), strings.Fields(s2)) } + +// PrintFs prints the given filesystem to the given writer starting from the given path. +// This is useful for debugging. +func PrintFs(fs afero.Fs, path string, w io.Writer) { + if fs == nil { + return + } + afero.Walk(fs, path, func(path string, info os.FileInfo, err error) error { + if info != nil && !info.IsDir() { + s := path + if lang, ok := info.(hugofs.LanguageAnnouncer); ok { + s = s + "\tLANG: " + lang.Lang() + } + if fp, ok := info.(hugofs.FilePather); ok { + s = s + "\tRF: " + fp.Filename() + "\tBP: " + fp.BaseDir() + } + fmt.Fprintln(w, " ", s) + } + return nil + }) +} |