aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/listing.rs15
-rw-r--r--src/renderer.rs64
2 files changed, 66 insertions, 13 deletions
diff --git a/src/listing.rs b/src/listing.rs
index ee9c581..4a69108 100644
--- a/src/listing.rs
+++ b/src/listing.rs
@@ -138,7 +138,6 @@ pub fn directory_listing<S>(
let base = Path::new(serve_path);
let random_route = format!("/{}", random_route.unwrap_or_default());
let is_root = base.parent().is_none() || req.path() == random_route;
- let page_parent = base.parent().map(|p| p.display().to_string());
let current_dir = match base.strip_prefix(random_route) {
Ok(c_d) => Path::new("/").join(c_d),
Err(_) => base.to_path_buf(),
@@ -285,6 +284,19 @@ pub fn directory_listing<S>(
.chunked()
.body(Body::Streaming(Box::new(rx))))
} else {
+ // Redirect to directory
+ if !renderer::has_trailing(&serve_path) {
+ let query = match req.query_string() {
+ "" => String::new(),
+ _ => format!("?{}", req.query_string())
+ };
+ return Ok(
+ HttpResponse::MovedPermanenty()
+ .header("Location", format!("{}/{}", serve_path, query))
+ .body("301")
+ );
+ }
+
Ok(HttpResponse::Ok()
.content_type("text/html; charset=utf-8")
.body(
@@ -292,7 +304,6 @@ pub fn directory_listing<S>(
serve_path,
entries,
is_root,
- page_parent,
query_params.sort,
query_params.order,
default_color_scheme,
diff --git a/src/renderer.rs b/src/renderer.rs
index d1e16ea..af8f5d7 100644
--- a/src/renderer.rs
+++ b/src/renderer.rs
@@ -15,7 +15,6 @@ pub fn page(
serve_path: &str,
entries: Vec<Entry>,
is_root: bool,
- page_parent: Option<String>,
sort_method: Option<SortingMethod>,
sort_order: Option<SortingOrder>,
default_color_scheme: ColorScheme,
@@ -73,13 +72,11 @@ pub fn page(
}
tbody {
@if !is_root {
- @if let Some(parent) = page_parent {
- tr {
- td colspan="3" {
- span.root-chevron { (chevron_left()) }
- a.root href=(parametrized_link(&parent, sort_method, sort_order, color_scheme, default_color_scheme)) {
- "Parent directory"
- }
+ tr {
+ td colspan="3" {
+ span.root-chevron { (chevron_left()) }
+ a.root href=(parametrized_link("../", sort_method, sort_order, color_scheme, default_color_scheme)) {
+ "Parent directory"
}
}
}
@@ -218,6 +215,23 @@ fn archive_button(
}
}
+// Is there a trailing "/"
+pub fn has_trailing(s: &str) -> bool {
+ match s.chars().last() {
+ Some(d) => d == '/',
+ None => false
+ }
+}
+
+// Add trailing "/" if conditions permit
+fn add_trailing(link: &str) -> String {
+ if has_trailing(&link) {
+ link.to_string()
+ }else {
+ format!("{}/", link)
+ }
+}
+
/// If they are set, adds query parameters to links to keep them across pages
fn parametrized_link(
link: &str,
@@ -228,7 +242,12 @@ fn parametrized_link(
) -> String {
if let Some(method) = sort_method {
if let Some(order) = sort_order {
- let parametrized_link = format!("{}?sort={}&order={}", link, method, order);
+ let parametrized_link = format!(
+ "{}?sort={}&order={}",
+ add_trailing(&link),
+ method,
+ order
+ );
if color_scheme != default_color_scheme {
return format!("{}&theme={}", parametrized_link, color_scheme.to_slug());
@@ -239,10 +258,14 @@ fn parametrized_link(
}
if color_scheme != default_color_scheme {
- return format!("{}?theme={}", link.to_string(), color_scheme.to_slug());
+ return format!(
+ "{}?theme={}",
+ add_trailing(&link),
+ color_scheme.to_slug()
+ );
}
- link.to_string()
+ add_trailing(&link)
}
/// Partial: table header link
@@ -672,6 +695,25 @@ fn css(color_scheme: ColorScheme) -> Markup {
.mobile-info {{
display: block;
}}
+ table tbody tr td {{
+ padding-top: 0;
+ padding-bottom: 0;
+ }}
+ a.directory {{
+ display: block;
+ padding: 0.5625rem 0;
+ }}
+ .file-entry {{
+ align-items: center;
+ }}
+ a.root, a.file, a.symlink {{
+ display: inline-block;
+ flex: 1;
+ padding: 0.5625rem 0;
+ }}
+ a.symlink {{
+ width: 100%;
+ }}
.back {{
display: flex;
}}