From 3d7cd8a7addd86b7a97a50821eb348345e0d427a Mon Sep 17 00:00:00 2001 From: Cara Salter Date: Wed, 22 Dec 2021 01:06:39 -0500 Subject: Work for the day Post parsing, index page, navbar, CSS, blog listings There's something weird with the path matching that's making it miss the post view page in favor of the list view page. --- src/blog/mod.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'src/blog/mod.rs') diff --git a/src/blog/mod.rs b/src/blog/mod.rs index 3640bcd..c227f22 100644 --- a/src/blog/mod.rs +++ b/src/blog/mod.rs @@ -2,6 +2,7 @@ pub mod post; pub mod handlers { use std::sync::Arc; +use color_eyre::eyre::eyre; use warp::{Reply, Rejection}; use warp::http::Response; @@ -9,13 +10,31 @@ use crate::templates::{self, Html, RenderRucte}; use crate::internal::SiteState; +use super::post::Post; + pub async fn list(state: Arc) -> Result { let state = state.clone(); Response::builder() - .html(|o| templates::index_html(o)) + .html(|o| templates::bloglist_html(o, state.blog.clone())) } - pub async fn post(name: String) -> Result { - Ok("Post test") + pub async fn post(name: String, state: Arc) -> Result { + let mut want: Option = 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"), + } } } -- cgit v1.2.3