2022-08-31 23:25:17 +02:00
|
|
|
use std::sync::Arc;
|
2022-08-31 23:20:59 +02:00
|
|
|
use tracing::log::*;
|
|
|
|
|
2022-08-31 23:25:17 +02:00
|
|
|
use axum::{
|
|
|
|
response::{Html, IntoResponse, Response},
|
|
|
|
Extension,
|
|
|
|
};
|
2022-08-31 23:20:59 +02:00
|
|
|
|
|
|
|
use crate::State;
|
|
|
|
|
2022-09-05 00:02:58 +02:00
|
|
|
pub mod posts;
|
|
|
|
|
2022-08-31 23:20:59 +02:00
|
|
|
pub enum Error {
|
|
|
|
NotFound,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub type Result<T = Html<Vec<u8>>> = std::result::Result<T, Error>;
|
|
|
|
|
|
|
|
pub async fn index(Extension(state): Extension<Arc<State>>) -> Result {
|
|
|
|
let ctx = tera::Context::new();
|
2022-08-31 23:25:17 +02:00
|
|
|
let res = state.tera.render("index.html", &ctx).map_err(|e| {
|
|
|
|
error!("Failed rendering index: {}", e);
|
|
|
|
Error::NotFound
|
|
|
|
})?;
|
2022-08-31 23:20:59 +02:00
|
|
|
Ok(Html(res.into()))
|
|
|
|
}
|
|
|
|
|
|
|
|
impl IntoResponse for Error {
|
|
|
|
fn into_response(self) -> Response {
|
|
|
|
let result: Vec<u8> = "not found".into();
|
|
|
|
let body = axum::body::boxed(axum::body::Full::from(result));
|
|
|
|
match self {
|
2022-08-31 23:25:17 +02:00
|
|
|
Error::NotFound => Response::builder().status(404).body(body).unwrap(),
|
2022-08-31 23:20:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|