diff --git a/.env.example b/.env.example index 5e187f9..5e60b08 100644 --- a/.env.example +++ b/.env.example @@ -24,6 +24,8 @@ REDLIB_DEFAULT_WIDE=off REDLIB_DEFAULT_POST_SORT=hot # Set the default comment sort method (options: confidence, top, new, controversial, old) REDLIB_DEFAULT_COMMENT_SORT=confidence +# Enable blurring Spoiler content by default +REDLIB_DEFAULT_BLUR_SPOILER=off # Enable showing NSFW content by default REDLIB_DEFAULT_SHOW_NSFW=off # Enable blurring NSFW content by default diff --git a/README.md b/README.md index 1773858..533b628 100644 --- a/README.md +++ b/README.md @@ -394,6 +394,7 @@ Assign a default value for each user-modifiable setting by passing environment v | `WIDE` | `["on", "off"]` | `off` | | `POST_SORT` | `["hot", "new", "top", "rising", "controversial"]` | `hot` | | `COMMENT_SORT` | `["confidence", "top", "new", "controversial", "old"]` | `confidence` | +| `BLUR_SPOILER` | `["on", "off"]` | `off` | | `SHOW_NSFW` | `["on", "off"]` | `off` | | `BLUR_NSFW` | `["on", "off"]` | `off` | | `USE_HLS` | `["on", "off"]` | `off` | diff --git a/app.json b/app.json index b3e8616..d73780c 100644 --- a/app.json +++ b/app.json @@ -29,6 +29,9 @@ "REDLIB_DEFAULT_POST_SORT": { "required": false }, + "REDLIB_DEFAULT_BLUR_SPOILER": { + "required": false + }, "REDLIB_DEFAULT_SHOW_NSFW": { "required": false }, diff --git a/contrib/redlib.conf b/contrib/redlib.conf index 880bc7a..43c1d86 100644 --- a/contrib/redlib.conf +++ b/contrib/redlib.conf @@ -6,6 +6,7 @@ PORT=12345 #REDLIB_DEFAULT_WIDE=off #REDLIB_DEFAULT_POST_SORT=hot #REDLIB_DEFAULT_COMMENT_SORT=confidence +#REDLIB_DEFAULT_BLUR_SPOILER=off #REDLIB_DEFAULT_SHOW_NSFW=off #REDLIB_DEFAULT_BLUR_NSFW=off #REDLIB_DEFAULT_USE_HLS=off diff --git a/src/config.rs b/src/config.rs index a787251..2b8c752 100644 --- a/src/config.rs +++ b/src/config.rs @@ -48,6 +48,10 @@ pub struct Config { #[serde(alias = "LIBREDDIT_DEFAULT_POST_SORT")] pub(crate) default_post_sort: Option, + #[serde(rename = "REDLIB_DEFAULT_BLUR_SPOILER")] + #[serde(alias = "LIBREDDIT_DEFAULT_BLUR_SPOILER")] + pub(crate) default_blur_spoiler: Option, + #[serde(rename = "REDLIB_DEFAULT_SHOW_NSFW")] #[serde(alias = "LIBREDDIT_DEFAULT_SHOW_NSFW")] pub(crate) default_show_nsfw: Option, @@ -130,6 +134,7 @@ impl Config { default_post_sort: parse("REDLIB_DEFAULT_POST_SORT"), default_wide: parse("REDLIB_DEFAULT_WIDE"), default_comment_sort: parse("REDLIB_DEFAULT_COMMENT_SORT"), + default_blur_spoiler: parse("REDLIB_DEFAULT_BLUR_SPOILER"), default_show_nsfw: parse("REDLIB_DEFAULT_SHOW_NSFW"), default_blur_nsfw: parse("REDLIB_DEFAULT_BLUR_NSFW"), default_use_hls: parse("REDLIB_DEFAULT_USE_HLS"), @@ -155,6 +160,7 @@ fn get_setting_from_config(name: &str, config: &Config) -> Option { "REDLIB_DEFAULT_LAYOUT" => config.default_layout.clone(), "REDLIB_DEFAULT_COMMENT_SORT" => config.default_comment_sort.clone(), "REDLIB_DEFAULT_POST_SORT" => config.default_post_sort.clone(), + "REDLIB_DEFAULT_BLUR_SPOILER" => config.default_blur_spoiler.clone(), "REDLIB_DEFAULT_SHOW_NSFW" => config.default_show_nsfw.clone(), "REDLIB_DEFAULT_BLUR_NSFW" => config.default_blur_nsfw.clone(), "REDLIB_DEFAULT_USE_HLS" => config.default_use_hls.clone(), diff --git a/src/instance_info.rs b/src/instance_info.rs index 85c4883..20ffc6d 100644 --- a/src/instance_info.rs +++ b/src/instance_info.rs @@ -141,6 +141,7 @@ impl InstanceInfo { ["Wide", &convert(&self.config.default_wide)], ["Comment sort", &convert(&self.config.default_comment_sort)], ["Post sort", &convert(&self.config.default_post_sort)], + ["Blur Spoiler", &convert(&self.config.default_blur_spoiler)], ["Show NSFW", &convert(&self.config.default_show_nsfw)], ["Blur NSFW", &convert(&self.config.default_blur_nsfw)], ["Use HLS", &convert(&self.config.default_use_hls)], @@ -174,6 +175,7 @@ impl InstanceInfo { Default wide: {:?}\n Default comment sort: {:?}\n Default post sort: {:?}\n + Default blur Spoiler: {:?}\n Default show NSFW: {:?}\n Default blur NSFW: {:?}\n Default use HLS: {:?}\n @@ -197,6 +199,7 @@ impl InstanceInfo { self.config.default_wide, self.config.default_comment_sort, self.config.default_post_sort, + self.config.default_blur_spoiler, self.config.default_show_nsfw, self.config.default_blur_nsfw, self.config.default_use_hls, diff --git a/src/settings.rs b/src/settings.rs index 6964675..6c0480c 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -19,13 +19,14 @@ struct SettingsTemplate { // CONSTANTS -const PREFS: [&str; 16] = [ +const PREFS: [&str; 17] = [ "theme", "front_page", "layout", "wide", "comment_sort", "post_sort", + "blur_spoiler", "show_nsfw", "blur_nsfw", "use_hls", diff --git a/src/utils.rs b/src/utils.rs index f44d037..4d412cc 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -157,6 +157,7 @@ impl PollOption { // Post flags with nsfw and stickied pub struct Flags { + pub spoiler: bool, pub nsfw: bool, pub stickied: bool, } @@ -403,6 +404,7 @@ impl Post { }, }, flags: Flags { + spoiler: data["spoiler"].as_bool().unwrap_or_default(), nsfw: data["over_18"].as_bool().unwrap_or_default(), stickied: data["stickied"].as_bool().unwrap_or_default() || data["pinned"].as_bool().unwrap_or_default(), }, @@ -575,6 +577,7 @@ pub struct Preferences { pub front_page: String, pub layout: String, pub wide: String, + pub blur_spoiler: String, pub show_nsfw: String, pub blur_nsfw: String, pub hide_hls_notification: String, @@ -612,6 +615,7 @@ impl Preferences { front_page: setting(req, "front_page"), layout: setting(req, "layout"), wide: setting(req, "wide"), + blur_spoiler: setting(req, "blur_spoiler"), show_nsfw: setting(req, "show_nsfw"), hide_sidebar_and_summary: setting(req, "hide_sidebar_and_summary"), blur_nsfw: setting(req, "blur_nsfw"), @@ -732,6 +736,7 @@ pub async fn parse_post(post: &Value) -> Post { }, }, flags: Flags { + spoiler: post["data"]["spoiler"].as_bool().unwrap_or_default(), nsfw: post["data"]["over_18"].as_bool().unwrap_or_default(), stickied: post["data"]["stickied"].as_bool().unwrap_or_default() || post["data"]["pinned"].as_bool().unwrap_or(false), }, diff --git a/templates/settings.html b/templates/settings.html index 496b9b1..434f0d2 100644 --- a/templates/settings.html +++ b/templates/settings.html @@ -54,6 +54,11 @@ {% call utils::options(prefs.comment_sort, ["confidence", "top", "new", "controversial", "old"], "confidence") %} +
+ + + +
{% if !crate::utils::sfw_only() %}
diff --git a/templates/utils.html b/templates/utils.html index a99e2be..e40d6c6 100644 --- a/templates/utils.html +++ b/templates/utils.html @@ -194,6 +194,7 @@ {% endmacro %} {% macro post_in_list(post) -%} +{% set post_should_be_blurred = (post.flags.nsfw && prefs.blur_nsfw=="on") || (post.flags.spoiler && prefs.blur_spoiler=="on") -%}

{% let community -%} @@ -233,7 +234,7 @@ Post image {% else %} @@ -247,19 +248,19 @@

{% else if (prefs.layout.is_empty() || prefs.layout == "card") && post.post_type == "gif" %}
- +
{% else if (prefs.layout.is_empty() || prefs.layout == "card") && post.post_type == "video" %} {% if prefs.use_hls == "on" && !post.media.alt_url.is_empty() %}
-
{% else %}
- +
{% call render_hls_notification(format!("{}%23{}", &self.url[1..].replace("&", "%26").replace("+", "%2B"), post.id)) %} {% endif %} @@ -272,7 +273,7 @@ {% else %}
- + Thumbnail