Commit 4e1229e7 authored by Toby Allen's avatar Toby Allen Committed by Matt Holt

browse: sort listing by dir first (#1527)

* Default Browse sort by Dir, File

* Ignore temp template files

* Add folder to test

* unneeded chagne
parent 5341c85a
......@@ -17,3 +17,5 @@ Caddyfile
og_static/
.vscode/
caddyhttp/browse/temp*
\ No newline at end of file
......@@ -137,7 +137,14 @@ func (l byName) Swap(i, j int) { l.Items[i], l.Items[j] = l.Items[j], l.Items[i]
// Treat upper and lower case equally
func (l byName) Less(i, j int) bool {
// if both are dir or file sort normally
if l.Items[i].IsDir == l.Items[j].IsDir {
return strings.ToLower(l.Items[i].Name) < strings.ToLower(l.Items[j].Name)
} else {
// always sort dir ahead of file
return l.Items[i].IsDir
}
}
// By Size
......
......@@ -181,6 +181,8 @@ func TestBrowseTemplate(t *testing.T) {
<h1>/photos/</h1>
<a href="./test1/">test1</a><br>
<a href="./test.html">test.html</a><br>
<a href="./test2.html">test2.html</a><br>
......@@ -192,7 +194,7 @@ func TestBrowseTemplate(t *testing.T) {
`
if respBody != expectedBody {
t.Fatalf("Expected body: %v got: %v", expectedBody, respBody)
t.Fatalf("Expected body: '%v' got: '%v'", expectedBody, respBody)
}
}
......
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment