diff options
author | Cara Salter <cara@devcara.com> | 2021-12-22 01:06:39 -0500 |
---|---|---|
committer | Cara Salter <cara@devcara.com> | 2021-12-22 01:06:39 -0500 |
commit | 3d7cd8a7addd86b7a97a50821eb348345e0d427a (patch) | |
tree | 875aecda597c8161359005c33a147097fa36c807 /src/main.rs | |
parent | c4d7f8f50d53057005d6bb28ac487f69ea45bd5e (diff) | |
download | site-3d7cd8a7addd86b7a97a50821eb348345e0d427a.tar.gz site-3d7cd8a7addd86b7a97a50821eb348345e0d427a.zip |
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.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 18 |
1 files changed, 14 insertions, 4 deletions
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<SiteState>) -> impl Filter<Extract = (Arc<SiteState>,), Error=std::convert::Infallible> + Clone { warp::any().map(move || sitestate.clone()) } + +include!(concat!(env!("OUT_DIR"), "/templates.rs")); |