mod error; mod live; mod posts; mod scrobbles; mod skweets; use std::borrow::Cow; use rocket::fs::{relative, FileServer}; use rocket::http::Status; use rocket::{Request, State}; use rocket_dyn_templates::{context, Template}; use error::BlossomError; type Result = std::result::Result; struct Clients { listenbrainz: listenbrainz::raw::Client, skinnyverse: mastodon_async::Mastodon, reqwest: reqwest::Client, } #[macro_use] extern crate rocket; #[get("/")] async fn home(clients: &State) -> Template { let (live, listenbrainz, skweets, blogposts) = tokio::join!( live::get_live_status(&clients.reqwest), scrobbles::get_now_playing(&clients.listenbrainz), skweets::get_recents(&clients.skinnyverse), posts::get_blogposts() ); let is_live = live.unwrap_or_default().online; let listenbrainz = listenbrainz.unwrap_or_default(); let skweets = skweets.unwrap_or_default(); let blogposts = blogposts.unwrap_or_default(); Template::render( "home", context! { is_live, listenbrainz, skweets, blogposts, }, ) } #[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