| 1 | pub mod slug; |
| 2 | |
| 3 | use topcoat::{ |
| 4 | Result, |
| 5 | context::Cx, |
| 6 | router::{href, page}, |
| 7 | view::{View, component, view}, |
| 8 | }; |
| 9 | |
| 10 | use crate::{app::Title, content::posts::Post}; |
| 11 | |
| 12 | pub fn detail_url(cx: &Cx, post: Post) -> String { |
| 13 | href!(slug::detail, slug: post.slug()).resolve(cx) |
| 14 | } |
| 15 | |
| 16 | #[component] |
| 17 | pub async fn post_row(cx: &Cx, post: Post) -> Result<impl View> { |
| 18 | Ok(view! { |
| 19 | <a class="row" href=(detail_url(cx, post))> |
| 20 | <span class="row-key">(post.date().unwrap_or(post.kind().label()))</span> |
| 21 | <span>(post.title())</span> |
| 22 | </a> |
| 23 | }) |
| 24 | } |
| 25 | |
| 26 | #[page(with(Title(|_| "Posts · tahinli".to_owned())))] |
| 27 | pub async fn index(cx: &Cx) -> Result<impl View> { |
| 28 | Ok(view! { |
| 29 | <h2 class="label">"Writing"</h2> |
| 30 | for post in Post::ALL { |
| 31 | post_row(post: post) |
| 32 | } |
| 33 | }) |
| 34 | } |