diff --git a/README.md b/README.md index f225bf5..cab3565 100644 --- a/README.md +++ b/README.md @@ -224,24 +224,20 @@ Assign a default value for each instance-specific setting by passing environment Assign a default value for each user-modifiable setting by passing environment variables to Libreddit in the format `LIBREDDIT_DEFAULT_{Y}`. Replace `{Y}` with the setting name (see list below) in capital letters. -| Name | Possible values | Default value | -|-------------------------------------|------------------------------------------------------------------------------------------------------------------------------------|---------------| -| `THEME` | `["system", "light", "dark", "black", "dracula", "nord", "laserwave", "violet", "gold", "rosebox", "gruvboxdark", "gruvboxlight"]` | `system` | -| `FRONT_PAGE` | `["default", "popular", "all"]` | `default` | -| `LAYOUT` | `["card", "clean", "compact"]` | `card` | -| `WIDE` | `["on", "off"]` | `off` | -| `POST_SORT` | `["hot", "new", "top", "rising", "controversial"]` | `hot` | -| `COMMENT_SORT` | `["confidence", "top", "new", "controversial", "old"]` | `confidence` | -| `SHOW_NSFW` | `["on", "off"]` | `off` | -| `BLUR_NSFW` | `["on", "off"]` | `off` | -| `USE_HLS` | `["on", "off"]` | `off` | -| `HIDE_HLS_NOTIFICATION` | `["on", "off"]` | `off` | -| `AUTOPLAY_VIDEOS` | `["on", "off"]` | `off` | -| `SUBSCRIPTIONS` | `+`-delimited list of subreddits (`sub1+sub2+sub3+...`) | _(none)_ | -| `HIDE_AWARDS` | `["on", "off"]` | `off` | -| `DISABLE_VISIT_REDDIT_CONFIRMATION` | `["on", "off"]` | `off` | -| `DISABLE_STATS_COLLECTION` | Any string to disable | _(none)_ | -| `HIDE_SCORE` | `["on", "off"]` | `off` | +| Name | Possible values | Default value | +|-------------------------|-----------------------------------------------------------------------------------------------------|---------------| +| `THEME` | `["system", "light", "dark", "black", "dracula", "nord", "laserwave", "violet", "gold", "rosebox", "gruvboxdark", "gruvboxlight"]` | `system` | +| `FRONT_PAGE` | `["default", "popular", "all"]` | `default` | +| `LAYOUT` | `["card", "clean", "compact"]` | `card` | +| `WIDE` | `["on", "off"]` | `off` | +| `POST_SORT` | `["hot", "new", "top", "rising", "controversial"]` | `hot` | +| `COMMENT_SORT` | `["confidence", "top", "new", "controversial", "old"]` | `confidence` | +| `SHOW_NSFW` | `["on", "off"]` | `off` | +| `BLUR_NSFW` | `["on", "off"]` | `off` | +| `USE_HLS` | `["on", "off"]` | `off` | +| `HIDE_HLS_NOTIFICATION` | `["on", "off"]` | `off` | +| `AUTOPLAY_VIDEOS` | `["on", "off"]` | `off` | +| `FIXED_NAVBAR` | `["on", "off"]` | `on` | You can also configure Libreddit with a configuration file. An example `libreddit.toml` can be found below: diff --git a/src/settings.rs b/src/settings.rs index 12795bc..052941a 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -19,7 +19,7 @@ struct SettingsTemplate { // CONSTANTS -const PREFS: [&str; 14] = [ +const PREFS: [&str; 13] = [ "theme", "front_page", "layout", @@ -31,6 +31,7 @@ const PREFS: [&str; 14] = [ "use_hls", "hide_hls_notification", "autoplay_videos", + "fixed_navbar", "hide_awards", "hide_score", "disable_visit_reddit_confirmation", diff --git a/src/utils.rs b/src/utils.rs index 3931fad..ac41c4a 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -572,7 +572,7 @@ pub struct Preferences { pub hide_hls_notification: String, pub use_hls: String, pub autoplay_videos: String, - pub disable_visit_reddit_confirmation: String, + pub fixed_navbar: String, pub comment_sort: String, pub post_sort: String, pub subscriptions: Vec, @@ -607,7 +607,7 @@ impl Preferences { use_hls: setting(&req, "use_hls"), hide_hls_notification: setting(&req, "hide_hls_notification"), autoplay_videos: setting(&req, "autoplay_videos"), - disable_visit_reddit_confirmation: setting(&req, "disable_visit_reddit_confirmation"), + fixed_navbar: setting_or_default(&req, "fixed_navbar", "on".to_string()), comment_sort: setting(&req, "comment_sort"), post_sort: setting(&req, "post_sort"), subscriptions: setting(&req, "subscriptions").split('+').map(String::from).filter(|s| !s.is_empty()).collect(), @@ -769,6 +769,16 @@ pub fn setting(req: &Request, name: &str) -> String { .to_string() } +// Retrieve the value of a setting by name or the default value +pub fn setting_or_default(req: &Request, name: &str, default: String) -> String { + let value = setting(req, name); + if !value.is_empty() { + value + } else { + default + } +} + // Detect and redirect in the event of a random subreddit pub async fn catch_random(sub: &str, additional: &str) -> Result, String> { if sub == "random" || sub == "randnsfw" { diff --git a/static/style.css b/static/style.css index bad0c75..4cd9216 100644 --- a/static/style.css +++ b/static/style.css @@ -100,6 +100,9 @@ pre, form, fieldset, table, th, td, select, input { body { background: var(--background); font-size: 15px; +} + +body.fixed_navbar { padding-top: 60px; padding-bottom: var(--footer-height); min-height: calc(100vh - 60px); @@ -122,8 +125,12 @@ nav { z-index: 2; top: 0; padding: 5px 15px; + margin-bottom: 10px; min-height: 40px; width: calc(100% - 30px); +} + +nav.fixed_navbar { position: fixed; } @@ -1566,10 +1573,7 @@ td, th { /* Mobile */ @media screen and (max-width: 800px) { - body { - padding-top: 120px; - padding-bottom: var(--footer-height); - } + body.fixed_navbar { padding-top: 120px } main { flex-direction: column-reverse; @@ -1612,10 +1616,8 @@ td, th { } @media screen and (max-width: 480px) { - body { - padding-top: 100px; - padding-bottom: var(--footer-height); - } + body.fixed_navbar { padding-top: 100px; } + #version { display: none; } .post { grid-template: "post_header post_header post_thumbnail" auto diff --git a/templates/base.html b/templates/base.html index af539f8..b42caf9 100644 --- a/templates/base.html +++ b/templates/base.html @@ -27,9 +27,11 @@ + {% if prefs.theme != "system" %} {{ prefs.theme }}{% endif %} + {% if prefs.fixed_navbar == "on" %} fixed_navbar{% endif %}"> -