awesome pawsome

This commit is contained in:
2026-01-13 20:28:42 +00:00
parent cced229c5e
commit 32b0b62fef
8 changed files with 72 additions and 19 deletions

View File

@@ -20,7 +20,7 @@ mod loader;
use crate::loader::*;
struct AppState<'a> {
pages: Vec<Page>,
pub pages: Vec<Page>,
env: Environment<'a>,
}
@@ -28,18 +28,29 @@ struct AppState<'a> {
async fn serve(req: Request<Incoming>, state: Arc<AppState<'_>>) -> Result<Response<Full<Bytes>>> {
println!("Serving {}", req.uri());
let tmpl = state.env.get_template("hello").unwrap();
let guh = tmpl.render(context!(name => "meowmeowmeowmeow!")).unwrap();
let guh2 = state.env.get_template("meow").unwrap();
let guh3 = guh2.render(context!(meow => "meow")).unwrap();
let path = req.uri().path();
let reply: Bytes = match path {
"/" => guh.into(),
"/mreow" => guh3.into(),
_ => "Invalid path!".into(),
let mreow = state.pages.iter().find(|&x| {
if let Some(path_x) = &x.header.path {
println!("{},{}", path_x, path);
if path_x == path {
true
} else {
false
}
} else {
false
}
});
let reply = match mreow {
Some(x) => state
.env
.get_template(&x.header.id)
.unwrap()
.render(context! {})
.unwrap(),
None => "?".to_string(),
};
Ok(Response::new(Full::new(reply)))
Ok(Response::new(Full::new(reply.into())))
}
async fn handle_client(client: Async<TcpStream>, state: Arc<AppState<'_>>) -> Result<()> {