forked from solderpunk/molly-brown
Merge pull request 'Sort directory listings with directories before files' (#1) from sort-dirs-first into master
Reviewed-on: #1
This commit is contained in:
commit
f8141952f2
36
dirlist.go
36
dirlist.go
|
@ -42,10 +42,46 @@ func generateDirectoryListing(URL *url.URL, path string, config Config) (string,
|
||||||
i, j = j, i
|
i, j = j, i
|
||||||
}
|
}
|
||||||
if config.DirectorySort == "Name" {
|
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()
|
return files[i].Name() < files[j].Name()
|
||||||
} else if config.DirectorySort == "Size" {
|
} 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()
|
return files[i].Size() < files[j].Size()
|
||||||
} else if config.DirectorySort == "Time" {
|
} 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 files[i].ModTime().Before(files[j].ModTime())
|
||||||
}
|
}
|
||||||
return false // Should not happen
|
return false // Should not happen
|
||||||
|
|
Loading…
Reference in New Issue