From aef8039358b3d9f0cbd47dfa04ab3d24a2c05e5c Mon Sep 17 00:00:00 2001 From: Cara Salter Date: Wed, 6 Apr 2022 12:22:54 -0400 Subject: flakes + projects --- src/blog/mod.rs | 2 +- src/internal/mod.rs | 4 +++- src/main.rs | 9 +++++++++ src/projects/mod.rs | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 src/projects/mod.rs (limited to 'src') diff --git a/src/blog/mod.rs b/src/blog/mod.rs index 811de15..ac1413e 100644 --- a/src/blog/mod.rs +++ b/src/blog/mod.rs @@ -14,7 +14,7 @@ pub mod handlers { pub async fn list(state: Arc) -> Result { let state = state.clone(); - Response::builder().html(|o| templates::bloglist_html(o, state.blog.clone())) + Response::builder().html(|o| templates::bloglist_html(o, state.blog.clone(), "Posts".into())) } pub async fn post(name: String, state: Arc) -> Result { diff --git a/src/internal/mod.rs b/src/internal/mod.rs index 2a5fa56..5f42764 100644 --- a/src/internal/mod.rs +++ b/src/internal/mod.rs @@ -5,10 +5,12 @@ pub mod markdown; pub struct SiteState { pub blog: Vec, + pub projects: Vec, } pub async fn init() -> Result { let blog = crate::blog::post::load("blog").await?; + let projects = crate::blog::post::load("projects").await?; - Ok(SiteState { blog }) + Ok(SiteState { blog, projects }) } diff --git a/src/main.rs b/src/main.rs index 21eac18..b4801ad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,7 @@ use warp::{path, Filter}; use std::str::FromStr; pub mod blog; +pub mod projects; mod internal; pub mod misc; @@ -35,9 +36,17 @@ async fn main() -> Result<()> { .and(give_site_state(state.clone())) .and_then(blog::handlers::post); + let project_index = warp::path!("projects") + .and(give_site_state(state.clone())) + .and_then(projects::handlers::list); + let project = warp::path!("projects" / String) + .and(give_site_state(state.clone())) + .and_then(projects::handlers::project); + let static_files = warp::path("static").and(warp::fs::dir("./statics")); let site = index.or(about) .or(blog_index.or(blog_post)) + .or(project_index.or(project)) .or(static_files) .with(warp::log("site")); 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) -> Result { + 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) -> Result { + let mut want: Option = 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"), + } + } +} -- cgit v1.2.3