index : static-web-server.git

ascending towards madness

author Jose Quintana <joseluisquintana20@gmail.com> 2023-06-27 22:40:15.0 +00:00:00
committer Jose Quintana <joseluisquintana20@gmail.com> 2023-06-27 22:40:15.0 +00:00:00
commit
b2e4e49a35bce46d4229b967e987be7d1a4bd801 [patch]
tree
ed04ab9f49ab0553ae58726891a6b9a58bebbac0
parent
1bce2044197eb3cc6759e19e474b6558cee4e0a6
download
b2e4e49a35bce46d4229b967e987be7d1a4bd801.tar.gz

refactor: improve directory listing styling for html display



Diff

 src/directory_listing.rs | 14 +++++---------
 tests/toml/config.toml   |  2 +-
 2 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/src/directory_listing.rs b/src/directory_listing.rs
index 4ef1f40..d5b9723 100644
--- a/src/directory_listing.rs
+++ b/src/directory_listing.rs
@@ -118,8 +118,9 @@ pub fn auto_index(
    })
}

const STYLE: &str = r#"<style>html{background-color:#fff;-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;min-width:20rem;text-rendering:optimizeLegibility;-webkit-text-size-adjust:100%;-moz-text-size-adjust:100%;text-size-adjust:100%}body{padding:1rem;font-family:Consolas,'Liberation Mono',Menlo,monospace;font-size:.875rem;max-width:70rem;margin:0 auto;color:#4a4a4a;font-weight:400;line-height:1.5}h1{margin:0;padding:0;font-size:1.375rem;line-height:1.25;margin-bottom:0.5rem;}table{width:100%;border-spacing: 0;}table th,table td{padding:.2rem .5rem;white-space:nowrap;vertical-align:top}table th a,table td a{display:inline-block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:95%;vertical-align:top}table tr:hover td{background-color:#f5f5f5}footer{padding-top:0.5rem}table tr th{text-align:left;}</style>"#;
const FOOTER: &str = r#"<footer>Powered by <a target="_blank" href="https://static-web-server.net">Static Web Server</a> | MIT &amp; Apache 2.0</footer>"#;
const STYLE: &str = r#"<style>html{background-color:#fff;-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;min-width:20rem;text-rendering:optimizeLegibility;-webkit-text-size-adjust:100%;-moz-text-size-adjust:100%;text-size-adjust:100%}body{padding:1rem;font-family:Consolas,'Liberation Mono',Menlo,monospace;font-size:.75rem;max-width:70rem;margin:0 auto;color:#4a4a4a;font-weight:400;line-height:1.5}h1{margin:0;padding:0;font-size:1.375rem;line-height:1.25;margin-bottom:0.5rem;}table{width:100%;border-spacing: 0;}table th,table td{padding:.15rem 0;white-space:nowrap;vertical-align:top}table th a,table td a{display:inline-block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:95%;vertical-align:top;}table tr:hover td{background-color:#f5f5f5}footer{padding-top:0.5rem}table tr th{text-align:left;}</style>"#;
const FOOTER: &str =
    r#"<footer><em>Powered by Static Web Server (SWS) / static-web-server.net</em></footer>"#;

const DATETIME_FORMAT_UTC: &str = "%FT%TZ";
const DATETIME_FORMAT_LOCAL: &str = "%F %T";
@@ -458,14 +459,9 @@ fn html_auto_index<'a>(
    }

    let current_path = percent_decode_str(base_path).decode_utf8()?.to_string();
    let dirs_str = if dirs_count == 1 {
        "directory"
    } else {
        "directories"
    };
    let summary = format!(
        "<div>{} {}, {} {}</div>",
        dirs_count, dirs_str, files_count, "file(s)"
        "<div>directories: {}, files: {}</div>",
        dirs_count, files_count,
    );

    let html_page = format!(
diff --git a/tests/toml/config.toml b/tests/toml/config.toml
index 1043890..f551404 100644
--- a/tests/toml/config.toml
+++ b/tests/toml/config.toml
@@ -38,7 +38,7 @@ directory-listing = true
directory-listing-order = 1

#### Directory listing content format
directory-listing-format = "json"
directory-listing-format = "html"

#### Basic Authentication
basic-auth = ""