diff options
author | cel 🌸 <cel@blos.sm> | 2023-06-21 23:46:20 +0100 |
---|---|---|
committer | cel 🌸 <cel@blos.sm> | 2023-06-21 23:46:20 +0100 |
commit | 5f2a48905634e7874946425057dc904dcb6c7d16 (patch) | |
tree | 89335193f5303c2d236440d6d88c3a1f00c0c4c9 /src/main.rs | |
parent | a508c3a7b49373d89a0522784a2a7e96b8d873e0 (diff) | |
download | blossom-5f2a48905634e7874946425057dc904dcb6c7d16.tar.gz blossom-5f2a48905634e7874946425057dc904dcb6c7d16.tar.bz2 blossom-5f2a48905634e7874946425057dc904dcb6c7d16.zip |
implement blog
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() |