mirror of
https://github.com/caddyserver/caddy.git
synced 2025-02-24 08:49:01 +01:00
browse: sort listing by dir first (#1527)
* Default Browse sort by Dir, File * Ignore temp template files * Add folder to test * unneeded chagne
This commit is contained in:
parent
5341c85a27
commit
4e1229e7c9
4 changed files with 22 additions and 3 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -17,3 +17,5 @@ Caddyfile
|
||||||
og_static/
|
og_static/
|
||||||
|
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|
||||||
|
caddyhttp/browse/temp*
|
|
@ -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
|
// Treat upper and lower case equally
|
||||||
func (l byName) Less(i, j int) bool {
|
func (l byName) Less(i, j int) bool {
|
||||||
return strings.ToLower(l.Items[i].Name) < strings.ToLower(l.Items[j].Name)
|
|
||||||
|
// 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
|
// By Size
|
||||||
|
|
|
@ -181,6 +181,8 @@ func TestBrowseTemplate(t *testing.T) {
|
||||||
|
|
||||||
<h1>/photos/</h1>
|
<h1>/photos/</h1>
|
||||||
|
|
||||||
|
<a href="./test1/">test1</a><br>
|
||||||
|
|
||||||
<a href="./test.html">test.html</a><br>
|
<a href="./test.html">test.html</a><br>
|
||||||
|
|
||||||
<a href="./test2.html">test2.html</a><br>
|
<a href="./test2.html">test2.html</a><br>
|
||||||
|
@ -192,7 +194,7 @@ func TestBrowseTemplate(t *testing.T) {
|
||||||
`
|
`
|
||||||
|
|
||||||
if respBody != expectedBody {
|
if respBody != expectedBody {
|
||||||
t.Fatalf("Expected body: %v got: %v", expectedBody, respBody)
|
t.Fatalf("Expected body: '%v' got: '%v'", expectedBody, respBody)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
8
caddyhttp/browse/testdata/photos/test1/test.html
vendored
Normal file
8
caddyhttp/browse/testdata/photos/test1/test.html
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Test</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in a new issue