aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/args.rs20
-rw-r--r--src/config.rs27
-rw-r--r--src/listing.rs12
-rw-r--r--src/renderer.rs4
4 files changed, 59 insertions, 4 deletions
diff --git a/src/args.rs b/src/args.rs
index c5c268f..e400c8a 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -113,6 +113,26 @@ pub struct CliArgs {
#[arg(short = 'H', long = "hidden", env = "MINISERVE_HIDDEN")]
pub hidden: bool,
+ /// Default sorting method for file list
+ #[arg(
+ short = 'S',
+ long = "default-sorting-method",
+ default_value = "",
+ ignore_case = true,
+ env = "MINISERVE_DEFAULT_SORTING_METHOD"
+ )]
+ pub default_sorting_method: String,
+
+ /// Default sorting order for file list
+ #[arg(
+ short = 'O',
+ long = "default-sorting-order",
+ default_value = "",
+ ignore_case = true,
+ env = "MINISERVE_DEFAULT_SORTING_ORDER"
+ )]
+ pub default_sorting_order: String,
+
/// Default color scheme
#[arg(
short = 'c',
diff --git a/src/config.rs b/src/config.rs
index 1ef9eca..491ac40 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -15,6 +15,7 @@ use crate::{
args::{parse_auth, CliArgs, MediaType},
auth::RequiredAuth,
file_utils::sanitize_path,
+ listing::{SortingMethod, SortingOrder},
renderer::ThemeSlug,
};
@@ -50,6 +51,12 @@ pub struct MiniserveConfig {
/// Show hidden files
pub show_hidden: bool,
+ /// Default sorting method
+ pub default_sorting_method: Option<SortingMethod>,
+
+ /// Default sorting order
+ pub default_sorting_order: Option<SortingOrder>,
+
/// Route prefix; Either empty or prefixed with slash
pub route_prefix: String,
@@ -265,6 +272,24 @@ impl MiniserveConfig {
.transpose()?
.unwrap_or_default();
+ let default_sorting_method: Option<SortingMethod> = match args
+ .default_sorting_method
+ .to_owned()
+ .parse::<SortingMethod>()
+ {
+ Ok(value) => Some(value),
+ Err(_) => None,
+ };
+
+ let default_sorting_order: Option<SortingOrder> = match args
+ .default_sorting_order
+ .to_owned()
+ .parse::<SortingOrder>()
+ {
+ Ok(value) => Some(value),
+ Err(_) => None,
+ };
+
Ok(MiniserveConfig {
verbose: args.verbose,
path: args.path.unwrap_or_else(|| PathBuf::from(".")),
@@ -274,6 +299,8 @@ impl MiniserveConfig {
path_explicitly_chosen,
no_symlinks: args.no_symlinks,
show_hidden: args.hidden,
+ default_sorting_method,
+ default_sorting_order,
route_prefix,
favicon_route,
css_route,
diff --git a/src/listing.rs b/src/listing.rs
index 6e75b0e..40c5a77 100644
--- a/src/listing.rs
+++ b/src/listing.rs
@@ -223,7 +223,7 @@ pub fn directory_listing(
res
};
- let query_params = extract_query_parameters(req);
+ let mut query_params = extract_query_parameters(req);
let mut entries: Vec<Entry> = Vec::new();
let mut readme: Option<(String, String)> = None;
@@ -299,6 +299,14 @@ pub fn directory_listing(
}
}
+ if query_params.sort.is_none() {
+ query_params.sort = conf.default_sorting_method
+ }
+
+ if query_params.order.is_none() {
+ query_params.order = conf.default_sorting_order
+ }
+
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())
@@ -319,7 +327,7 @@ pub fn directory_listing(
}),
};
- if let Some(SortingOrder::Descending) = query_params.order {
+ if let Some(SortingOrder::Ascending) = query_params.order {
entries.reverse()
}
diff --git a/src/renderer.rs b/src/renderer.rs
index 5a591f0..3b62704 100644
--- a/src/renderer.rs
+++ b/src/renderer.rs
@@ -459,7 +459,7 @@ fn build_link(
) -> Markup {
let mut link = format!("?sort={name}&order=asc");
let mut help = format!("Sort by {name} in ascending order");
- let mut chevron = chevron_up();
+ let mut chevron = chevron_down();
let mut class = "";
if let Some(method) = sort_method {
@@ -469,7 +469,7 @@ fn build_link(
if order.to_string() == "asc" {
link = format!("?sort={name}&order=desc");
help = format!("Sort by {name} in descending order");
- chevron = chevron_down();
+ chevron = chevron_up();
}
}
}