Echo Writes Code

handlers.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
use crate::errors::{ Result };
use crate::state::{ ApplicationState };
use crate::templates;

use axum::extract::{ Path, State };
use axum::http::{ StatusCode };
use axum::response::{ Html, IntoResponse };

use std::sync::{ Arc };

pub(crate) async fn index_handler(State(state): State<Arc<ApplicationState>>) -> Result<Html<String>> {
	let context = templates::index_context(&state)?;
	let html = state.tera.render("markdown_page.tera.html", &context)?;
	Ok(Html(html))
}

pub(crate) async fn page_handler(
	State(state): State<Arc<ApplicationState>>,
	Path(page_path): Path<String>
) -> Result<Html<String>> {
	let context = templates::page_context(&state, &page_path)?;
	let html = state.tera.render("markdown_page.tera.html", &context)?;
	Ok(Html(html))
}

pub(crate) async fn not_found_handler() -> impl IntoResponse {
	(StatusCode::NOT_FOUND, "Not found")
}