mirror of
https://github.com/caddyserver/caddy.git
synced 2025-02-21 18:59:55 +08:00
browse: Sort directory contents by name
This commit is contained in:
parent
6b27d4ce11
commit
dda9a68499
@ -9,6 +9,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -65,6 +66,12 @@ func (fi FileInfo) HumanModTime(format string) string {
|
|||||||
return fi.ModTime.Format(format)
|
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{
|
var IndexPages = []string{
|
||||||
"index.html",
|
"index.html",
|
||||||
"index.htm",
|
"index.htm",
|
||||||
@ -149,6 +156,8 @@ func (b Browse) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sort.Sort(fileInfoByName(fileinfos))
|
||||||
|
|
||||||
// Determine if user can browse up another folder
|
// Determine if user can browse up another folder
|
||||||
var canGoUp bool
|
var canGoUp bool
|
||||||
curPath := strings.TrimSuffix(r.URL.Path, "/")
|
curPath := strings.TrimSuffix(r.URL.Path, "/")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user