//! Askama template definitions for all HTML pages and fragments. //! //! Split by domain: //! - `public`: forum directory, project, category, thread pages mod public; pub use public::*; use askama::Template; use axum::response::{Html, IntoResponse, Response}; /// CSRF token passed to templates; None when no session store is configured. pub type CsrfTokenOption = Option; /// Convert any Askama template into an Axum response. fn render_template(template: T) -> Response { match template.render() { Ok(html) => Html(html).into_response(), Err(err) => { tracing::error!(error = ?err, "template rendering error"); // Static branded page, not the Error500 *template*: the engine that // just failed can't be trusted to render the fallback. crate::error_page::internal_error_static() } } } /// Implement `IntoResponse` for one or more Askama template structs. macro_rules! impl_into_response { ($($T:ty),+ $(,)?) => { $( impl IntoResponse for $T { fn into_response(self) -> Response { render_template(self) } } )+ }; } impl_into_response!( AccountSettingsTemplate, AdminCommunityTemplate, ForumDirectoryTemplate, CommunityTemplate, CategoryTemplate, ThreadTemplate, NewThreadTemplate, EditThreadTemplate, CommunitySettingsTemplate, EditCategoryTemplate, MembersTemplate, UserProfileTemplate, ModerationTemplate, ModLogTemplate, ChatTemplate, DeletedThreadsTemplate, AdminDashboardTemplate, TrackedThreadsTemplate, TrackingInfoTemplate, SearchResultsFragment, Error404Template, Error500Template, );