bobashare_web/views/
about.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use askama::Template;
use axum::{extract::State, response::IntoResponse};
use hyper::StatusCode;
use tracing::instrument;

use super::{
    filters, render_template, CurrentNavigation, ErrorResponse, ErrorTemplate, TemplateState,
};
use crate::AppState;

#[derive(Template)]
#[template(path = "about.html.jinja")]
pub struct AboutTemplate<'s, 'c> {
    pub state: TemplateState<'s>,
    pub about_content_rendered: &'c str,
}

/// Display a simple about page
#[instrument(skip(state))]
pub async fn about(
    State(state): State<&'static AppState>,
) -> Result<impl IntoResponse, ErrorResponse> {
    let mut tmpl_state = TemplateState::from(state);

    if state.about_page.is_none() {
        Err(ErrorTemplate {
            state: tmpl_state.clone(),
            code: StatusCode::NOT_FOUND,
            message: "no about page is configured".to_string(),
        })?;
    }

    tmpl_state.current_navigation = Some(CurrentNavigation::About);

    render_template(AboutTemplate {
        state: tmpl_state,
        about_content_rendered: &state.about_page_content,
    })
}