Sort directory listings with directories before files
This commit is contained in:
parent
e42c366565
commit
a4873da190
36
dirlist.go
36
dirlist.go
|
@ -42,10 +42,46 @@ func generateDirectoryListing(URL *url.URL, path string, config Config) (string,
|
|||
i, j = j, i
|
||||
}
|
||||
if config.DirectorySort == "Name" {
|
||||
if files[i].IsDir() {
|
||||
if files[j].IsDir() {
|
||||
return files[i].Name() < files[j].Name()
|
||||
}
|
||||
return true
|
||||
}
|
||||
if files[j].IsDir() {
|
||||
if files[i].IsDir() {
|
||||
return files[i].Name() < files[j].Name()
|
||||
}
|
||||
return false
|
||||
}
|
||||
return files[i].Name() < files[j].Name()
|
||||
} else if config.DirectorySort == "Size" {
|
||||
if files[i].IsDir() {
|
||||
if files[j].IsDir() {
|
||||
return files[i].Size() < files[j].Size()
|
||||
}
|
||||
return true
|
||||
}
|
||||
if files[j].IsDir() {
|
||||
if files[i].IsDir() {
|
||||
return files[i].Size() < files[j].Size()
|
||||
}
|
||||
return false
|
||||
}
|
||||
return files[i].Size() < files[j].Size()
|
||||
} else if config.DirectorySort == "Time" {
|
||||
if files[i].IsDir() {
|
||||
if files[j].IsDir() {
|
||||
return files[i].ModTime().Before(files[j].ModTime())
|
||||
}
|
||||
return true
|
||||
}
|
||||
if files[j].IsDir() {
|
||||
if files[i].IsDir() {
|
||||
return files[i].ModTime().Before(files[j].ModTime())
|
||||
}
|
||||
return false
|
||||
}
|
||||
return files[i].ModTime().Before(files[j].ModTime())
|
||||
}
|
||||
return false // Should not happen
|
||||
|
|
Loading…
Reference in New Issue