diff --git a/README.md b/README.md index 7ea145c5..a90f9d29 100644 --- a/README.md +++ b/README.md @@ -408,15 +408,16 @@ Redlib supports the following command line flags: Assign a default value for each instance-specific setting by passing environment variables to Redlib in the format `REDLIB_{X}`. Replace `{X}` with the setting name (see list below) in capital letters. -| Name | Possible values | Default value | Description | -|---------------------------|-----------------|------------------------|-----------------------------------------------------------------------------------------------------------| -| `SFW_ONLY` | `["on", "off"]` | `off` | Enables SFW-only mode for the instance, i.e. all NSFW content is filtered. | -| `BANNER` | String | (empty) | Allows the server to set a banner to be displayed. Currently this is displayed on the instance info page. | -| `ROBOTS_DISABLE_INDEXING` | `["on", "off"]` | `off` | Disables indexing of the instance by search engines. | -| `PUSHSHIFT_FRONTEND` | String | `undelete.pullpush.io` | Allows the server to set the Pushshift frontend to be used with "removed" links. | -| `PORT` | Integer 0-65535 | `8080` | The **internal** port Redlib listens on. | -| `ENABLE_RSS` | `["on", "off"]` | `off` | Enables RSS feed generation. | -| `FULL_URL` | String | (empty) | Allows for proper URLs (for now, only needed by RSS) | +| Name | Possible values | Default value | Description | +|---------------------------|-----------------|----------------------------------------|-----------------------------------------------------------------------------------------------------------| +| `SFW_ONLY` | `["on", "off"]` | `off` | Enables SFW-only mode for the instance, i.e. all NSFW content is filtered. | +| `BANNER` | String | (empty) | Allows the server to set a banner to be displayed. Currently this is displayed on the instance info page. | +| `ROBOTS_DISABLE_INDEXING` | `["on", "off"]` | `off` | Disables indexing of the instance by search engines. | +| `PUSHSHIFT_FRONTEND` | String | `undelete.pullpush.io` | Allows the server to set the Pushshift frontend to be used with "removed" links. | +| `PORT` | Integer 0-65535 | `8080` | The **internal** port Redlib listens on. | +| `ENABLE_RSS` | `["on", "off"]` | `off` | Enables RSS feed generation. | +| `FULL_URL` | String | (empty) | Allows for proper URLs (for now, only needed by RSS) | +| `SOURCE_URL` | String | `https://github.com/redlib-org/redlib` | Link to the source code for this instance. ## Default user settings diff --git a/src/config.rs b/src/config.rs index 8f92c9b7..b587155b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -108,6 +108,9 @@ pub struct Config { #[serde(rename = "REDLIB_DEFAULT_REMOVE_DEFAULT_FEEDS")] pub(crate) default_remove_default_feeds: Option, + + #[serde(rename = "REDLIB_SOURCE_URL")] + pub(crate) source_url: Option, } impl Config { @@ -156,6 +159,7 @@ impl Config { enable_rss: parse("REDLIB_ENABLE_RSS"), full_url: parse("REDLIB_FULL_URL"), default_remove_default_feeds: parse("REDLIB_DEFAULT_REMOVE_DEFAULT_FEEDS"), + source_url: parse("REDLIB_SOURCE_URL"), } } } @@ -186,6 +190,7 @@ fn get_setting_from_config(name: &str, config: &Config) -> Option { "REDLIB_ENABLE_RSS" => config.enable_rss.clone(), "REDLIB_FULL_URL" => config.full_url.clone(), "REDLIB_DEFAULT_REMOVE_DEFAULT_FEEDS" => config.default_remove_default_feeds.clone(), + "REDLIB_SOURCE_URL" => config.source_url.clone(), _ => None, } } @@ -263,6 +268,12 @@ mod tests { assert_eq!(get_setting("REDLIB_DEFAULT_FILTERS"), Some("news+bestof".into())); } + #[test] + #[sealed_test(env = [("REDLIB_SOURCE_URL", "https://example.com")])] + fn test_source_url() { + assert_eq!(get_setting("REDLIB_SOURCE_URL"), Some("https://example.com".into())); + } + #[test] #[sealed_test] fn test_pushshift() { diff --git a/src/utils.rs b/src/utils.rs index 36b798f4..358d28d0 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1381,6 +1381,12 @@ pub fn disable_indexing() -> bool { } } +/// Returns the currently configured source code URL to display in the footer. +/// Defaults to the upstream Github repository URL when not explicitly configured. +pub fn get_source_url() -> String { + get_setting("REDLIB_SOURCE_URL").unwrap_or("https://github.com/redlib-org/redlib".into()) +} + /// Determines if a request should redirect to a NSFW landing gate. pub fn should_be_nsfw_gated(req: &Request, _req_url: &str) -> bool { (setting(req, "show_nsfw") != "on") || sfw_only() diff --git a/templates/base.html b/templates/base.html index a1c141bc..c7fd6fc1 100644 --- a/templates/base.html +++ b/templates/base.html @@ -77,7 +77,7 @@ {% block footer %} {% endblock %}