aboutsummaryrefslogtreecommitdiffstats
path: root/src/listing.rs
diff options
context:
space:
mode:
authorLukas Stabe <lukas@stabe.de>2020-08-21 00:41:41 +0000
committerLukas Stabe <lukas@stabe.de>2020-08-21 00:41:41 +0000
commitcdc10d5e234df74de01fb3fa6f30a507d7199408 (patch)
tree9b2d20e899a4e134f1355cc4945b53e158398f24 /src/listing.rs
parenturl-decode path in title and heading (diff)
downloadminiserve-cdc10d5e234df74de01fb3fa6f30a507d7199408.tar.gz
miniserve-cdc10d5e234df74de01fb3fa6f30a507d7199408.zip
make name ordering case-insensitive
Diffstat (limited to 'src/listing.rs')
-rw-r--r--src/listing.rs42
1 files changed, 19 insertions, 23 deletions
diff --git a/src/listing.rs b/src/listing.rs
index 6970c36..b58d765 100644
--- a/src/listing.rs
+++ b/src/listing.rs
@@ -249,29 +249,25 @@ pub fn directory_listing(
}
}
- if let Some(sorting_method) = query_params.sort {
- match sorting_method {
- SortingMethod::Name => entries
- .sort_by(|e1, e2| alphanumeric_sort::compare_str(e1.name.clone(), e2.name.clone())),
- SortingMethod::Size => entries.sort_by(|e1, e2| {
- // If we can't get the size of the entry (directory for instance)
- // let's consider it's 0b
- e2.size
- .unwrap_or_else(|| ByteSize::b(0))
- .cmp(&e1.size.unwrap_or_else(|| ByteSize::b(0)))
- }),
- SortingMethod::Date => entries.sort_by(|e1, e2| {
- // If, for some reason, we can't get the last modification date of an entry
- // let's consider it was modified on UNIX_EPOCH (01/01/19270 00:00:00)
- e2.last_modification_date
- .unwrap_or(SystemTime::UNIX_EPOCH)
- .cmp(&e1.last_modification_date.unwrap_or(SystemTime::UNIX_EPOCH))
- }),
- };
- } else {
- // Sort in alphanumeric order by default
- entries.sort_by(|e1, e2| alphanumeric_sort::compare_str(e1.name.clone(), e2.name.clone()))
- }
+ match query_params.sort.unwrap_or(SortingMethod::Name) {
+ SortingMethod::Name => entries.sort_by(|e1, e2| {
+ alphanumeric_sort::compare_str(e1.name.to_lowercase(), e2.name.to_lowercase())
+ }),
+ SortingMethod::Size => entries.sort_by(|e1, e2| {
+ // If we can't get the size of the entry (directory for instance)
+ // let's consider it's 0b
+ e2.size
+ .unwrap_or_else(|| ByteSize::b(0))
+ .cmp(&e1.size.unwrap_or_else(|| ByteSize::b(0)))
+ }),
+ SortingMethod::Date => entries.sort_by(|e1, e2| {
+ // If, for some reason, we can't get the last modification date of an entry
+ // let's consider it was modified on UNIX_EPOCH (01/01/19270 00:00:00)
+ e2.last_modification_date
+ .unwrap_or(SystemTime::UNIX_EPOCH)
+ .cmp(&e1.last_modification_date.unwrap_or(SystemTime::UNIX_EPOCH))
+ }),
+ };
if let Some(sorting_order) = query_params.order {
if let SortingOrder::Descending = sorting_order {