Set default sorting order and method with arguments#1308
Set default sorting order and method with arguments#1308svenstaro merged 1 commit intosvenstaro:masterfrom ElliottLandsborough:set_sorting_order_with_arguments
Conversation
|
Cool! Could you add a description for what it is supposed to do and why? For example, why aren't the current sorters not sufficient? I suppose the idea is to provide a sorting default? |
I have updated the description - you are right, I want to be able to set the default sort type and order. The chevrons may have been pointing in the wrong direction too so I have included the change. This is not a big deal to me and it is probably open to interpretation. |
|
Code looks perfect. Can I somehow convince you to write a test for this? |
I've added a test, fixed some bugs, updated some comments. |
svenstaro
left a comment
There was a problem hiding this comment.
Looks great, just one comment about the tests.
|
I'm happy to merge this and release a new version of miniserve once the test is a bit more useful. |
Tests have been updated 😃 |
| } | ||
|
|
||
| /// Return the href attributes of all links that start with the specified prefix `text`. | ||
| pub fn get_link_hrefs_from_text_with_prefix(document: &Document, text: &str) -> Vec<String> { |
There was a problem hiding this comment.
| pub fn get_link_hrefs_from_text_with_prefix(document: &Document, text: &str) -> Vec<String> { | |
| pub fn get_link_hrefs_from_text_with_prefix(document: &Document, prefix: &str) -> Vec<String> { |
| Some(a_elem.attr("href")?.to_string()) | ||
| } | ||
|
|
||
| /// Return the href attributes of all links that start with the specified prefix `text`. |
There was a problem hiding this comment.
| /// Return the href attributes of all links that start with the specified prefix `text`. | |
| /// Return the href attributes of all links that start with the specified `prefix`. |
| #[case(server(&["--default-sorting-method", "date", "--default-sorting-order", "asc"]))] | ||
| /// We can specify the default sorting order | ||
| fn can_specify_default_sorting_order(#[case] server: TestServer) -> Result<(), Error> { | ||
| let slash = String::from("/"); |
There was a problem hiding this comment.
I'm not sure how I feel about this since we only really need it at a single place. Maybe just create this where it needs to be and remove this?
|
I'm making the last few bits of changes myself. Thanks for the contribution! |
|
Thanks - that was the fastest i've ever had a PR merged to anyone else's project 👍 |
|
Happy to hear! Check my changes to your code as well. I think I improved it somewhere and it's now pretty neat. |
My intention is to add a way to sort by
descendingdate(or anything else) by default.I think the best way to do this is with a command line argument but I am open to suggestions.
This is useful for anyone who wants the most recently created/edited files at the top of the list when the page first loads.
Without this change, a user would have to do an entire whole extra single click to sort the files by date 😢