diff --git a/axum_server/Cargo.toml b/axum_server/Cargo.toml index c1d0d56..6280dab 100644 --- a/axum_server/Cargo.toml +++ b/axum_server/Cargo.toml @@ -6,6 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +askama = { version = "0.12", features = ["with-axum", "mime", "mime_guess"] } +askama_axum = "0.4.0" axum = "0.7.3" chrono = { version = "0.4.31", features = ["serde"] } gray_matter = "0.2.6" diff --git a/axum_server/askama.toml b/axum_server/askama.toml new file mode 100644 index 0000000..70e25ae --- /dev/null +++ b/axum_server/askama.toml @@ -0,0 +1,6 @@ +[general] +# Directories to search for templates, relative to the crate root. +dirs = ["templates"] +# Unless you add a `-` in a block, whitespace characters won't be trimmed. +whitespace = "preserve" + diff --git a/axum_server/src/main.rs b/axum_server/src/main.rs index 127747a..e01d7fd 100644 --- a/axum_server/src/main.rs +++ b/axum_server/src/main.rs @@ -1,8 +1,10 @@ use axum; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; +mod pages; mod post_parser; mod router; +// mod template; #[tokio::main] async fn main() { diff --git a/axum_server/src/pages/index.rs b/axum_server/src/pages/index.rs new file mode 100644 index 0000000..fccf926 --- /dev/null +++ b/axum_server/src/pages/index.rs @@ -0,0 +1,9 @@ +use askama::Template; + +#[derive(Template)] +#[template(path = "index.html")] +pub struct IndexTemplate {} + +pub async fn render_index() -> IndexTemplate { + IndexTemplate {} +} diff --git a/axum_server/src/pages/mod.rs b/axum_server/src/pages/mod.rs new file mode 100644 index 0000000..33edc95 --- /dev/null +++ b/axum_server/src/pages/mod.rs @@ -0,0 +1 @@ +pub mod index; diff --git a/axum_server/src/router.rs b/axum_server/src/router.rs index f6b16ee..bfbb2f2 100644 --- a/axum_server/src/router.rs +++ b/axum_server/src/router.rs @@ -1,11 +1,11 @@ -use crate::post_parser::parse_post; +use crate::{pages::index::render_index, post_parser::parse_post}; use axum::{extract::MatchedPath, http::Request, routing::get, Router}; use tower_http::trace::TraceLayer; use tracing::info_span; pub fn get_router() -> Router { Router::new() - .route("/", get(|| async { "Hello, World!" })) + .route("/", get(render_index)) .route("/blog/:post_id", get(parse_post)) .layer( TraceLayer::new_for_http().make_span_with(|request: &Request<_>| { diff --git a/axum_server/src/template.rs b/axum_server/src/template.rs new file mode 100644 index 0000000..a92da2d --- /dev/null +++ b/axum_server/src/template.rs @@ -0,0 +1,9 @@ +pub use askama::*; +use axum::http::Response; + +pub fn into_response(t: &T) -> Response { + match t.render() { + Ok(body) => Html(body), + Err(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(), + } +} diff --git a/axum_server/templates/base.html b/axum_server/templates/base.html new file mode 100644 index 0000000..aeb584e --- /dev/null +++ b/axum_server/templates/base.html @@ -0,0 +1,36 @@ + + + + {% block title %} {{title}} @michalvankodev {% endblock %} + + + + + + + + + + + + + + + + + + + + {% block content %} Placeholder {% endblock %} + + diff --git a/axum_server/templates/index.html b/axum_server/templates/index.html new file mode 100644 index 0000000..d0421ef --- /dev/null +++ b/axum_server/templates/index.html @@ -0,0 +1,56 @@ +{% extends "base.html" %} + +{% block title %}Introduction{% endblock %} + +{% block content %} +
+
+ + Portrait + +
+ +

+ “Let your ambition carry you.” + - La Flame +

+
+ +

+ Hey, welcome to my personal website. My name is + Michal Vanko + and I'm a + programmer + . I'll try to share some stories and opinions about things that I'm interested + in. +

+ +
+

Follow my twitch stream

+
+
+