| 1 | use topcoat::{ |
| 2 | Result, |
| 3 | context::Cx, |
| 4 | router::{error::RouterErrorExt, href, module_param, page}, |
| 5 | view::{View, view}, |
| 6 | }; |
| 7 | |
| 8 | use crate::{ |
| 9 | app::{Title, blocks::blocks}, |
| 10 | content::posts::Post, |
| 11 | }; |
| 12 | |
| 13 | module_param!(pub slug); |
| 14 | |
| 15 | fn title(cx: &Cx) -> String { |
| 16 | match Post::from_slug(slug(cx)) { |
| 17 | Some(post) => format!("{} · tahinli", post.title()), |
| 18 | None => String::from("tahinli"), |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | #[page(with(Title(title)))] |
| 23 | pub async fn detail(cx: &Cx) -> Result<impl View> { |
| 24 | let post = Post::from_slug(slug(cx)).ok_or_not_found()?; |
| 25 | let meta = match post.date() { |
| 26 | Some(date) => format!("{} · {} · Ahmet Kaan Gümüş", post.kind().label(), date), |
| 27 | None => format!("{} · Ahmet Kaan Gümüş", post.kind().label()), |
| 28 | }; |
| 29 | |
| 30 | Ok(view! { |
| 31 | <article class="article"> |
| 32 | <a class="back" href=(href!(super::index))>"← posts"</a> |
| 33 | <h1>(post.title())</h1> |
| 34 | <span class="meta">(meta)</span> |
| 35 | blocks(items: post.body()) |
| 36 | </article> |
| 37 | }) |
| 38 | } |