aienos.com
Source of www.aienos.com, served from my own hardware
Brought by drakestapleton
aienos.com / crates / site-builder / src / components / contact.rs
| 1 | //! Where Drake is and how to reach him: the /contact/ page, the X button in |
| 2 | //! every header, and the contact line in every footer. |
| 3 | //! |
| 4 | //! Generated pages get the header and footer pieces from the navbar and the |
| 5 | //! footer components. Hand-written pages under public/ carry |
| 6 | //! their own copy of the header, so [`enrich`] adds the same markup to them |
| 7 | //! in the shared document pass, and [`verify`] fails the build if any page |
| 8 | //! in dist lacks either piece. The X button is a plain link: no widget, no |
| 9 | //! script and nothing loaded from X. It is the header's only contact entry; |
| 10 | //! the email address lives in the footer line and on /contact/. |
| 11 | |
| 12 | use std::fs; |
| 13 | use std::path::Path; |
| 14 | |
| 15 | use maud::{html, Markup, PreEscaped}; |
| 16 | |
| 17 | use crate::seo::{X_HANDLE, X_URL}; |
| 18 | |
| 19 | pub const TITLE: &str = "Where I am and how to reach me | AienOS"; |
| 20 | pub const DESCRIPTION: &str = "How to reach Drake Stapleton: X @drakestapleton, email drake@aienos.com, Aien (who can pass a message to me or put you through when I'm online) and my repositories on the forge."; |
| 21 | pub const URL: &str = "https://www.aienos.com/contact/"; |
| 22 | pub const PATH: &str = "/contact/"; |
| 23 | pub const EMAIL: &str = "drake@aienos.com"; |
| 24 | pub const ALLEN: &str = "/aien/"; |
| 25 | pub const FORGE: &str = crate::forge::FORGE; |
| 26 | /// The front door: install command, releases and a hub of every part. |
| 27 | pub const SI: &str = "https://interplane.io/drakestapleton/sovereign-intelligence"; |
| 28 | |
| 29 | /// The X mark (Simple Icons, CC0), drawn in the link's text colour. |
| 30 | const X_MARK: &str = r#"<svg class="aien-x-mark" width="13" height="13" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true" focusable="false"><path d="M18.901 1.153h3.68l-8.04 9.19L24 22.846h-7.406l-5.8-7.584-6.638 7.584H.474l8.6-9.83L0 1.154h7.594l5.243 6.932ZM17.61 20.644h2.039L6.486 3.24H4.298Z"/></svg>"#; |
| 31 | |
| 32 | fn x_link() -> Markup { |
| 33 | html! { |
| 34 | a class="aien-x-link" href=(X_URL) target="_blank" rel="me noopener noreferrer" { |
| 35 | (PreEscaped(X_MARK)) |
| 36 | span class="aien-x-label" { "Follow me on X" } |
| 37 | " " |
| 38 | span class="aien-x-handle" translate="no" { (X_HANDLE) } |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | /// The last group of the header nav: one pressable X button, the header's |
| 44 | /// contact entry. Its name is text a reader meets (visually hidden, so the |
| 45 | /// mark is the only thing drawn), which is what [`check_page`] counts. |
| 46 | pub fn nav_reach() -> Markup { |
| 47 | let name = format!("Contact me on X ({X_HANDLE})"); |
| 48 | html! { |
| 49 | ul class="aien-nav-secondary aien-nav-reach" aria-label="Reach me" { |
| 50 | li { |
| 51 | a class="aien-x-link aien-x-button" href=(X_URL) target="_blank" rel="me noopener noreferrer" aria-label=(name) title=(name) { |
| 52 | (PreEscaped(X_MARK)) |
| 53 | span class="aien-x-name" { (name) } |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /// The contact line in the footer: the contact page, then every route. |
| 61 | pub fn footer_reach() -> Markup { |
| 62 | html! { |
| 63 | div class="aien-reach-foot" { |
| 64 | p class="aien-reach-title" { a href=(PATH) { "Where I am and how to reach me" } } |
| 65 | p class="aien-reach-routes" { |
| 66 | (x_link()) |
| 67 | " · " |
| 68 | "Email: " a href=(format!("mailto:{EMAIL}")) { (EMAIL) } |
| 69 | " · " |
| 70 | a href=(ALLEN) { "Talk to Aien" } |
| 71 | " · " |
| 72 | a href=(FORGE) target="_blank" rel="noopener noreferrer" { "Forge: drakestapleton" } |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | /// Adds the header and footer pieces to a page that does not carry them |
| 79 | /// yet (hand-written pages). Idempotent. Panics on a page |
| 80 | /// without the shared header nav: every page must show the X link. |
| 81 | pub fn enrich(mut page: String) -> String { |
| 82 | if !page.contains("aien-nav-reach") { |
| 83 | let nav = page.find("class=\"aien-nav").expect("page carries the shared header nav"); |
| 84 | let end = nav + page[nav..].find("</nav>").expect("shared header nav closes"); |
| 85 | page.insert_str(end, &nav_reach().into_string()); |
| 86 | } |
| 87 | if !page.contains("aien-reach-foot") { |
| 88 | let strip = html! { div class="aien-reach-strip" { (footer_reach()) } }.into_string(); |
| 89 | let end = if page.contains("class=\"aien-footer\"") { page.rfind("</footer>") } else { None } |
| 90 | .or_else(|| page.rfind("</body>")) |
| 91 | .expect("page has a body"); |
| 92 | page.insert_str(end, &strip); |
| 93 | } |
| 94 | page |
| 95 | } |
| 96 | |
| 97 | /// Fails the build unless every HTML page in dist reaches Drake: see |
| 98 | /// [`check_page`]. |
| 99 | pub fn verify(dist: &Path) { |
| 100 | fn walk(dir: &Path, dist: &Path, n: &mut usize) { |
| 101 | for entry in fs::read_dir(dir).expect("read dist directory") { |
| 102 | let path = entry.expect("dist entry").path(); |
| 103 | if path.is_dir() { |
| 104 | walk(&path, dist, n); |
| 105 | } else if path.extension().and_then(|e| e.to_str()) == Some("html") { |
| 106 | let html = fs::read_to_string(&path).expect("read page"); |
| 107 | let rel = path.strip_prefix(dist).expect("page under dist").to_string_lossy().replace('\\', "/"); |
| 108 | check_page(&rel, &html).unwrap_or_else(|e| panic!("{}: {e}", path.display())); |
| 109 | *n += 1; |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | let mut n = 0; |
| 114 | walk(dist, dist, &mut n); |
| 115 | println!(" Follow me on X, contact, email and the way home: {n} pages"); |
| 116 | } |
| 117 | |
| 118 | /// The redesign has no header bar, so the rule is about what a reader can |
| 119 | /// reach, not where a bar sits. Every page (`rel` is its file under dist) |
| 120 | /// has exactly one visible `<main>` and carries, outside comments, scripts, |
| 121 | /// templates, `<noscript>` fallbacks and hidden elements: |
| 122 | /// - an X link (href exactly [`X_URL`], text naming X) placed before that |
| 123 | /// `<main>`, so it is met before the content; |
| 124 | /// - a link to [`PATH`] (/contact/) and to `mailto:` [`EMAIL`]; |
| 125 | /// - a way home (`/`) on every page but the root; |
| 126 | /// - after the last `aien-reach-foot` element, the X link and the email again. |
| 127 | /// |
| 128 | /// The full-screen /allen/ page gets no exception: it carries the same |
| 129 | /// links in its own controls. |
| 130 | pub fn check_page(rel: &str, html: &str) -> Result<(), String> { |
| 131 | use crate::oracle::{anchors, find_class, reachable}; |
| 132 | let visible = reachable(html); |
| 133 | let links = anchors(&visible); |
| 134 | let has = |links: &[(String, String)], href: &str| links.iter().any(|(h, t)| h == href && !t.is_empty()); |
| 135 | let x = |links: &[(String, String)]| links.iter().any(|(h, t)| h == X_URL && t.contains('X')); |
| 136 | if !x(&links) { |
| 137 | return Err("no visible X link".into()); |
| 138 | } |
| 139 | let lower = visible.to_ascii_lowercase(); |
| 140 | let mains: Vec<usize> = lower.match_indices("<main").map(|(i, _)| i).filter(|&i| lower[i + 5..].starts_with(['>', ' ', '\t', '\n', '\r'])).collect(); |
| 141 | let [main] = mains[..] else { |
| 142 | return Err(format!("needs exactly one visible <main>, found {}", mains.len())); |
| 143 | }; |
| 144 | if !x(&anchors(&visible[..main])) { |
| 145 | return Err("the X link must come before the page's <main>".into()); |
| 146 | } |
| 147 | if !has(&links, PATH) { |
| 148 | return Err("no link to the contact page".into()); |
| 149 | } |
| 150 | if !has(&links, &format!("mailto:{EMAIL}")) { |
| 151 | return Err("no email link".into()); |
| 152 | } |
| 153 | let root = rel == "index.html" || rel == "404.html"; |
| 154 | if !root && !has(&links, "/") { |
| 155 | return Err("no link home".into()); |
| 156 | } |
| 157 | let mut foot = None; |
| 158 | let mut from = 0; |
| 159 | while let Some((at, end, _)) = find_class(&visible, from, "aien-reach-foot") { |
| 160 | foot = Some(at); |
| 161 | from = end; |
| 162 | } |
| 163 | let foot = foot.ok_or("no contact line (aien-reach-foot)")?; |
| 164 | let tail = anchors(&visible[foot..]); |
| 165 | if !x(&tail) || !has(&tail, &format!("mailto:{EMAIL}")) { |
| 166 | return Err("the contact line lacks the X link or the email".into()); |
| 167 | } |
| 168 | Ok(()) |
| 169 | } |
| 170 | |
| 171 | fn route(name: &str, link: Markup, text: Markup) -> Markup { |
| 172 | html! { |
| 173 | div class="contact-route" { |
| 174 | dt { (name) } |
| 175 | dd class="contact-route-link" { (link) } |
| 176 | dd class="contact-route-text" { (text) } |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | pub fn render_contact() -> Markup { |
| 182 | html! { |
| 183 | section id="contact" class="contact-page" { |
| 184 | div class="container" style="max-width: 820px;" { |
| 185 | div class="badge badge-blue" style="margin-bottom: 12px;" { "CONTACT" } |
| 186 | h1 { "Where I am and how to reach me" } |
| 187 | p class="contact-lede" { |
| 188 | "I'm Drake Stapleton. I build AienOS alone, with my agents, and I do it in public. Here is every way to find me. Pick the one that suits you." |
| 189 | } |
| 190 | dl class="contact-routes" { |
| 191 | (route("X", html! { |
| 192 | a href=(X_URL) target="_blank" rel="me noopener noreferrer" { (PreEscaped(X_MARK)) " " (X_HANDLE) } |
| 193 | }, html! { |
| 194 | "Where I post the work as it happens. Follow me, reply or mention me." |
| 195 | })) |
| 196 | (route("Email", html! { |
| 197 | a href=(format!("mailto:{EMAIL}")) { (EMAIL) } |
| 198 | }, html! { |
| 199 | "For anything longer than a post, or anything private." |
| 200 | })) |
| 201 | (route("Talk to Aien", html! { |
| 202 | a href=(ALLEN) { "aienos.com/aien/" } |
| 203 | }, html! { |
| 204 | "Aien is my AI. Aien can pass a message to me, or put you through to me when I'm online." |
| 205 | })) |
| 206 | (route("Forge", html! { |
| 207 | a href=(FORGE) target="_blank" rel="noopener noreferrer" { "interplane.io/drakestapleton" } |
| 208 | }, html! { |
| 209 | "My code is on my forge, Interplane, served from my own hardware. Its project pages are being rebuilt and are not open yet." |
| 210 | })) |
| 211 | (route("Sovereign Intelligence", html! { |
| 212 | a href=(SI) target="_blank" rel="noopener noreferrer" { "interplane.io/drakestapleton/sovereign-intelligence" } |
| 213 | }, html! { |
| 214 | "The front door to everything I build: the install command, the releases and a link to every part. Sovereign Intelligence, built on AienOS." |
| 215 | })) |
| 216 | } |
| 217 | p class="contact-note" { |
| 218 | "Want to see what I'm doing right now? " |
| 219 | a href="/hive/" { "Watch me and my agents work in Hive" } |
| 220 | ", or read " |
| 221 | a href="/now/" { "the live ledger" } |
| 222 | "." |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | #[cfg(test)] |
| 230 | mod tests { |
| 231 | use super::*; |
| 232 | |
| 233 | const HAND_WRITTEN: &str = "<html><head></head><body><header class=\"aien-header\"><div class=\"aien-header-inner\"><a class=\"aien-brand\" href=\"/\">AienOS</a><nav aria-label=\"x\" class=\"aien-nav\"><ul class=\"aien-nav-primary\"></ul></nav></div></header><main>text</main><footer>own footer</footer></body></html>"; |
| 234 | |
| 235 | /// The redesign's shape: no header bar, a small utility with the X link |
| 236 | /// before the content, a quiet footer with every route. |
| 237 | const REDESIGN: &str = "<body><div class=\"quiet-utility\"><a href=\"/\">SI</a> <a class=\"x-link\" href=\"https://x.com/drakestapleton\"><span aria-hidden=\"true\">X</span> Follow me on X</a></div><main id=\"main-content\">body</main><footer><p class=\"aien-reach-foot\"><a href=\"https://x.com/drakestapleton\">X @drakestapleton</a> <a href=\"mailto:drake@aienos.com\">drake@aienos.com</a> <a href=\"/contact/\">Contact</a></p></footer></body>"; |
| 238 | |
| 239 | #[test] |
| 240 | fn enrich_adds_the_header_link_and_footer_line_once() { |
| 241 | let once = enrich(HAND_WRITTEN.to_string()); |
| 242 | check_page("turing/index.html", &once).expect("enriched page passes the check"); |
| 243 | assert_eq!(enrich(once.clone()), once, "enrich must be idempotent"); |
| 244 | assert!(once.find("aien-nav-reach").unwrap() < once.find("</nav>").unwrap(), "reach group sits inside the nav"); |
| 245 | assert!(once.find("aien-reach-strip").unwrap() > once.find("own footer").unwrap(), "footer line follows the page"); |
| 246 | assert!(once.contains("Follow me on X")); |
| 247 | } |
| 248 | |
| 249 | #[test] |
| 250 | fn enrich_puts_the_footer_line_inside_a_shared_footer() { |
| 251 | let page = enrich(HAND_WRITTEN.replace("<footer>own footer</footer>", "<footer class=\"aien-footer\"><div>x</div></footer>")); |
| 252 | check_page("turing/index.html", &page).expect("enriched page passes the check"); |
| 253 | assert!(page.find("aien-reach-strip").unwrap() < page.rfind("</footer>").unwrap(), "inside the shared footer"); |
| 254 | } |
| 255 | |
| 256 | #[test] |
| 257 | fn the_redesign_without_a_header_bar_passes() { |
| 258 | check_page("omega/index.html", REDESIGN).expect("semantic reach without a header"); |
| 259 | check_page("allen/index.html", REDESIGN).expect("/allen/ meets the same rule, no exception"); |
| 260 | check_page("index.html", &REDESIGN.replace("<a href=\"/\">SI</a>", "")).expect("the root needs no way home"); |
| 261 | } |
| 262 | |
| 263 | #[test] |
| 264 | fn a_page_without_the_link_fails_the_check() { |
| 265 | let r = REDESIGN; |
| 266 | let first_x = "<a class=\"x-link\" href=\"https://x.com/drakestapleton\"><span aria-hidden=\"true\">X</span> Follow me on X</a>"; |
| 267 | let cases = [ |
| 268 | ("hand-written page not enriched", "turing/index.html", HAND_WRITTEN.to_string()), |
| 269 | ("no X link before the content", "omega/index.html", r.replace(first_x, "")), |
| 270 | ("X link only after main", "omega/index.html", r.replace(first_x, "").replace("<main id=\"main-content\">body</main>", &format!("<main id=\"main-content\">body</main>{first_x}"))), |
| 271 | ("X link whose text never names X", "omega/index.html", r.replace(first_x, "<a href=\"https://x.com/drakestapleton\"><span aria-hidden=\"true\">X</span> Follow me</a>")), |
| 272 | ("X link hidden from readers", "omega/index.html", r.replace("<div class=\"quiet-utility\">", "<div class=\"quiet-utility\" aria-hidden=\"true\">")), |
| 273 | ("X link only in a script", "omega/index.html", r.replace(first_x, &format!("<script>var s='{first_x}'</script>"))), |
| 274 | ("no contact page link", "omega/index.html", r.replace("<a href=\"/contact/\">Contact</a>", "")), |
| 275 | ("contact link with no text", "omega/index.html", r.replace("<a href=\"/contact/\">Contact</a>", "<a href=\"/contact/\"></a>")), |
| 276 | ("no email", "omega/index.html", r.replace("<a href=\"mailto:drake@aienos.com\">drake@aienos.com</a>", "")), |
| 277 | ("no way home", "omega/index.html", r.replace("<a href=\"/\">SI</a>", "")), |
| 278 | ("/allen/ without a way home", "allen/index.html", r.replace("<a href=\"/\">SI</a>", "")), |
| 279 | ("/allen/ without email", "allen/index.html", r.replace("<a href=\"mailto:drake@aienos.com\">drake@aienos.com</a>", "")), |
| 280 | ("no contact line", "omega/index.html", r.replace("class=\"aien-reach-foot\"", "class=\"foot\"")), |
| 281 | ("contact line lacks the X link", "omega/index.html", r.replace("<a href=\"https://x.com/drakestapleton\">X @drakestapleton</a>", "")), |
| 282 | ("no <main> at all, so nothing to come before", "omega/index.html", r.replace("<main id=\"main-content\">body</main>", "<div>body</div>")), |
| 283 | ("only <main> is hidden", "omega/index.html", r.replace("<main id=\"main-content\">", "<main id=\"main-content\" hidden>")), |
| 284 | ("two <main> elements", "omega/index.html", r.replace("<footer>", "<main>more</main><footer>")), |
| 285 | ("<main> only inside a comment", "omega/index.html", r.replace("<main id=\"main-content\">body</main>", "<!-- <main> -->body")), |
| 286 | ("X link only inside a comment", "omega/index.html", r.replace(first_x, &format!("<!-- {first_x} -->"))), |
| 287 | ("X link only in the noscript fallback", "omega/index.html", r.replace(first_x, &format!("<noscript>{first_x}</noscript>"))), |
| 288 | ("X link in a hidden element", "omega/index.html", r.replace("<div class=\"quiet-utility\">", "<div class=\"quiet-utility\" hidden>")), |
| 289 | ("404 without a <main>", "404.html", r.replace("<main id=\"main-content\">body</main>", "<div>body</div>")), |
| 290 | ]; |
| 291 | for (what, rel, html) in cases { |
| 292 | assert!(check_page(rel, &html).is_err(), "must reject: {what}"); |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | #[test] |
| 297 | fn the_page_lists_every_route() { |
| 298 | let html = render_contact().into_string(); |
| 299 | for needle in [ |
| 300 | "<h1>Where I am and how to reach me</h1>", |
| 301 | "href=\"https://x.com/drakestapleton\"", |
| 302 | "@drakestapleton", |
| 303 | "href=\"mailto:drake@aienos.com\"", |
| 304 | "href=\"/aien/\"", |
| 305 | "href=\"https://interplane.io/drakestapleton\"", |
| 306 | "href=\"https://interplane.io/drakestapleton/sovereign-intelligence\"", |
| 307 | ] { |
| 308 | assert!(html.contains(needle), "contact page lacks {needle}"); |
| 309 | } |
| 310 | assert!(!html.contains('\u{2014}') && !html.contains('\u{2013}')); |
| 311 | assert!(!html.contains("<script"), "the X link is a plain link"); |
| 312 | } |
| 313 | } |