From 856482ce1781b8dd825bfabae0b21df76fc7f593 Mon Sep 17 00:00:00 2001 From: Matthew Gordon Date: Sat, 10 Feb 2024 13:16:37 -0400 Subject: [PATCH] Stub in Axum templating --- Cargo.toml | 4 +++- src/main.rs | 11 +++++++++-- templates/index.html | 11 +++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 templates/index.html diff --git a/Cargo.toml b/Cargo.toml index 93fac06..70fde55 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,4 +7,6 @@ edition = "2021" [dependencies] tokio = { version = "1", features = ["rt-multi-thread"]} -axum = "0.7" \ No newline at end of file +axum = "0.7" +askama = "0.12" +askama_axum = "0.4" diff --git a/src/main.rs b/src/main.rs index ee84d16..3d5f385 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use askama::Template; use axum::{routing::get, Router}; #[tokio::main] @@ -9,6 +10,12 @@ async fn main() -> Result<(), Box> { Ok(()) } -async fn root() -> &'static str { - "It works!" +#[derive(Template)] +#[template(path = "index.html")] +struct IndexTemplate<'a> { + title: &'a str, +} + +async fn root<'a>() -> IndexTemplate<'a> { + IndexTemplate { title: "LocalHub" } } diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..d925a10 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,11 @@ + + + + + + {{title}} + + + It still works! + +