umbrella/src/main.rs
2024-09-18 11:15:30 +02:00

35 lines
768 B
Rust

use std::path::Path;
use config::Config;
use rocket::fs::NamedFile;
use rocket::response::content::RawHtml;
use rocket::{get, launch, routes, State};
mod config;
mod site;
#[get("/static/<file>")]
async fn icon_res(file: &str) -> Option<NamedFile> {
let path = Path::new("static").join(file);
NamedFile::open(path).await.ok()
}
#[get("/")]
pub fn main_page(c: &State<Config>) -> RawHtml<String> {
RawHtml(site::gen_site(c))
}
// todo : fav icon
#[launch]
async fn rocket() -> _ {
let conf_path: String = std::env::args()
.skip(1)
.next()
.unwrap_or("./config.yml".to_string());
let conf = config::Config::load(&conf_path);
rocket::build()
.mount("/", routes![main_page, icon_res])
.manage(conf)
}