feat: Add option for a noindex meta tag on the HTML index page

Adds a new config option `index_page_allow_indexing` which defaults to false.

Fixes: !1527
This commit is contained in:
theS1LV3R 2026-03-11 16:47:47 +01:00 committed by Ginger
parent 67d5619ccb
commit 7b6bf4b78e
No known key found for this signature in database
6 changed files with 28 additions and 1 deletions

View file

@ -1799,6 +1799,11 @@
# #
#config_reload_signal = true #config_reload_signal = true
# Allow or disallow search engine crawling by adding
# `<meta name="robots" content="noindex" />` to the index page.
#
#index_page_allow_indexing = false
[global.tls] [global.tls]
# Path to a valid TLS certificate file. # Path to a valid TLS certificate file.

View file

@ -2093,6 +2093,13 @@ pub struct Config {
#[serde(default)] #[serde(default)]
pub force_disable_first_run_mode: bool, pub force_disable_first_run_mode: bool,
/// Allow or disallow search engine crawling by adding
/// `<meta name="robots" content="noindex" />` to the index page.
///
/// default: false
#[serde(default)]
pub index_page_allow_indexing: bool,
/// display: nested /// display: nested
#[serde(default)] #[serde(default)]
pub ldap: LdapConfig, pub ldap: LdapConfig,

View file

@ -40,6 +40,7 @@ impl IntoResponse for WebError {
struct Error { struct Error {
error: WebError, error: WebError,
status: StatusCode, status: StatusCode,
allow_indexing: bool,
} }
let status = match &self { let status = match &self {
| Self::ValidationError(_) | Self::ValidationError(_)
@ -50,7 +51,13 @@ impl IntoResponse for WebError {
| _ => StatusCode::INTERNAL_SERVER_ERROR, | _ => StatusCode::INTERNAL_SERVER_ERROR,
}; };
let template = Error { error: self, status }; let template = Error {
error: self,
status,
// Statically set false to prevent error pages from being indexed and to prevent
// further errors if services.config is having issues.
allow_indexing: false,
};
if let Ok(body) = template.render() { if let Ok(body) = template.render() {
(status, Html(body)).into_response() (status, Html(body)).into_response()

View file

@ -18,11 +18,13 @@ async fn index_handler(
struct Index<'a> { struct Index<'a> {
server_name: &'a str, server_name: &'a str,
first_run: bool, first_run: bool,
allow_indexing: bool,
} }
let template = Index { let template = Index {
server_name: services.globals.server_name().as_str(), server_name: services.globals.server_name().as_str(),
first_run: services.firstrun.is_first_run(), first_run: services.firstrun.is_first_run(),
allow_indexing: services.config.index_page_allow_indexing,
}; };
Ok(Html(template.render()?)) Ok(Html(template.render()?))
} }

View file

@ -27,6 +27,7 @@ struct PasswordResetQuery {
struct PasswordReset<'a> { struct PasswordReset<'a> {
user_card: UserCard<'a>, user_card: UserCard<'a>,
body: PasswordResetBody, body: PasswordResetBody,
allow_indexing: bool,
} }
#[derive(Debug)] #[derive(Debug)]
@ -74,6 +75,7 @@ async fn password_reset_form(
let template = PasswordReset { let template = PasswordReset {
user_card, user_card,
body: PasswordResetBody::Form(reset_form), body: PasswordResetBody::Form(reset_form),
allow_indexing: services.config.index_page_allow_indexing,
}; };
Ok(Html(template.render()?)) Ok(Html(template.render()?))
@ -112,6 +114,7 @@ async fn post_password_reset(
let template = PasswordReset { let template = PasswordReset {
user_card, user_card,
body: PasswordResetBody::Success, body: PasswordResetBody::Success,
allow_indexing: services.config.index_page_allow_indexing,
}; };
Ok(Html(template.render()?).into_response()) Ok(Html(template.render()?).into_response())

View file

@ -5,6 +5,9 @@
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<title>{% block title %}Continuwuity{% endblock %}</title> <title>{% block title %}Continuwuity{% endblock %}</title>
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
{%- if allow_indexing %}
<meta name="robots" content="noindex" />
{%- endif %}
<link rel="icon" href="/_continuwuity/resources/logo.svg"> <link rel="icon" href="/_continuwuity/resources/logo.svg">
<link rel="stylesheet" href="/_continuwuity/resources/common.css"> <link rel="stylesheet" href="/_continuwuity/resources/common.css">