blob: c227f22cdc772af299c3e768ee4b813a10012371 (
plain) (
blame)
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
40
|
pub mod post;
pub mod handlers {
use std::sync::Arc;
use color_eyre::eyre::eyre;
use warp::{Reply, Rejection};
use warp::http::Response;
use crate::templates::{self, Html, RenderRucte};
use crate::internal::SiteState;
use super::post::Post;
pub async fn list(state: Arc<SiteState>) -> Result<impl Reply, Rejection> {
let state = state.clone();
Response::builder()
.html(|o| templates::bloglist_html(o, state.blog.clone()))
}
pub async fn post(name: String, state: Arc<SiteState>) -> Result<impl Reply, Rejection> {
let mut want: Option<Post> = None;
for post in &state.blog {
if post.link == format!("blog/{}", name) {
want = Some(post.clone());
break;
}
}
match want {
Some(post) => {
let body = Html(post.body_html.clone());
Response::builder()
.html(|o| templates::post_html(o, post, body))
},
None => panic!("No post found"),
}
}
}
|