💄 Make directory indexes prettier

main
_ 2020-10-31 15:28:27 +00:00
parent 1fb0c2aafa
commit 0572de2ad0
3 changed files with 85 additions and 8 deletions

View File

@ -1,10 +1,39 @@
<ul>
<li><a href="https://example.com">..</a></li>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
body {
font-family: sans;
}
.entry {
display: inline-block;
padding: 10px;
min-width: 50%;
}
.entry_list div:nth-child(odd) {
background-color: #ddd;
}
</style>
<title>{{path}}</title>
</head>
<body>
<div class="entry_list">
<div>
<a class="entry" href="https://example.com">../</a>
</div>
{{#each entries}}
<li>
<a href="{{this.encoded_file_name}}{{this.trailing_slash}}">
<div>
<a class="entry" href="{{this.encoded_file_name}}{{this.trailing_slash}}">
{{this.file_name}}{{this.trailing_slash}}
</a>
</li>
</div>
{{/each}}
</ul>
</div>
</body>
</html>

View File

@ -0,0 +1,43 @@
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
body {
font-family: sans;
}
.entry {
display: inline-block;
padding: 20px;
min-width: 50%;
}
.entry_list div:nth-child(odd) {
background-color: #ddd;
}
</style>
<title>/home/user/stuff</title>
</head>
<body>
<div class="entry_list">
<div>
<a class="entry" href="https://example.com">../</a>
</div>
<div>
<a class="entry" href="some_dir/">some_dir/</a>
</div>
<div>
<a class="entry" href="alice">alice</a>
</div>
<div>
<a class="entry" href="alice">alice</a>
</div>
</div>
</body>
</html>

View File

@ -95,8 +95,11 @@ async fn read_dir_entry (entry: DirEntry) -> TemplateDirEntry
}
}
use std::borrow::Cow;
async fn serve_dir (
handlebars: Arc <Handlebars <'static>>,
path: Cow <'_, str>,
mut dir: ReadDir
) -> http_serde::Response
{
@ -107,11 +110,13 @@ async fn serve_dir (
}
#[derive (Serialize)]
struct TemplateDirPage {
struct TemplateDirPage <'a> {
path: Cow <'a, str>,
entries: Vec <TemplateDirEntry>,
}
let s = handlebars.render ("file_server_dir", &TemplateDirPage {
path,
entries,
}).unwrap ();
@ -258,7 +263,7 @@ pub async fn serve_all (
full_path.push (&*path);
if let Ok (dir) = read_dir (&full_path).await {
serve_dir (handlebars, dir).await
serve_dir (handlebars, full_path.to_string_lossy (), dir).await
}
else if let Ok (file) = File::open (&full_path).await {
serve_file (