diff options
Diffstat (limited to 'src/projects/mod.rs')
-rw-r--r-- | src/projects/mod.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/projects/mod.rs b/src/projects/mod.rs new file mode 100644 index 0000000..f69c2c0 --- /dev/null +++ b/src/projects/mod.rs @@ -0,0 +1,38 @@ +use crate::blog::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 crate::blog::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.projects.clone(), "Projects".into())) + } + + pub async fn project(name: String, state: Arc<SiteState>) -> Result<impl Reply, Rejection> { + let mut want: Option<Post> = None; + + for post in &state.projects { + if post.link == format!("projects/{}", 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"), + } + } +} |