From bfcc946baad150b790590a436795b53197b9f7df Mon Sep 17 00:00:00 2001 From: ayaka Date: Sat, 11 Jan 2025 15:05:18 +1300 Subject: [PATCH] subreddit banners --- src/subreddit.rs | 5 +++++ src/utils.rs | 1 + static/style.css | 2 +- templates/subreddit.html | 8 +++++++- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/subreddit.rs b/src/subreddit.rs index 5f964ef..8569185 100644 --- a/src/subreddit.rs +++ b/src/subreddit.rs @@ -469,6 +469,10 @@ async fn subreddit(sub: &str, quarantined: bool) -> Result { let community_icon: &str = res["data"]["community_icon"].as_str().unwrap_or_default(); let icon = if community_icon.is_empty() { val(&res, "icon_img") } else { community_icon.to_string() }; + // Fetch subreddit banner either from the banner_background_image or banner_img value + let banner_background_image: &str = res["data"]["banner_background_image"].as_str().unwrap_or_default(); + let banner = if banner_background_image.is_empty() { val(&res, "banner_img") } else { banner_background_image.to_string() }; + Ok(Subreddit { name: val(&res, "display_name"), title: val(&res, "title"), @@ -476,6 +480,7 @@ async fn subreddit(sub: &str, quarantined: bool) -> Result { info: rewrite_urls(&val(&res, "description_html")), // moderators: moderators_list(sub, quarantined).await.unwrap_or_default(), icon: format_url(&icon), + banner: format_url(&banner), members: format_num(members), active: format_num(active), wiki: res["data"]["wiki_enabled"].as_bool().unwrap_or_default(), diff --git a/src/utils.rs b/src/utils.rs index b8105c3..ba09800 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -585,6 +585,7 @@ pub struct Subreddit { pub info: String, // pub moderators: Vec, pub icon: String, + pub banner: String, pub members: (String, String), pub active: (String, String), pub wiki: bool, diff --git a/static/style.css b/static/style.css index 9567a81..df9f8da 100644 --- a/static/style.css +++ b/static/style.css @@ -499,7 +499,7 @@ aside { height: 100px; border: 2px solid var(--accent); border-radius: 100%; - padding: 10px; + padding: 0px; margin: 10px; } diff --git a/templates/subreddit.html b/templates/subreddit.html index 5584863..2765e1f 100644 --- a/templates/subreddit.html +++ b/templates/subreddit.html @@ -100,8 +100,14 @@ Wiki {% endif %} -
+ {% block head %} + {% call super() %} + + {% endblock %} +
Icon for r/{{ sub.name }} +
+

{{ sub.title }}

r/{{ sub.name }}

{% if crate::utils::enable_rss() %}