From 4cc07e61d9131c3564d4f450342975652966f90e Mon Sep 17 00:00:00 2001 From: Caleb Gardner Date: Fri, 23 Aug 2024 18:24:45 -0500 Subject: [PATCH] Better formatting on the files pages --- files.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/files.go b/files.go index 46d5493..d027dad 100644 --- a/files.go +++ b/files.go @@ -6,10 +6,12 @@ import ( "net/http" "os" "path/filepath" + "slices" + "strings" "time" ) -const fileElement = "

%v

%v

" +const fileElement = "
%v
%v
" func filesRequest(w http.ResponseWriter, r *http.Request) { partPath := filepath.Clean(r.URL.Path) @@ -30,6 +32,9 @@ func filesRequest(w http.ResponseWriter, r *http.Request) { if stat.IsDir() { var dirs []os.DirEntry dirs, err = fil.ReadDir(-1) + slices.SortFunc(dirs, func(a, b os.DirEntry) int { + return strings.Compare(a.Name(), b.Name()) + }) if err != nil { pageContent = "

Server error!

" w.WriteHeader(http.StatusInternalServerError)