From f38aaecc9a6abed226648417338baff032be8187 Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Wed, 31 Jan 2024 22:12:02 +0000 Subject: add random-poem panel --- src/main.rs | 9 +++++++-- src/poetry.rs | 1 + src/templates.rs | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 1c5126a..60c501f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,6 +25,7 @@ use poem::{ EndpointExt, Route, Server, }; use poem::{IntoResponse, Response}; +use rand::seq::SliceRandom; use rust_embed::RustEmbed; use error::BlossomError; @@ -45,19 +46,23 @@ struct Static; #[handler] async fn home(Data(reqwest): Data<&reqwest::Client>) -> templates::Home { let listenbrainz_client = listenbrainz::raw::Client::new(); - let (live, listenbrainz, blogposts) = tokio::join!( + let (live, listenbrainz, blogposts, poems) = tokio::join!( live::get_live_status(reqwest), scrobbles::get_now_playing(&listenbrainz_client), // skweets::get_recents(&clients.skinnyverse), - Blogpost::get_articles() + Blogpost::get_articles(), + Poem::get_articles() ); let is_live = live.unwrap_or_default().online; let listenbrainz = listenbrainz.unwrap_or_default(); let blogposts = blogposts.unwrap_or_default(); + let poems = poems.unwrap_or_default(); + let poem = poems.choose(&mut rand::thread_rng()).cloned(); templates::Home { is_live, listenbrainz, blogposts, + poem, } } diff --git a/src/poetry.rs b/src/poetry.rs index ef168e8..68fa2ef 100644 --- a/src/poetry.rs +++ b/src/poetry.rs @@ -6,6 +6,7 @@ use crate::{article::Article, posts::Post}; static DIRECTORY: &str = "./poetry"; +#[derive(Clone)] pub struct Poem { pub file_name: String, pub title: Option, diff --git a/src/templates.rs b/src/templates.rs index 8eafd98..4bcb64b 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -26,6 +26,7 @@ pub struct Home { pub is_live: bool, pub listenbrainz: NowPlayingData, pub blogposts: Vec, + pub poem: Option, } #[derive(Template)] -- cgit