added askama, base template and index

This commit is contained in:
2024-01-11 20:43:47 +01:00
parent f071a702af
commit ae1b65957d
9 changed files with 123 additions and 2 deletions

View File

@ -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() {

View File

@ -0,0 +1,9 @@
use askama::Template;
#[derive(Template)]
#[template(path = "index.html")]
pub struct IndexTemplate {}
pub async fn render_index() -> IndexTemplate {
IndexTemplate {}
}

View File

@ -0,0 +1 @@
pub mod index;

View File

@ -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<_>| {

View File

@ -0,0 +1,9 @@
pub use askama::*;
use axum::http::Response;
pub fn into_response<T: Template>(t: &T) -> Response {
match t.render() {
Ok(body) => Html(body),
Err(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
}
}