From a77a4cde225626f2763944f8adfd8116fe5a17ef Mon Sep 17 00:00:00 2001
From: asonix
Date: Mon, 21 Nov 2022 14:23:37 -0600
Subject: [PATCH] Add an 'About' section to the relay
---
.env | 6 +++++
README.md | 8 +++++-
scss/index.scss | 22 ++++++++++-----
src/config.rs | 31 +++++++++++++++++++++
src/routes/index.rs | 26 ++++++++++++++++--
templates/admin.rs.html | 22 +++++++--------
templates/index.rs.html | 55 +++++++++++++++++++++++++++++---------
templates/info.rs.html | 20 +++++++-------
templates/instance.rs.html | 54 ++++++++++++++++++-------------------
9 files changed, 174 insertions(+), 70 deletions(-)
diff --git a/.env b/.env
index b28a8c6..6fb6351 100644
--- a/.env
+++ b/.env
@@ -1,6 +1,12 @@
HOSTNAME=localhost:8079
PORT=8079
+HTTPS=false
+DEBUG=true
RESTRICTED_MODE=true
+VALIDATE_SIGNATURES=false
API_TOKEN=somesecretpassword
FOOTER_BLURB="Contact @asonix for inquiries"
+LOCAL_DOMAINS="masto.asonix.dog"
+LOCAL_BLURB="Welcome to my cool relay where I have cool relay things happening. I hope you enjoy your stay!
"
+RUST_LOG=info
# OPENTELEMETRY_URL=http://localhost:4317
diff --git a/README.md b/README.md
index 273f3bc..64d873e 100644
--- a/README.md
+++ b/README.md
@@ -100,7 +100,9 @@ TELEGRAM_TOKEN=secret
TELEGRAM_ADMIN_HANDLE=your_handle
TLS_KEY=/path/to/key
TLS_CERT=/path/to/cert
-FOOTER_BLURB="Contact @asonix
+FOOTER_BLURB="Contact @asonix for inquiries"
+LOCAL_DOMAINS=masto.asonix.dog
+LOCAL_BLURB="Welcome to my cool relay where I have cool relay things happening. I hope you enjoy your stay!
"
```
#### Descriptions
@@ -140,6 +142,10 @@ Optional - This is specified if you are running the relay directly on the intern
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
+##### `LOCAL_DOMAINS`
+Optional - domains of mastodon servers run by the same admin as the relay
+##### `LOCAL_BLURB`
+Optional - description for the relay
### Subscribing
Mastodon admins can subscribe to this relay by adding the `/inbox` route to their relay settings.
diff --git a/scss/index.scss b/scss/index.scss
index d5e1e50..02baa93 100644
--- a/scss/index.scss
+++ b/scss/index.scss
@@ -41,7 +41,7 @@ header {
}
}
-section {
+article {
background-color: #fff;
color: #333;
border: 1px solid #e5e5e5;
@@ -51,8 +51,16 @@ section {
max-width: 700px;
padding-bottom: 32px;
- > p:first-child {
- margin-top: 0;
+ section {
+ border-bottom: 1px solid #e5e5e5;
+
+ > h4:first-child,
+ > p:first-child {
+ margin-top: 0;
+ }
+ > p:last-child {
+ margin-bottom: 0;
+ }
}
h3 {
@@ -67,13 +75,13 @@ section {
li {
padding-top: 36px;
- border-bottom: 1px solid #e5e5e5;
}
.padded {
padding: 0 24px;
}
+ .local-explainer,
.joining {
padding: 24px;
}
@@ -174,9 +182,11 @@ footer {
li {
padding: 0;
- border-bottom: none;
}
}
+ article section {
+ border-bottom: none;
+ }
}
}
@@ -226,7 +236,7 @@ footer {
padding: 24px;
}
- section {
+ article {
border-left: none;
border-right: none;
border-radius: 0;
diff --git a/src/config.rs b/src/config.rs
index b1da0cc..884a30f 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -38,6 +38,8 @@ pub(crate) struct ParsedConfig {
tls_key: Option,
tls_cert: Option,
footer_blurb: Option,
+ local_domains: Option,
+ local_blurb: Option,
}
#[derive(Clone)]
@@ -58,6 +60,8 @@ pub struct Config {
api_token: Option,
tls: Option,
footer_blurb: Option,
+ local_domains: Vec,
+ local_blurb: Option,
}
#[derive(Clone)]
@@ -115,6 +119,8 @@ impl std::fmt::Debug for Config {
.field("tls_key", &"[redacted]")
.field("tls_cert", &"[redacted]")
.field("footer_blurb", &self.footer_blurb)
+ .field("local_domains", &self.local_domains)
+ .field("local_blurb", &self.local_blurb)
.finish()
}
}
@@ -139,6 +145,8 @@ impl Config {
.set_default("tls_key", None as Option<&str>)?
.set_default("tls_cert", None as Option<&str>)?
.set_default("footer_blurb", None as Option<&str>)?
+ .set_default("local_domains", None as Option<&str>)?
+ .set_default("local_blurb", None as Option<&str>)?
.add_source(Environment::default())
.build()?;
@@ -160,6 +168,13 @@ impl Config {
(None, None) => None,
};
+ let local_domains = config
+ .local_domains
+ .iter()
+ .flat_map(|s| s.split(","))
+ .map(|d| d.to_string())
+ .collect();
+
Ok(Config {
hostname: config.hostname,
addr: config.addr,
@@ -177,6 +192,8 @@ impl Config {
api_token: config.api_token,
tls,
footer_blurb: config.footer_blurb,
+ local_domains,
+ local_blurb: config.local_blurb,
})
}
@@ -229,6 +246,20 @@ impl Config {
None
}
+ pub(crate) fn local_blurb(&self) -> Option> {
+ if let Some(blurb) = &self.local_blurb {
+ if !blurb.is_empty() {
+ return Some(crate::templates::Html(blurb));
+ }
+ }
+
+ None
+ }
+
+ pub(crate) fn local_domains(&self) -> &[String] {
+ &self.local_domains
+ }
+
pub(crate) fn sled_path(&self) -> &PathBuf {
&self.sled_path
}
diff --git a/src/routes/index.rs b/src/routes/index.rs
index 4e141d7..f243d8b 100644
--- a/src/routes/index.rs
+++ b/src/routes/index.rs
@@ -20,7 +20,29 @@ pub(crate) async fn route(
state: web::Data,
config: web::Data,
) -> Result {
- let mut nodes = state.node_cache().nodes().await?;
+ let all_nodes = state.node_cache().nodes().await?;
+
+ let mut nodes = Vec::new();
+ let mut local = Vec::new();
+
+ for node in all_nodes {
+ if node
+ .base
+ .authority_str()
+ .map(|authority| {
+ config
+ .local_domains()
+ .iter()
+ .find(|domain| domain.as_str() == authority)
+ .is_some()
+ })
+ .unwrap_or(false)
+ {
+ local.push(node);
+ } else {
+ nodes.push(node);
+ }
+ }
nodes.sort_by(|lhs, rhs| match (open_reg(lhs), open_reg(rhs)) {
(true, true) | (false, false) => std::cmp::Ordering::Equal,
@@ -37,7 +59,7 @@ pub(crate) async fn route(
let mut buf = BufWriter::new(Vec::new());
- crate::templates::index(&mut buf, &nodes, &config)?;
+ crate::templates::index(&mut buf, &local, &nodes, &config)?;
let buf = buf.into_inner().map_err(|e| {
tracing::error!("Error rendering template, {}", e.error());
ErrorKind::FlushBuffer
diff --git a/templates/admin.rs.html b/templates/admin.rs.html
index e9d89aa..1af6bc2 100644
--- a/templates/admin.rs.html
+++ b/templates/admin.rs.html
@@ -4,15 +4,15 @@
@(contact: &Contact, base: &IriString)
-
-
-
-
-
-
-
@contact.display_name
-
- @@@contact.username@if let Some(authority) = base.authority_str() {@@@authority}
-
-
+
+
+
+
+
+
+
@contact.display_name
+
+ @@@contact.username@if let Some(authority) = base.authority_str() {@@@authority}
+
+
diff --git a/templates/index.rs.html b/templates/index.rs.html
index fe5161b..9f03c22 100644
--- a/templates/index.rs.html
+++ b/templates/index.rs.html
@@ -4,7 +4,7 @@ data::Node,
templates::{info, instance, statics::index_css},
};
-@(nodes: &[Node], config: &Config)
+@(local: &[Node], nodes: &[Node], config: &Config)
@@ -24,16 +24,23 @@ templates::{info, instance, statics::index_css},
-
- @nodes.len() Connected Servers
- @if nodes.is_empty() {
- There are no connected servers at this time.
- } else {
+ @if !local.is_empty() || config.local_blurb().is_some() {
+
+ About
+
+ @if let Some(blurb) = config.local_blurb() {
+ @blurb
+ } else {
+ These domains are run by the same admins as this relay.
+ }
+
+ @if !local.is_empty() {
- @for node in nodes {
+ @for node in local {
@if let Some(inst) = node.instance.as_ref() {
- @:instance(inst, node.info.as_ref().map(|info| { info.software.as_ref() }), node.contact.as_ref(), &node.base)
+ @:instance(inst, node.info.as_ref().map(|info| { info.software.as_ref() }), node.contact.as_ref(),
+ &node.base)
} else {
@if let Some(inf) = node.info.as_ref() {
@@ -45,10 +52,32 @@ templates::{info, instance, statics::index_css},
}
}
-
-
+
+ }
+ @if !nodes.is_empty() {
+
+ @nodes.len() Connected Servers
+
+ @for node in nodes {
+ @if let Some(inst) = node.instance.as_ref() {
+
+ @:instance(inst, node.info.as_ref().map(|info| { info.software.as_ref() }), node.contact.as_ref(),
+ &node.base)
+
+ } else {
+ @if let Some(inf) = node.info.as_ref() {
+
+ @:info(inf, &node.base)
+
+ }
+ }
+ }
+
+
+ }
+
Joining
-
+
@if config.restricted_mode() {
This relay is Restricted
@@ -80,8 +109,8 @@ templates::{info, instance, statics::index_css},
Consult the documentation for your server. It's likely that it follows either
Mastodon or Pleroma's relay formatting.
-
-
+
+