~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

A host's operator sets the colour that acts, and a cooler set of colours

Merged chadtmiller.com asked to merge into feature/branding from chadtmiller.com/group-host:branding/colours
.changeset/host-colours.mdnew+7−0
@@ -0,0 +1,7 @@
---
default: minor
---
# A host's operator sets the colour that acts, and a cooler set of colours
`PRIMARY_COLOR` and `PRIMARY_COLOR_DARK`, each `#rgb` or `#rrggbb`, make the console's buttons, links and marks the operator's colour, with their hover, wash and link line mixed from it and the text on a button whichever of white or the page's ink reads better. Without a dark one, the light one is lifted lighter. `THEME=slate` sets the rest of the console, its paper, cards, lines and ink, cool rather than warm. `getBrand` answers them as `colors` and `theme`; the host refuses to start on any other colour or theme.
crates/group-host/src/brand.rs+7−2
@@ -27,10 +27,11 @@ pub(crate) fn set<const N: usize>(fields: [(&str, &Option<String>); N]) -> Value
}
/// How the host shows itself: its name and logo, the links to its
/// operator's pages, and its backgrounds, each only when set.
/// operator's pages, its backgrounds, its colours and the console's set of
/// colours it's in, each only when set.
pub async fn get_brand(State(host): State<Arc<Host>>) -> Json<Value> {
let b = &host.config.brand;
let mut brand = set([("name", &b.name), ("logo", &b.logo)]);
let mut brand = set([("name", &b.name), ("logo", &b.logo), ("theme", &b.theme)]);
brand["links"] = set([
("home", &b.home),
("privacyPolicy", &b.privacy_policy),
@@ -38,6 +39,10 @@ pub async fn get_brand(State(host): State<Arc<Host>>) -> Json<Value> {
("support", &b.support),
]);
brand["backgrounds"] = set([("light", &b.background_light), ("dark", &b.background_dark)]);
brand["colors"] = set([
("primary", &b.primary_color),
("primaryDark", &b.primary_color_dark),
]);
Json(brand)
}
crates/group-host/src/config.rs+34−0
@@ -112,11 +112,23 @@ pub struct Brand {
pub background_light: Option<String>,
/// And in a dark one, `BACKGROUND_DARK_URL`, at `/img/background-dark`.
pub background_dark: Option<String>,
/// The colour of what acts on its pages, `PRIMARY_COLOR`, as `#rrggbb`
/// or `#rgb`, lower case.
pub primary_color: Option<String>,
/// The same in a dark colour scheme, `PRIMARY_COLOR_DARK`: unset, the
/// console lifts `primary_color` lighter.
pub primary_color_dark: Option<String>,
/// Which of the console's sets of colours its pages are in, `THEME`,
/// one of [`THEMES`] but the first, `paper`, which is none.
pub theme: Option<String>,
}
/// The most characters a host's name may be, as a page's header has room for.
pub const NAME_AT_MOST: usize = 40;
/// The console's sets of colours, its own first.
pub const THEMES: [&str; 2] = ["paper", "slate"];
impl Brand {
/// The brand `var` names, each variable left empty as unset.
fn from(var: &impl Fn(&str) -> Option<String>) -> Result<Brand> {
@@ -142,6 +154,25 @@ impl Brand {
if let Some(e) = contact_email.as_ref().filter(|e| !e.contains('@')) {
bail!("CONTACT_EMAIL is no email address: {e}");
}
// Only a colour as #rgb or #rrggbb: one the console writes into its
// styles as it is.
let colour = |name: &str| -> Result<Option<String>> {
let Some(c) = set(name) else {
return Ok(None);
};
let hex =
|h: &&str| [3, 6].contains(&h.len()) && h.chars().all(|d| d.is_ascii_hexdigit());
match c.strip_prefix('#').filter(hex) {
Some(_) => Ok(Some(c.to_ascii_lowercase())),
None => bail!("{name} is a colour as #rgb or #rrggbb, not {c}"),
}
};
let theme = match set("THEME") {
Some(t) if !THEMES.contains(&t.as_str()) => {
bail!("THEME is one of {}, not {t}", THEMES.join(", "))
}
t => t.filter(|t| t != THEMES[0]),
};
Ok(Brand {
name,
logo: page("LOGO_URL")?,
@@ -152,6 +183,9 @@ impl Brand {
contact_email,
background_light: page("BACKGROUND_LIGHT_URL")?,
background_dark: page("BACKGROUND_DARK_URL")?,
primary_color: colour("PRIMARY_COLOR")?,
primary_color_dark: colour("PRIMARY_COLOR_DARK")?,
theme,
})
}
}
crates/group-host/tests/brand.rs+5−1
@@ -25,7 +25,7 @@ async fn a_host_named_nothing_shows_the_consoles_own() {
let h = start(&[], false).await;
let (status, brand) = h.get("org.atgrp.internal.getBrand", "").await;
assert_eq!(status, 200, "{brand}");
assert_eq!(brand, json!({"links": {}, "backgrounds": {}}));
assert_eq!(brand, json!({"links": {}, "backgrounds": {}, "colors": {}}));
let (status, described) = h.get("com.atproto.server.describeServer", "").await;
assert_eq!(status, 200, "{described}");
assert_eq!(described["links"], json!({}));
@@ -90,6 +90,8 @@ async fn a_host_shows_its_operators_name_logo_and_pages() {
("TERMS_OF_SERVICE_URL", "https://riverside.example/terms"),
("SUPPORT_URL", "https://riverside.example/help"),
("CONTACT_EMAIL", "hello@riverside.example"),
("PRIMARY_COLOR", "#0F766E"),
("THEME", "slate"),
])
.await;
@@ -100,6 +102,7 @@ async fn a_host_shows_its_operators_name_logo_and_pages() {
json!({
"name": "Riverside Groups",
"logo": logo_url,
"theme": "slate",
"links": {
"home": "https://riverside.example",
"privacyPolicy": "https://riverside.example/privacy",
@@ -107,6 +110,7 @@ async fn a_host_shows_its_operators_name_logo_and_pages() {
"support": "https://riverside.example/help",
},
"backgrounds": {},
"colors": {"primary": "#0f766e"},
})
);
crates/group-host/tests/config.rs+18−0
@@ -204,6 +204,9 @@ fn the_host_shows_itself_as_its_operator_names_it() {
"https://riverside.example/light.jpg",
),
("BACKGROUND_DARK_URL", "https://riverside.example/dark.jpg"),
("PRIMARY_COLOR", "#0F766E"),
("PRIMARY_COLOR_DARK", "#2dd"),
("THEME", "slate"),
])
.unwrap();
let some = |s: &str| Some(s.to_string());
@@ -219,6 +222,9 @@ fn the_host_shows_itself_as_its_operator_names_it() {
contact_email: some("hello@riverside.example"),
background_light: some("https://riverside.example/light.jpg"),
background_dark: some("https://riverside.example/dark.jpg"),
primary_color: some("#0f766e"),
primary_color_dark: some("#2dd"),
theme: some("slate"),
}
);
@@ -240,4 +246,16 @@ fn the_host_shows_itself_as_its_operator_names_it() {
err(&[("CONTACT_EMAIL", "riverside.example")]),
"CONTACT_EMAIL is no email address: riverside.example"
);
for colour in ["teal", "#0f766", "0f766e", "#0f766g"] {
assert_eq!(
err(&[("PRIMARY_COLOR", colour)]),
format!("PRIMARY_COLOR is a colour as #rgb or #rrggbb, not {colour}")
);
}
assert_eq!(
err(&[("THEME", "neon")]),
"THEME is one of paper, slate, not neon"
);
// The console's own set of colours is no set at all.
assert_eq!(config(&[("THEME", "paper")]).unwrap().brand.theme, None);
}
deploy/docker-compose.yml+3−0
@@ -54,6 +54,9 @@ services:
CONTACT_EMAIL: ${GROUP_HOST_CONTACT_EMAIL:-}
BACKGROUND_LIGHT_URL: ${GROUP_HOST_BACKGROUND_LIGHT_URL:-}
BACKGROUND_DARK_URL: ${GROUP_HOST_BACKGROUND_DARK_URL:-}
PRIMARY_COLOR: ${GROUP_HOST_PRIMARY_COLOR:-}
PRIMARY_COLOR_DARK: ${GROUP_HOST_PRIMARY_COLOR_DARK:-}
THEME: ${GROUP_HOST_THEME:-}
volumes:
# The database, blobs and keys: back it up (docs/deploying.md).
# Owned by uid 1000, the node user the image runs as.
docs/reference/api.md+1−1
@@ -312,7 +312,7 @@ Moving groups between hosts, and accounts here to become groups ([moving](../des
| `POST /console/switch` | switches to another account the browser is signed in to (`did`), and goes back to the page `back` |
| `GET /console/move/login`, `GET /console/move/callback` | signs in to an account to move here |
| `GET /console/client-metadata.json` | the host's metadata as the console's OAuth client, a confidential web client's as atproto's profile has one; 500 where `CONSOLE_URL` cannot be one (not https at a public name) |
| `GET org.atgrp.internal.getBrand` | how the host shows itself, as its operator names it ([config](config.md#how-it-shows-itself)): its `name`, its `logo`, `links` to its operator's home page, privacy policy, terms of service and support, and the `backgrounds` of the page an app's request is approved on, light and dark, each only when set. Anyone may ask |
| `GET org.atgrp.internal.getBrand` | how the host shows itself, as its operator names it ([config](config.md#how-it-shows-itself)): its `name`, its `logo`, `links` to its operator's home page, privacy policy, terms of service and support, the `backgrounds` of the page an app's request is approved on, light and dark, its `colors`, and the console's set of colours it's in (`theme`), each only when set. Anyone may ask |
| `GET /img/host`, `GET /img/background-light`, `GET /img/background-dark` | serve the host's logo (`LOGO_URL`) and backgrounds (`BACKGROUND_LIGHT_URL`, `BACKGROUND_DARK_URL`), as `/img/app` serves an app's logo: from a public address, only a PNG, JPEG, GIF or WebP image, of at most 256 KiB for the logo and 2 MiB for a background, kept for 10 minutes. Each answers 404 when the host has none, or when what it names is no such image |
## The PDS
docs/reference/config.md+3−0
@@ -72,3 +72,6 @@ the host (`getBrand`), so they are set on the host alone.
| `HOME_URL`, `PRIVACY_POLICY_URL`, `TERMS_OF_SERVICE_URL`, `SUPPORT_URL` | `http` or `https` URLs of the operator's pages, linked from the console's footer and from the foot of the page an app's request is approved on. `describeServer` names the privacy policy and terms of service in its `links` |
| `CONTACT_EMAIL` | an email address for the operator, which `describeServer` gives as its `contact` |
| `BACKGROUND_LIGHT_URL`, `BACKGROUND_DARK_URL` | `http` or `https` URLs of the pictures behind the card an app's request is approved on, by the reader's colour scheme, either standing in for the other when one is unset. Each is a PNG, JPEG, GIF or WebP image of at most 2 MiB, read as the logo is and served at `/img/background-light` and `/img/background-dark`. It's drawn to cover the screen, cut at its edges, under an opaque card: one about 2000 pixels wide, with nothing that matters at its edges, reads at any size |
| `PRIMARY_COLOR` | the colour of what acts on the console's pages, its buttons, links and marks, as `#rgb` or `#rrggbb`. Their hover, the soft wash behind what they mark and the line under links are mixed from it, and the text on a button is white or the page's ink, whichever reads better on it |
| `PRIMARY_COLOR_DARK` | the same in a dark colour scheme. Unset, it's `PRIMARY_COLOR` lifted to a lightness dark ink reads on |
| `THEME` | the console's set of colours for everything else, its paper, cards, lines and ink: `paper`, its own warm one, or `slate`, a cool one |
docs/deploying.md+1−1
@@ -84,7 +84,7 @@ Compose reads these and passes each to the host under the name the host knows:
| `GROUP_HOST_ADMINS` | `HOST_ADMINS`, the operators who read its logs and stats | none |
| `GROUP_HOST_LOGS_KEEP` | `LOGS_KEEP` | `500000` |
| `GROUP_HOST_RATE_LIMITS` | `RATE_LIMITS`, `on` or `off` ([limits](design/limits.md)) | `on` |
| `GROUP_HOST_SERVICE_NAME`, `GROUP_HOST_LOGO_URL`, `GROUP_HOST_HOME_URL`, `GROUP_HOST_PRIVACY_POLICY_URL`, `GROUP_HOST_TERMS_OF_SERVICE_URL`, `GROUP_HOST_SUPPORT_URL`, `GROUP_HOST_CONTACT_EMAIL`, `GROUP_HOST_BACKGROUND_LIGHT_URL`, `GROUP_HOST_BACKGROUND_DARK_URL` | the same without `GROUP_HOST_`, how the host shows itself ([config](reference/config.md#how-it-shows-itself)) | the console's own name, no logo, links or backgrounds |
| `GROUP_HOST_SERVICE_NAME`, `GROUP_HOST_LOGO_URL`, `GROUP_HOST_HOME_URL`, `GROUP_HOST_PRIVACY_POLICY_URL`, `GROUP_HOST_TERMS_OF_SERVICE_URL`, `GROUP_HOST_SUPPORT_URL`, `GROUP_HOST_CONTACT_EMAIL`, `GROUP_HOST_BACKGROUND_LIGHT_URL`, `GROUP_HOST_BACKGROUND_DARK_URL`, `GROUP_HOST_PRIMARY_COLOR`, `GROUP_HOST_PRIMARY_COLOR_DARK`, `GROUP_HOST_THEME` | the same without `GROUP_HOST_`, how the host shows itself ([config](reference/config.md#how-it-shows-itself)) | the console's own name and colours, no logo, links or backgrounds |
| `GROUP_HOST_DATA` | the directory mounted at `/data` | `/var/lib/group-host` |
| `GROUP_HOST_PROXY_NETWORK` | the proxy's docker network | `group-host` |
lexicons/org/atgrp/internal/getBrand.json+27−1
@@ -13,7 +13,7 @@
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["links", "backgrounds"],
"required": ["links", "backgrounds", "colors"],
"properties": {
"name": {
"type": "string",
@@ -26,6 +26,12 @@
"format": "uri",
"description": "Its logo (LOGO_URL), which the host serves at /img/host, as a page is to draw it; absent when it has none."
},
"theme": {
"type": "string",
"knownValues": ["paper", "slate"],
"maxLength": 64,
"description": "Which of the console's sets of colours its pages are in (THEME); absent for the console's own, paper."
},
"links": {
"type": "ref",
"ref": "#links"
@@ -33,6 +39,10 @@
"backgrounds": {
"type": "ref",
"ref": "#backgrounds"
},
"colors": {
"type": "ref",
"ref": "#colors"
}
}
}
@@ -64,6 +74,22 @@
}
}
},
"colors": {
"type": "object",
"description": "The colour of what acts on its pages, each as #rrggbb or #rgb, absent when not set.",
"properties": {
"primary": {
"type": "string",
"maxLength": 7,
"description": "In a light colour scheme, and in a dark one unless primaryDark is set (PRIMARY_COLOR)."
},
"primaryDark": {
"type": "string",
"maxLength": 7,
"description": "In a dark colour scheme (PRIMARY_COLOR_DARK)."
}
}
},
"backgrounds": {
"type": "object",
"description": "The pictures behind the card an app's request is approved on, by colour scheme, each absent when not set.",
web/src/lib/brand.ts+62−2
web/src/routes/+layout.svelte+9−0
web/src/tokens.css+54−0