use actix_web::{get, HttpRequest, HttpResponse, Responder}; use maud::html; #[get("/post")] pub async fn post_page(r: HttpRequest) -> impl Responder { // Check if the request is an htmx request if web_base::htmx::is_htmx_request(&r) { return HttpResponse::Ok() .message_body( html! { p { "Short Summary"; a href="/post" { " [MORE]" }; }; } .into_string(), ) .unwrap(); } else { return web_base::func::build_site( &r, "Post", &html! { h1 { "Article" }; p {"Short Summary" }; p { b { "More Info"};}; } .into_string(), ); } } #[get("/")] pub(crate) async fn index(r: HttpRequest) -> impl Responder { let content = html!( p hx-swap="outerHTML" hx-trigger="load delay:1s" hx-get="/post" { "Loading..." }; ) .into_string(); web_base::func::build_site(&r, "Index", &content) } #[actix_web::main] async fn main() -> std::io::Result<()> { web_base::map!( web_base::Site::new() .enable_bootstrap(false) .enable_picocss(false) // HTMX .enable_htmx(true), |app: actix_web::App<_>| { app.service(index).service(post_page) } ) .bind(("0.0.0.0".to_string(), 8080))? .run() .await }