summaryrefslogblamecommitdiff
path: root/src/blog/mod.rs
blob: 811de15b26c2bd0f0bd45965c7db656d83e2b70b (plain) (tree)
1
2
3
4
5
6
7
8
9
             

                  

                               
 


                                                    
 
                                   
 
                          
 

                                                                               
                                                                                     

     












                                                                                             

                                                                                 

                                            

     
pub mod post;
pub mod handlers {

    use color_eyre::eyre::eyre;
    use std::sync::Arc;

    use crate::templates::{self, Html, RenderRucte};
    use warp::http::Response;
    use warp::{Rejection, Reply};

    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"),
        }
    }
}