diff options
Diffstat (limited to '')
-rw-r--r-- | src/main.rs | 32 |
1 files changed, 31 insertions, 1 deletions
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<Clients>) -> 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/<blogpost>")] +async fn blogpost(blogpost: &str) -> Result<Template> { + let mut blogpost = posts::get_blogpost(blogpost).await?; + blogpost.render().await?; + Ok(Template::render( + "blogpost", + context! { + blogpost, + }, + )) +} + #[get("/contact")] async fn contact() -> Template { Template::render("contact", context! {}) @@ -90,7 +120,7 @@ async fn main() -> std::result::Result<(), rocket::Error> { .attach(Template::custom(|engines| { engines.tera.autoescape_on(vec![]); })) - .mount("/", routes![home, contact, plants]) + .mount("/", routes![home, contact, blog, blogpost, plants]) .register("/", catchers![catcher]) .mount("/", FileServer::from(relative!("static"))) .launch() |