diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/listing.rs | 42 |
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 { |