diff --git a/cmd/files.go b/cmd/files.go index cd7c2dd..a87bb7e 100644 --- a/cmd/files.go +++ b/cmd/files.go @@ -44,13 +44,40 @@ func appendPaths(m map[string][]string, path string, filters *Filters) (map[stri directory, filename := filepath.Split(absolutePath) - if filters.IsEmpty() { - m[directory] = append(m[directory], path) - } else { + filename = strings.ToLower(filename) + + switch { + case filters.HasIncludes() && !filters.HasExcludes(): + for i := 0; i < len(filters.Includes); i++ { + if strings.Contains( + filename, + filters.Includes[i], + ) { + m[directory] = append(m[directory], path) + + return m, nil + } + } + + return m, nil + case !filters.HasIncludes() && filters.HasExcludes(): for i := 0; i < len(filters.Excludes); i++ { if strings.Contains( - strings.ToLower(filename), - strings.ToLower(filters.Excludes[i]), + filename, + filters.Excludes[i], + ) { + return m, nil + } + } + + m[directory] = append(m[directory], path) + + return m, nil + case filters.HasIncludes() && filters.HasExcludes(): + for i := 0; i < len(filters.Excludes); i++ { + if strings.Contains( + filename, + filters.Excludes[i], ) { return m, nil } @@ -58,17 +85,21 @@ func appendPaths(m map[string][]string, path string, filters *Filters) (map[stri for i := 0; i < len(filters.Includes); i++ { if strings.Contains( - strings.ToLower(filename), - strings.ToLower(filters.Includes[i]), + filename, + filters.Includes[i], ) { m[directory] = append(m[directory], path) - break + return m, nil } } - } - return m, nil + return m, nil + default: + m[directory] = append(m[directory], path) + + return m, nil + } } func getFirstFile(p *Path) (string, error) { @@ -227,6 +258,17 @@ func getFiles(m map[string][]string, path string, filters *Filters) (map[string] return err } + if Filter && filters.HasExcludes() { + for i := 0; i < len(filters.Excludes); i++ { + if strings.Contains( + strings.ToLower(p), + strings.ToLower(filters.Excludes[i]), + ) { + return filepath.SkipDir + } + } + } + switch { case !Recursive && info.IsDir() && p != path: return filepath.SkipDir diff --git a/cmd/version.go b/cmd/version.go index 62e2782..bf8fbe2 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -10,7 +10,7 @@ import ( "github.com/spf13/cobra" ) -var Version = "0.15.1" +var Version = "0.15.2" func init() { rootCmd.AddCommand(versionCmd) diff --git a/cmd/web.go b/cmd/web.go index 0633f17..1efeb12 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -22,17 +22,33 @@ type Filters struct { } func (f *Filters) IsEmpty() bool { - if len(f.Includes) == 0 && len(f.Excludes) == 0 { + if !f.HasIncludes() && !f.HasExcludes() { return true } return false } +func (f *Filters) HasIncludes() bool { + if len(f.Includes) == 0 { + return false + } + + return true +} + func (f *Filters) GetIncludes() string { return strings.Join(f.Includes, ",") } +func (f *Filters) HasExcludes() bool { + if len(f.Excludes) == 0 { + return false + } + + return true +} + func (f *Filters) GetExcludes() string { return strings.Join(f.Excludes, ",") } @@ -53,7 +69,13 @@ func splitQueryParams(query string) []string { return []string{} } - return strings.Split(query, ",") + params := strings.Split(query, ",") + + for i := 0; i < len(params); i++ { + params[i] = strings.ToLower(params[i]) + } + + return params } func generateQueryParams(filters *Filters, sort string) string { @@ -114,7 +136,8 @@ func serveHtml(w http.ResponseWriter, r *http.Request, filePath string) error { case Filter && Sort: htmlBody += fmt.Sprintf(`