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. |
| `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

View file

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

View file

@ -60,6 +60,9 @@ pub struct Config {
#[serde(rename = "LIBREDDIT_BANNER")]
pub(crate) banner: Option<String>,
#[serde(rename = "LIBREDDIT_ROBOTS_DISABLE_INDEXING")]
pub(crate) robots_disable_indexing: Option<String>,
}
impl Config {
@ -90,6 +93,7 @@ impl Config {
default_subscriptions: parse("LIBREDDIT_DEFAULT_SUBSCRIPTIONS"),
default_disable_visit_reddit_confirmation: parse("LIBREDDIT_DEFAULT_DISABLE_VISIT_REDDIT_CONFIRMATION"),
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_DISABLE_VISIT_REDDIT_CONFIRMATION" => config.default_disable_visit_reddit_confirmation.clone(),
"LIBREDDIT_BANNER" => config.banner.clone(),
"LIBREDDIT_ROBOTS_DISABLE_INDEXING" => config.robots_disable_indexing.clone(),
_ => None,
}
}

View file

@ -186,9 +186,21 @@ async fn main() {
app
.at("/manifest.json")
.get(|_| resource(include_str!("../static/manifest.json"), "application/json", false).boxed());
app
.at("/robots.txt")
.get(|_| resource("User-agent: *\nDisallow: /u/\nDisallow: /user/", "text/plain", true).boxed());
app.at("/robots.txt").get(|_| {
resource(
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("/logo.png").get(|_| pwa_logo().boxed());
app.at("/Inter.var.woff2").get(|_| font().boxed());