From 9133dd7688c4c21efd1fa824a4fe37cb8fd6a937 Mon Sep 17 00:00:00 2001
From: asonix <asonix@asonix.dog>
Date: Mon, 21 Nov 2022 11:16:21 -0600
Subject: [PATCH] Add optional footer blurb

---
 .env                    |  1 +
 README.md               |  3 +++
 src/config.rs           | 15 +++++++++++++++
 templates/index.rs.html |  3 +++
 4 files changed, 22 insertions(+)

diff --git a/.env b/.env
index e8adc6f..b28a8c6 100644
--- a/.env
+++ b/.env
@@ -2,4 +2,5 @@ HOSTNAME=localhost:8079
 PORT=8079
 RESTRICTED_MODE=true
 API_TOKEN=somesecretpassword
+FOOTER_BLURB="Contact <a href=\"https://masto.asonix.dog/@asonix\">@asonix</a> for inquiries"
 # OPENTELEMETRY_URL=http://localhost:4317
diff --git a/README.md b/README.md
index ed0957b..273f3bc 100644
--- a/README.md
+++ b/README.md
@@ -100,6 +100,7 @@ TELEGRAM_TOKEN=secret
 TELEGRAM_ADMIN_HANDLE=your_handle
 TLS_KEY=/path/to/key
 TLS_CERT=/path/to/cert
+FOOTER_BLURB="Contact <a href=\"https://masto.asonix.dog/@asonix\">@asonix</a>
 ```
 
 #### Descriptions
@@ -137,6 +138,8 @@ The handle of the telegram user allowed to administer the relay. There is no def
 Optional - This is specified if you are running the relay directly on the internet and have a TLS key to provide HTTPS for your relay
 ##### `TLS_CERT`
 Optional - This is specified if you are running the relay directly on the internet and have a TLS certificate chain to provide HTTPS for your relay
+##### `FOOTER_BLURB`
+Optional - Add custom notes in the footer of the page
 
 ### Subscribing
 Mastodon admins can subscribe to this relay by adding the `/inbox` route to their relay settings.
diff --git a/src/config.rs b/src/config.rs
index a03ea3d..b1da0cc 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -37,6 +37,7 @@ pub(crate) struct ParsedConfig {
     api_token: Option<String>,
     tls_key: Option<PathBuf>,
     tls_cert: Option<PathBuf>,
+    footer_blurb: Option<String>,
 }
 
 #[derive(Clone)]
@@ -56,6 +57,7 @@ pub struct Config {
     telegram_admin_handle: Option<String>,
     api_token: Option<String>,
     tls: Option<TlsConfig>,
+    footer_blurb: Option<String>,
 }
 
 #[derive(Clone)]
@@ -112,6 +114,7 @@ impl std::fmt::Debug for Config {
             .field("api_token", &"[redacted]")
             .field("tls_key", &"[redacted]")
             .field("tls_cert", &"[redacted]")
+            .field("footer_blurb", &self.footer_blurb)
             .finish()
     }
 }
@@ -135,6 +138,7 @@ impl Config {
             .set_default("api_token", None as Option<&str>)?
             .set_default("tls_key", None as Option<&str>)?
             .set_default("tls_cert", None as Option<&str>)?
+            .set_default("footer_blurb", None as Option<&str>)?
             .add_source(Environment::default())
             .build()?;
 
@@ -172,6 +176,7 @@ impl Config {
             telegram_admin_handle: config.telegram_admin_handle,
             api_token: config.api_token,
             tls,
+            footer_blurb: config.footer_blurb,
         })
     }
 
@@ -214,6 +219,16 @@ impl Config {
         Ok(Some((certs, key)))
     }
 
+    pub(crate) fn footer_blurb(&self) -> Option<crate::templates::Html<&str>> {
+        if let Some(blurb) = &self.footer_blurb {
+            if !blurb.is_empty() {
+                return Some(crate::templates::Html(blurb));
+            }
+        }
+
+        None
+    }
+
     pub(crate) fn sled_path(&self) -> &PathBuf {
         &self.sled_path
     }
diff --git a/templates/index.rs.html b/templates/index.rs.html
index 20c0390..fe5161b 100644
--- a/templates/index.rs.html
+++ b/templates/index.rs.html
@@ -84,6 +84,9 @@ templates::{info, instance, statics::index_css},
     </section>
   </main>
   <footer>
+    @if let Some(blurb) = config.footer_blurb() {
+    <div>@blurb</div>
+    }
     <p>
       The source code for this project can be found at
       <a href="@config.source_code()">@config.source_code()</a>