From c494fbec318c8bc93a81756f7a3308f55435d379 Mon Sep 17 00:00:00 2001 From: Kot C Date: Tue, 3 Sep 2024 18:44:04 -0500 Subject: [PATCH] Insert noindex meta for ROBOTS_DISABLE_INDEXING (#199) (#207) --- src/utils.rs | 12 ++++++++++++ templates/base.html | 3 +++ 2 files changed, 15 insertions(+) diff --git a/src/utils.rs b/src/utils.rs index ee1fc66..ff968f8 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1096,6 +1096,18 @@ pub fn enable_rss() -> bool { } } +/// Returns true if the config/env variable `REDLIB_ROBOTS_DISABLE_INDEXING` carries the +/// value `on`. +/// +/// If this variable is set as such, the instance will block all robots in robots.txt and +/// insert the noindex, nofollow meta tag on every page. +pub fn disable_indexing() -> bool { + match get_setting("REDLIB_ROBOTS_DISABLE_INDEXING") { + Some(val) => val == "on", + None => false, + } +} + // Determines if a request shoud redirect to a nsfw landing gate. pub fn should_be_nsfw_gated(req: &Request, req_url: &str) -> bool { let sfw_instance = sfw_only(); diff --git a/templates/base.html b/templates/base.html index 139c76f..1c3ef18 100644 --- a/templates/base.html +++ b/templates/base.html @@ -8,6 +8,9 @@ + {% if crate::utils::disable_indexing() %} + + {% endif %}