diff --git a/handler.go b/handler.go index d188c9e..8347350 100644 --- a/handler.go +++ b/handler.go @@ -100,7 +100,12 @@ func dirList(w http.ResponseWriter, r *http.Request, f http.File, name string) { renderError(w, "Error reading directory", http.StatusInternalServerError) return } - sort.Slice(dirs, func(i, j int) bool { return dirs[i].Name() < dirs[j].Name() }) + sort.Slice(dirs, func(i, j int) bool { + if dirs[i].IsDir() && !dirs[j].IsDir() { + return true + } + return dirs[i].Name() < dirs[j].Name() + }) w.Header().Set("Content-Type", "text/html; charset=utf-8") @@ -111,8 +116,9 @@ func dirList(w http.ResponseWriter, r *http.Request, f http.File, name string) { } data := &Data{ - Title: name, - Files: make([]*File, 0, len(dirs)), + Title: name, + IsRoot: name == "/", + Files: make([]*File, 0, len(dirs)), } for _, d := range dirs {