From 31ff80c62f1ba09c456a068ec6676f651258542f Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Mon, 13 Jul 2020 08:37:09 -0400 Subject: [PATCH] gallery posts --- src/handlers/gallery.rs | 20 +++++- src/main.rs | 8 ++- templates/gallerypost.rs.html | 126 ++++++++++++++++++++++++++++++++++ 3 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 templates/gallerypost.rs.html diff --git a/src/handlers/gallery.rs b/src/handlers/gallery.rs index 3172c40..ee8f836 100644 --- a/src/handlers/gallery.rs +++ b/src/handlers/gallery.rs @@ -1,4 +1,4 @@ -use super::{PostNotFound, SeriesNotFound}; +use super::PostNotFound; use crate::{ app::State, post::Post, @@ -11,3 +11,21 @@ pub async fn index(state: Arc) -> Result { let state = state.clone(); Response::builder().html(|o| templates::galleryindex_html(o, state.gallery.clone())) } + +pub async fn post_view(name: String, state: Arc) -> Result { + let mut want: Option = None; + + for post in &state.gallery { + if post.link == format!("gallery/{}", name) { + want = Some(post.clone()); + } + } + + match want { + None => Err(PostNotFound("blog".into(), name).into()), + Some(post) => { + let body = Html(post.body_html.clone()); + Response::builder().html(|o| templates::gallerypost_html(o, post, body)) + } + } +} diff --git a/src/main.rs b/src/main.rs index 55d104f..dfb626a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,8 +62,14 @@ async fn main() -> Result<()> { .and(warp::path::end()) .and(with_state(state.clone())) .and_then(handlers::gallery::index); + let post_view = base.and( + warp::path!(String) + .and(with_state(state.clone())) + .and(warp::get()) + .and_then(handlers::gallery::post_view), + ); - index + index.or(post_view) }; let static_pages = { diff --git a/templates/gallerypost.rs.html b/templates/gallerypost.rs.html new file mode 100644 index 0000000..b3719f7 --- /dev/null +++ b/templates/gallerypost.rs.html @@ -0,0 +1,126 @@ +@use super::{header_html, footer_html}; +@use crate::post::Post; + +@(post: Post, body: impl ToHtml) + +@:header_html(Some(&post.front_matter.title.clone()), None) + + + + + + + + + + + + + + + + + + + + +

@post.front_matter.title

+ +@body + +
+ +
+ +
+ + + + +@if post.front_matter.series.is_some() { +

Series: @post.front_matter.series.as_ref().unwrap()

+} + +@if post.front_matter.tags.is_some() { +

Tags: @for tag in post.front_matter.tags.as_ref().unwrap() { @tag }

+} + + + +@:footer_html()