Merge pull request #790 from StuffNoOneCaresAbout/allow-disabling-indexing

This commit is contained in:
Matthew Esposito 2023-05-01 10:08:20 -04:00 committed by GitHub
commit 98e2833881
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 4 deletions

5
.gitignore vendored
View file

@ -1 +1,4 @@
/target /target
# Idea Files
.idea/

View file

@ -213,6 +213,7 @@ Assign a default value for each instance-specific setting by passing environment
|-|-|-|-| |-|-|-|-|
| `SFW_ONLY` | `["on", "off"]` | `off` | Enables SFW-only mode for the instance, i.e. all NSFW content is filtered. | | `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. | | `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. |
## Default User Settings ## Default User Settings

View file

@ -50,6 +50,9 @@
"LIBREDDIT_BANNER": { "LIBREDDIT_BANNER": {
"required": false "required": false
}, },
"LIBREDDIT_ROBOTS_DISABLE_INDEXING": {
"required": false
},
"LIBREDDIT_DEFAULT_SUBSCRIPTIONS": { "LIBREDDIT_DEFAULT_SUBSCRIPTIONS": {
"required": false "required": false
}, },

View file

@ -60,6 +60,9 @@ pub struct Config {
#[serde(rename = "LIBREDDIT_BANNER")] #[serde(rename = "LIBREDDIT_BANNER")]
pub(crate) banner: Option<String>, pub(crate) banner: Option<String>,
#[serde(rename = "LIBREDDIT_ROBOTS_DISABLE_INDEXING")]
pub(crate) robots_disable_indexing: Option<String>,
} }
impl Config { impl Config {
@ -90,6 +93,7 @@ impl Config {
default_subscriptions: parse("LIBREDDIT_DEFAULT_SUBSCRIPTIONS"), default_subscriptions: parse("LIBREDDIT_DEFAULT_SUBSCRIPTIONS"),
default_disable_visit_reddit_confirmation: parse("LIBREDDIT_DEFAULT_DISABLE_VISIT_REDDIT_CONFIRMATION"), default_disable_visit_reddit_confirmation: parse("LIBREDDIT_DEFAULT_DISABLE_VISIT_REDDIT_CONFIRMATION"),
banner: parse("LIBREDDIT_BANNER"), banner: parse("LIBREDDIT_BANNER"),
robots_disable_indexing: parse("LIBREDDIT_ROBOTS_DISABLE_INDEXING"),
} }
} }
} }
@ -111,6 +115,7 @@ fn get_setting_from_config(name: &str, config: &Config) -> Option<String> {
"LIBREDDIT_DEFAULT_SUBSCRIPTIONS" => config.default_subscriptions.clone(), "LIBREDDIT_DEFAULT_SUBSCRIPTIONS" => config.default_subscriptions.clone(),
"LIBREDDIT_DEFAULT_DISABLE_VISIT_REDDIT_CONFIRMATION" => config.default_disable_visit_reddit_confirmation.clone(), "LIBREDDIT_DEFAULT_DISABLE_VISIT_REDDIT_CONFIRMATION" => config.default_disable_visit_reddit_confirmation.clone(),
"LIBREDDIT_BANNER" => config.banner.clone(), "LIBREDDIT_BANNER" => config.banner.clone(),
"LIBREDDIT_ROBOTS_DISABLE_INDEXING" => config.robots_disable_indexing.clone(),
_ => None, _ => None,
} }
} }

View file

@ -186,9 +186,21 @@ async fn main() {
app app
.at("/manifest.json") .at("/manifest.json")
.get(|_| resource(include_str!("../static/manifest.json"), "application/json", false).boxed()); .get(|_| resource(include_str!("../static/manifest.json"), "application/json", false).boxed());
app app.at("/robots.txt").get(|_| {
.at("/robots.txt") resource(
.get(|_| resource("User-agent: *\nDisallow: /u/\nDisallow: /user/", "text/plain", true).boxed()); if match config::get_setting("LIBREDDIT_ROBOTS_DISABLE_INDEXING") {
Some(val) => val == "on",
None => false,
} {
"User-agent: *\nDisallow: /"
} else {
"User-agent: *\nDisallow: /u/\nDisallow: /user/"
},
"text/plain",
true,
)
.boxed()
});
app.at("/favicon.ico").get(|_| favicon().boxed()); app.at("/favicon.ico").get(|_| favicon().boxed());
app.at("/logo.png").get(|_| pwa_logo().boxed()); app.at("/logo.png").get(|_| pwa_logo().boxed());
app.at("/Inter.var.woff2").get(|_| font().boxed()); app.at("/Inter.var.woff2").get(|_| font().boxed());