#![allow(missing_docs)] use std::{ collections::HashMap, net::{Ipv4Addr, SocketAddr}, }; use axum::{extract::Query, routing::get, Router, Server}; use html_node::{html, text, Node}; use html_node_core::pretty::Pretty; #[tokio::main] async fn main() { let addr = SocketAddr::from((Ipv4Addr::LOCALHOST, 3000)); println!("listening on {addr}..."); Server::bind(&addr) .serve(router().into_make_service()) .await .unwrap(); } fn router() -> Router { Router::new() .route("/", get(home)) .route("/about", get(about)) .route("/contact", get(contact)) .route("/greet", get(greet)) .route("/pretty", get(pretty)) } fn layout(content: Node) -> Node { const NAV_PAGES: &[(&str, &str)] = &[("/", "home"), ("/about", "about"), ("/contact", "contact")]; html! { "my website"
{content}
} } async fn home() -> Node { layout(html! {

"home"

"welcome to my site!"

"use the form to get a personalized greeting!"

}) } async fn about() -> Node { layout(html! {

"about"

"my name is vidhan, and i'm a rust developer and a university student." }) } async fn contact() -> Node { layout(html! {

"contact"

}) } async fn greet(Query(params): Query>) -> Node { let name = params .get("name") .map_or("stranger", std::string::String::as_str); layout(html! {

{text!("hello, {name}")}!

}) } async fn pretty() -> Pretty { Pretty(layout(html! {

Pretty

})) }