From 5f2a48905634e7874946425057dc904dcb6c7d16 Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Wed, 21 Jun 2023 23:46:20 +0100 Subject: implement blog --- src/error.rs | 1 + src/main.rs | 32 ++++++++++++++++++++++++- src/posts/mod.rs | 73 ++++++++++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 93 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/error.rs b/src/error.rs index 81cadd1..eb6f6e6 100644 --- a/src/error.rs +++ b/src/error.rs @@ -8,6 +8,7 @@ pub enum BlossomError { Chrono(Status, #[response(ignore)] chrono::ParseError), Io(Status, #[response(ignore)] std::io::Error), Deserialization(Status, #[response(ignore)] toml::de::Error), + NotFound(Status), NoMetadata(Status), Unimplemented(Status), } diff --git a/src/main.rs b/src/main.rs index dd2bd34..c08c2e1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,6 +47,36 @@ async fn home(clients: &State) -> Template { ) } +#[get("/blog")] +async fn blog() -> Template { + let mut blogposts = posts::get_blogposts().await.unwrap_or_default(); + let tags = posts::get_tags(&blogposts); + for blogpost in &mut blogposts { + blogpost.render().await; + } + let reverse = "reverse".to_owned(); + Template::render( + "blog", + context! { + reverse, + blogposts, + tags, + }, + ) +} + +#[get("/blog/")] +async fn blogpost(blogpost: &str) -> Result