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 + static/style.css | 22 ++++++++++++++++++++++ templates/home.html | 1 + templates/random-poem.html | 11 +++++++++++ 6 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 templates/random-poem.html 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)] diff --git a/static/style.css b/static/style.css index cef4a10..dfc3bc9 100644 --- a/static/style.css +++ b/static/style.css @@ -478,6 +478,28 @@ iframe { text-decoration: underline; } +#random-poem { + background-color: #e8cdcf; +} + +#random-poem h2 { + font-family: 'Louise'; + margin-bottom: 0; +} + +#random-poem h3 { + margin-top: 0; +} + +#random-poem a { + font-family: 'Steps Mono'; + padding: 0; + margin: 0; + background-color: transparent; + color: #b52f6a; + text-decoration: underline; +} + /* filter-tags */ #filter-tags { font-family: 'Go Mono'; diff --git a/templates/home.html b/templates/home.html index 540abce..7bbed9e 100644 --- a/templates/home.html +++ b/templates/home.html @@ -46,6 +46,7 @@
latest update: added poetry!
{% include "latestposts.html" %} + {% include "random-poem.html" %} diff --git a/templates/random-poem.html b/templates/random-poem.html new file mode 100644 index 0000000..bdfbaff --- /dev/null +++ b/templates/random-poem.html @@ -0,0 +1,11 @@ +{% if let Some(poem) = poem %} + +{% endif %} \ No newline at end of file -- cgit