aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorboasting-squirrel <boasting.squirrel@gmail.com>2019-02-17 08:18:13 +0000
committerboasting-squirrel <boasting.squirrel@gmail.com>2019-02-17 08:18:13 +0000
commit89ed21ded5d052d54a28e2a08e042f50a9ccd5a0 (patch)
treecefb1d8884acc4352961dcbbf84a06fcede13a47
parentImproved date format (diff)
downloadminiserve-89ed21ded5d052d54a28e2a08e042f50a9ccd5a0.tar.gz
miniserve-89ed21ded5d052d54a28e2a08e042f50a9ccd5a0.zip
Improved design of last-modification column
-rw-r--r--src/listing.rs33
1 files changed, 23 insertions, 10 deletions
diff --git a/src/listing.rs b/src/listing.rs
index 93ae04b..b985b1e 100644
--- a/src/listing.rs
+++ b/src/listing.rs
@@ -190,24 +190,26 @@ pub fn directory_listing<S>(
if reverse_sort {
entries.reverse();
}
-
for entry in entries {
+ let (modification_date, modification_time) = convert_to_utc(entry.last_modification_date);
+
match entry.entry_type {
EntryType::Directory => {
let _ = write!(
body,
- "<tr><td><a class=\"directory\" href=\"{}\">{}/</a></td><td></td><td>{} <span class=\"ago\">({})</span></td></tr>",
- entry.link, entry.name, convert_to_utc(entry.last_modification_date), humanize_duration(entry.last_modification_date)
+ "<tr><td><a class=\"directory\" href=\"{}\">{}/</a></td><td></td><td class=\"date-cell\"><span>{}</span><span>{}</span><span>{}</span></td></tr>",
+ entry.link, entry.name, modification_date, modification_time, humanize_duration(entry.last_modification_date)
);
}
EntryType::File => {
let _ = write!(
body,
- "<tr><td><a class=\"file\" href=\"{}\">{}</a></td><td>{}</td><td>{} <span class=\"ago\">({})</span></td></tr>",
+ "<tr><td><a class=\"file\" href=\"{}\">{}</a></td><td>{}</td><td class=\"date-cell\"><span>{}</span><span>{}</span><span>{}</span></td></tr>",
entry.link,
entry.name,
entry.size.unwrap(),
- convert_to_utc(entry.last_modification_date),
+ modification_date,
+ modification_time,
humanize_duration(entry.last_modification_date)
);
}
@@ -269,8 +271,16 @@ pub fn directory_listing<S>(
a:visited {{\
color: #8e44ad;\
}}\
- .ago {{\
- color: #c5c5c5;\
+ td.date-cell {{\
+ display: flex;\
+ width: calc(100% - 1.25rem);\
+ }}\
+ td.date-cell span:first-of-type,\
+ td.date-cell span:nth-of-type(2) {{\
+ flex-basis:4.5rem;\
+ }}\
+ td.date-cell span:nth-of-type(3) {{\
+ color: #c5c5c5\
}}\
@media (max-width: 600px) {{\
h1 {{\
@@ -297,13 +307,16 @@ pub fn directory_listing<S>(
.body(html))
}
-fn convert_to_utc(src_time: Option<SystemTime>) -> String {
+fn convert_to_utc(src_time: Option<SystemTime>) -> (String, String) {
match src_time {
Some(time) => {
let date_time = DateTime::<Utc>::from(time);
- date_time.format("%e %b&emsp;&emsp;%R").to_string()
+ (
+ date_time.format("%e %b").to_string(),
+ date_time.format("%R").to_string(),
+ )
}
- None => "".to_string(),
+ None => ("".to_string(), "".to_string()),
}
}