Directory index generation works
This commit is contained in:
parent
dacfd479e9
commit
96189b04ad
2 changed files with 29 additions and 1 deletions
|
@ -47,4 +47,4 @@ Whatever is on here, just to make it extra spicy.
|
||||||
|
|
||||||
[ ] Compressing big files
|
[ ] Compressing big files
|
||||||
|
|
||||||
[ ] Directory index generation
|
[x] Directory index generation
|
||||||
|
|
28
src/main.rs
28
src/main.rs
|
@ -24,11 +24,39 @@ fn check_if_dir(directory: String) -> bool {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn generate_index(directory: String) -> String {
|
||||||
|
|
||||||
|
let mut index = format!("<!DOCTYPE HTML><html><body><h1>Directory of {}</h1>", directory);
|
||||||
|
for file in fs::read_dir(directory).unwrap() {
|
||||||
|
|
||||||
|
index = format!("{}<br/><a href={}>{:#?}</a>", index, file.as_ref().unwrap().path().display(), file.unwrap().file_name());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return index.to_string();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
fn get_page(filename: String) -> String {
|
fn get_page(filename: String) -> String {
|
||||||
|
|
||||||
// The loaded page should be left immutable as it does
|
// The loaded page should be left immutable as it does
|
||||||
// not need to be modified by the server.
|
// not need to be modified by the server.
|
||||||
|
|
||||||
|
let path = filename.to_string();
|
||||||
|
let checks = check_if_path_exists(path);
|
||||||
|
let path = filename.to_string();
|
||||||
|
let index = check_if_dir(path);
|
||||||
|
let path = filename.to_string();
|
||||||
|
|
||||||
|
println!("{} {} {}", path, checks, index);
|
||||||
|
|
||||||
|
if checks == true && index == false {
|
||||||
|
if path.contains(".") != true {
|
||||||
|
let result = generate_index(filename);
|
||||||
|
return result.to_string();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if filename == ".error_server_404" {
|
if filename == ".error_server_404" {
|
||||||
let result = "<!DOCTYPE HTML><html><body><h1>404 Not Found</h1><p>The resource you are trying to locate cannot be accessed!</p></body></html>";
|
let result = "<!DOCTYPE HTML><html><body><h1>404 Not Found</h1><p>The resource you are trying to locate cannot be accessed!</p></body></html>";
|
||||||
return result.to_string();
|
return result.to_string();
|
||||||
|
|
Loading…
Reference in a new issue