mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-14 14:56:27 +03:00
browse: Sort directory contents by name
This commit is contained in:
parent
6b27d4ce11
commit
dda9a68499
1 changed files with 9 additions and 0 deletions
|
@ -9,6 +9,7 @@ import (
|
|||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -65,6 +66,12 @@ func (fi FileInfo) HumanModTime(format string) string {
|
|||
return fi.ModTime.Format(format)
|
||||
}
|
||||
|
||||
type fileInfoByName []FileInfo
|
||||
|
||||
func (fi fileInfoByName) Len() int { return len(fi) }
|
||||
func (fi fileInfoByName) Swap(i, j int) { fi[i], fi[j] = fi[j], fi[i] }
|
||||
func (fi fileInfoByName) Less(i, j int) bool { return fi[i].Name < fi[j].Name }
|
||||
|
||||
var IndexPages = []string{
|
||||
"index.html",
|
||||
"index.htm",
|
||||
|
@ -149,6 +156,8 @@ func (b Browse) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
|
|||
continue
|
||||
}
|
||||
|
||||
sort.Sort(fileInfoByName(fileinfos))
|
||||
|
||||
// Determine if user can browse up another folder
|
||||
var canGoUp bool
|
||||
curPath := strings.TrimSuffix(r.URL.Path, "/")
|
||||
|
|
Loading…
Reference in a new issue