From bfcc946baad150b790590a436795b53197b9f7df Mon Sep 17 00:00:00 2001 From: ayaka Date: Sat, 11 Jan 2025 15:05:18 +1300 Subject: [PATCH 1/2] 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() %} -- 2.47.1 From 200509255c0039c163f35b9332fbfb70c900be78 Mon Sep 17 00:00:00 2001 From: ayaka Date: Mon, 13 Jan 2025 14:15:35 +1300 Subject: [PATCH 2/2] allow disabling of banner --- README.md | 1 + src/config.rs | 6 ++++++ src/settings.rs | 3 ++- src/utils.rs | 2 ++ templates/settings.html | 7 ++++++- 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 86764d3..b71973c 100644 --- a/README.md +++ b/README.md @@ -338,4 +338,5 @@ Assign a default value for each user-modifiable setting by passing environment v | `DISABLE_VISIT_REDDIT_CONFIRMATION` | `["on", "off"]` | `off` | | `HIDE_SCORE` | `["on", "off"]` | `off` | | `HIDE_SIDEBAR_AND_SUMMARY` | `["on", "off"]` | `off` | +| `HIDE_BANNER` | `["on", "off"]` | `off` | | `FIXED_NAVBAR` | `["on", "off"]` | `on` | diff --git a/src/config.rs b/src/config.rs index 1c1adbe..9b9fe75 100644 --- a/src/config.rs +++ b/src/config.rs @@ -84,6 +84,10 @@ pub struct Config { #[serde(alias = "LIBREDDIT_DEFAULT_HIDE_SIDEBAR_AND_SUMMARY")] pub(crate) default_hide_sidebar_and_summary: Option, + #[serde(rename = "REDLIB_DEFAULT_HIDE_BANNER")] + #[serde(alias = "LIBREDDIT_DEFAULT_HIDE_BANNER")] + pub(crate) default_hide_banner: Option, + #[serde(rename = "REDLIB_DEFAULT_HIDE_SCORE")] #[serde(alias = "LIBREDDIT_DEFAULT_HIDE_SCORE")] pub(crate) default_hide_score: Option, @@ -161,6 +165,7 @@ impl Config { default_hide_hls_notification: parse("REDLIB_DEFAULT_HIDE_HLS_NOTIFICATION"), default_hide_awards: parse("REDLIB_DEFAULT_HIDE_AWARDS"), default_hide_sidebar_and_summary: parse("REDLIB_DEFAULT_HIDE_SIDEBAR_AND_SUMMARY"), + default_hide_banner: parse("REDLIB_DEFAULT_HIDE_BANNER"), default_hide_score: parse("REDLIB_DEFAULT_HIDE_SCORE"), default_subscriptions: parse("REDLIB_DEFAULT_SUBSCRIPTIONS"), default_filters: parse("REDLIB_DEFAULT_FILTERS"), @@ -193,6 +198,7 @@ fn get_setting_from_config(name: &str, config: &Config) -> Option { "REDLIB_DEFAULT_WIDE" => config.default_wide.clone(), "REDLIB_DEFAULT_HIDE_AWARDS" => config.default_hide_awards.clone(), "REDLIB_DEFAULT_HIDE_SIDEBAR_AND_SUMMARY" => config.default_hide_sidebar_and_summary.clone(), + "REDLIB_DEFAULT_HIDE_BANNER" => config.default_hide_banner.clone(), "REDLIB_DEFAULT_HIDE_SCORE" => config.default_hide_score.clone(), "REDLIB_DEFAULT_SUBSCRIPTIONS" => config.default_subscriptions.clone(), "REDLIB_DEFAULT_FILTERS" => config.default_filters.clone(), diff --git a/src/settings.rs b/src/settings.rs index 6a65207..bed5c9c 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -21,7 +21,7 @@ struct SettingsTemplate { // CONSTANTS -const PREFS: [&str; 21] = [ +const PREFS: [&str; 22] = [ "theme", "mascot", "redsunlib_colorway", @@ -38,6 +38,7 @@ const PREFS: [&str; 21] = [ "hide_hls_notification", "autoplay_videos", "hide_sidebar_and_summary", + "hide_banner", "fixed_navbar", "hide_awards", "hide_score", diff --git a/src/utils.rs b/src/utils.rs index ba09800..c93c335 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -618,6 +618,7 @@ pub struct Preferences { pub hide_hls_notification: String, pub video_quality: String, pub hide_sidebar_and_summary: String, + pub hide_banner: String, pub use_hls: String, pub ffmpeg_video_downloads: String, pub autoplay_videos: String, @@ -671,6 +672,7 @@ impl Preferences { blur_spoiler: setting(req, "blur_spoiler"), show_nsfw: setting(req, "show_nsfw"), hide_sidebar_and_summary: setting(req, "hide_sidebar_and_summary"), + hide_banner: setting(req, "hide_banner"), blur_nsfw: setting(req, "blur_nsfw"), use_hls: setting(req, "use_hls"), ffmpeg_video_downloads: setting(req, "ffmpeg_video_downloads"), diff --git a/templates/settings.html b/templates/settings.html index a3bcd1c..5987e23 100644 --- a/templates/settings.html +++ b/templates/settings.html @@ -65,6 +65,11 @@
+
+ + + +
@@ -158,7 +163,7 @@

Note: settings and subscriptions are saved in browser cookies. Clearing your cookies will reset them.


-

You can restore your current settings and subscriptions after clearing your cookies using this link.

+

You can restore your current settings and subscriptions after clearing your cookies using this link.

{% if prefs.subscriptions.len() > 0 %}
-- 2.47.1