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/main.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 04ab18e..e247211 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,11 +3,12 @@ extern crate tracing; use color_eyre::eyre::Result; use std::{net::IpAddr, sync::Arc}; -use warp::Filter; +use warp::{Filter, path}; use std::str::FromStr; pub mod blog; +pub mod misc; mod internal; use internal::SiteState; @@ -24,15 +25,22 @@ async fn main() -> Result<()> { let state = Arc::new(internal::init().await?); + let index = warp::get().and(path::end().and_then(misc::handlers::index)); + let blog_base = warp::path!("blog" / ..); let blog_list = blog_base.and(give_site_state(state.clone())).and_then(blog::handlers::list); let blog_post = blog_base.and( warp::path!(String) - .and(warp::get()).and_then(blog::handlers::post)); + .and(give_site_state(state.clone())) + .and_then(blog::handlers::post), + ); - let blog = blog_list.or(blog_post); + let static_files = warp::path("static") + .and(warp::fs::dir("./statics")); + let site = index + .or(blog_list.or(blog_post)) + .or(static_files).with(warp::log("site")); - let site = blog.with(warp::log("site")); let server = warp::serve(site); @@ -51,3 +59,5 @@ async fn main() -> Result<()> { fn give_site_state(sitestate: Arc) -> impl Filter,), Error=std::convert::Infallible> + Clone { warp::any().map(move || sitestate.clone()) } + +include!(concat!(env!("OUT_DIR"), "/templates.rs")); -- cgit v1.2.3