use askama::Template; use axum::http::StatusCode; use axum::response::{Html, IntoResponse, Response}; pub mod admin; pub mod day; pub mod error; pub mod home; pub mod leaderboard; pub mod login; pub struct HtmlTemplate(pub T); /// Allows us to convert Askama HTML templates into valid HTML /// for axum to serve in the response. impl IntoResponse for HtmlTemplate where T: Template, { fn into_response(self) -> Response { // Attempt to render the template with askama match self.0.render() { // If we're able to successfully parse and aggregate the template, serve it Ok(html) => Html(html).into_response(), // If we're not, return an error or some bit of fallback HTML Err(err) => { log::error!("Failed to render template: {}", err); IntoResponse::into_response(( StatusCode::INTERNAL_SERVER_ERROR, "Failed to render the HTML Template", )) } } } }