aienos.com
Source of www.aienos.com, served from my own hardware
Brought by drakestapleton
aienos.com / crates / site-builder / src / components / navbar.rs
| 1 | use maud::{html, Markup, PreEscaped}; |
| 2 | |
| 3 | /// The six destinations of the site, in reading order (the approved Omega |
| 4 | /// redesign, 2026-10-26): Sovereign Intelligence in its classic readable |
| 5 | /// form, then Omega, the Machine, Discoveries, Learn and Aien. The root is |
| 6 | /// Aien's native front door and the redesign has no top nav bar; every page |
| 7 | /// still links all six, in this order, somewhere a reader can reach (a quiet |
| 8 | /// index or footer). [`check_destinations`] holds every page in dist to that. |
| 9 | pub const NAV_PRIMARY: [(&str, &str); 6] = [ |
| 10 | ("SI", "/classic/"), |
| 11 | ("Omega", "/omega/"), |
| 12 | ("Machine", "/machine/"), |
| 13 | ("Discoveries", "/discoveries/"), |
| 14 | ("Learn", "/learn/"), |
| 15 | ("Aien", "/aien/"), |
| 16 | ]; |
| 17 | |
| 18 | /// Secondary links: behind the "More" menu button at the end of the row. |
| 19 | /// Omega is one of the six destinations, so it is not repeated here. |
| 20 | pub const NAV_SECONDARY: [(&str, &str); 11] = [ |
| 21 | ("Sovereign Intelligence", "/alpha/"), |
| 22 | ("Lab", "/lab/"), |
| 23 | ("Start here", "/start/"), |
| 24 | ("Agora", "/agora/"), |
| 25 | ("Agents", "/agents/"), |
| 26 | ("CUDA++", "/cudaplusplus/"), |
| 27 | ("Now", "/now/"), |
| 28 | ("Progress", "/progress/"), |
| 29 | ("Blog", "/blog"), |
| 30 | ("Follow", "/#follow"), |
| 31 | ("Forge", "https://interplane.io/drakestapleton"), |
| 32 | ]; |
| 33 | |
| 34 | /// Every page links the six [`NAV_PRIMARY`] dashboards, in order, each an |
| 35 | /// `<a>` with exactly that href and that reader-visible label, among the |
| 36 | /// links a reader can reach (scripts, templates and `aria-hidden` content |
| 37 | /// do not count). Where they sit (a quiet index, a footer) and the markup |
| 38 | /// around them are free, and other links may come between them. |
| 39 | pub fn check_destinations(html: &str) -> Result<(), String> { |
| 40 | let links = crate::oracle::anchors(&crate::oracle::reachable(html)); |
| 41 | let mut next = 0usize; |
| 42 | for (label, href) in NAV_PRIMARY { |
| 43 | let at = links[next..] |
| 44 | .iter() |
| 45 | .position(|(h, t)| h == href && t == label) |
| 46 | .ok_or(format!("destination {label} ({href}) missing, hidden or out of order"))?; |
| 47 | next += at + 1; |
| 48 | } |
| 49 | Ok(()) |
| 50 | } |
| 51 | |
| 52 | pub fn render_navbar() -> Markup { |
| 53 | html! { |
| 54 | header class="aien-header" { |
| 55 | div class="aien-header-inner" { |
| 56 | a class="aien-brand" href="/" aria-label="AienOS PERSISTENT MACHINE INTELLIGENCE: home" { |
| 57 | span class="aien-brand-mark" aria-hidden="true" { |
| 58 | (PreEscaped(r#"<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 17 10 11 4 5"></polyline><line x1="12" y1="19" x2="20" y2="19"></line></svg>"#)) |
| 59 | } |
| 60 | span class="aien-brand-copy" { |
| 61 | span class="aien-brand-name" { "AienOS" } |
| 62 | // The space keeps the rendered text "AienOS PERSISTENT ..." inside the |
| 63 | // aria-label; without it the text reads "AienOSPERSISTENT ..." (L501). |
| 64 | " " |
| 65 | span class="aien-brand-tag" { "PERSISTENT MACHINE INTELLIGENCE" } |
| 66 | } |
| 67 | } |
| 68 | nav class="aien-nav aien-nav-bar" aria-label="Primary navigation" { |
| 69 | ul class="aien-nav-primary" { |
| 70 | @for (label, href) in NAV_PRIMARY { |
| 71 | li { a class="aien-nav-link" href=(href) { (label) } } |
| 72 | } |
| 73 | } |
| 74 | // One button holds everything that used to wrap onto |
| 75 | // further rows. A native <details>: it opens and closes |
| 76 | // by click, Enter or Space and needs no script. Below |
| 77 | // the narrow breakpoint the six sections move in here |
| 78 | // too (aien-nav-sections), so the header stays one row. |
| 79 | details class="aien-nav-more" { |
| 80 | summary class="aien-nav-more-button" { |
| 81 | span class="aien-nav-more-wide" { "More" } |
| 82 | span class="aien-nav-more-narrow" { "Menu" } |
| 83 | } |
| 84 | div class="aien-nav-panel" { |
| 85 | ul class="aien-nav-sections" aria-label="Sections" { |
| 86 | @for (label, href) in NAV_PRIMARY { |
| 87 | li { a class="aien-nav-minor" href=(href) { (label) } } |
| 88 | } |
| 89 | } |
| 90 | ul class="aien-nav-secondary" aria-label="More" { |
| 91 | @for (label, href) in NAV_SECONDARY { |
| 92 | li { a class="aien-nav-minor" href=(href) { (label) } } |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | (crate::components::contact::nav_reach()) |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | #[cfg(test)] |
| 105 | mod tests { |
| 106 | use super::*; |
| 107 | |
| 108 | /// Written out independently of NAV_PRIMARY so reordering or dropping |
| 109 | /// an entry in the const makes these tests fail. |
| 110 | const EXPECTED_PRIMARY: [(&str, &str); 6] = [ |
| 111 | ("SI", "/classic/"), |
| 112 | ("Omega", "/omega/"), |
| 113 | ("Machine", "/machine/"), |
| 114 | ("Discoveries", "/discoveries/"), |
| 115 | ("Learn", "/learn/"), |
| 116 | ("Aien", "/aien/"), |
| 117 | ]; |
| 118 | |
| 119 | fn assert_six_in_order(haystack: &str, what: &str) { |
| 120 | let mut last = 0usize; |
| 121 | for (i, (label, href)) in EXPECTED_PRIMARY.iter().enumerate() { |
| 122 | let needle = format!("<a class=\"aien-nav-link\" href=\"{href}\">{label}</a>"); |
| 123 | let pos = haystack[last..] |
| 124 | .find(&needle) |
| 125 | .unwrap_or_else(|| panic!("{what}: nav item {i} ({label}) missing or out of order")); |
| 126 | last += pos + needle.len(); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | /// A page in the shape of the redesign: no top nav, the six |
| 131 | /// destinations in a quiet footer index, each a glyph marked |
| 132 | /// aria-hidden plus its label. |
| 133 | fn quiet(items: &[(&str, &str)]) -> String { |
| 134 | let mut s = String::from("<body><a class=\"site-brand\" href=\"/\"><span aria-hidden=\"true\">SI</span>Sovereign Intelligence</a><main>body</main><footer><nav class=\"quiet-index\" aria-label=\"Destinations\">"); |
| 135 | for (label, href) in items { |
| 136 | s.push_str(&format!("<a href=\"{href}\"><span class=\"nav-glyph\" aria-hidden=\"true\">Ω</span><span>{label}</span></a>")); |
| 137 | } |
| 138 | s.push_str("</nav></footer></body>"); |
| 139 | s |
| 140 | } |
| 141 | |
| 142 | #[test] |
| 143 | fn primary_nav_const_matches_the_six_dashboards() { |
| 144 | assert_eq!(NAV_PRIMARY, EXPECTED_PRIMARY, "NAV_PRIMARY differs from the approved six dashboards"); |
| 145 | } |
| 146 | |
| 147 | #[test] |
| 148 | fn rendered_navbar_has_six_sections_in_order_before_secondary() { |
| 149 | let html = render_navbar().into_string(); |
| 150 | assert_six_in_order(&html, "generated navbar"); |
| 151 | check_destinations(&html).expect("the Rust navbar passes the dist check"); |
| 152 | let primary_end = html.find("</ul>").expect("primary list closes"); |
| 153 | let secondary = html.find("aien-nav-secondary").expect("secondary list present"); |
| 154 | assert!(secondary > primary_end, "secondary links must come after the six sections"); |
| 155 | for (label, _) in NAV_SECONDARY { |
| 156 | assert!(html[secondary..].contains(label), "secondary item {label} missing"); |
| 157 | assert!(!html[..primary_end].contains(&format!(">{label}<")), "{label} must not be a primary item"); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | #[test] |
| 162 | fn quiet_index_passes_the_destination_check() { |
| 163 | check_destinations(&quiet(&EXPECTED_PRIMARY)).expect("six in order, glyphs hidden"); |
| 164 | let mut extra = EXPECTED_PRIMARY.to_vec(); |
| 165 | extra.insert(2, ("Now", "/now/")); |
| 166 | check_destinations(&quiet(&extra)).expect("other links between the six are allowed"); |
| 167 | } |
| 168 | |
| 169 | #[test] |
| 170 | fn destination_check_negative_controls() { |
| 171 | let six = EXPECTED_PRIMARY; |
| 172 | let mut swapped = six.to_vec(); |
| 173 | swapped.swap(1, 2); |
| 174 | let mut relabelled = six.to_vec(); |
| 175 | relabelled[3] = ("Scientific Discovery", "/discoveries/"); |
| 176 | let mut rerouted = six.to_vec(); |
| 177 | rerouted[3] = ("Discoveries", "/discovery/"); |
| 178 | let good = quiet(&six); |
| 179 | let learn = "<a href=\"/learn/\"><span class=\"nav-glyph\" aria-hidden=\"true\">Ω</span><span>Learn</span></a>"; |
| 180 | let cases = [ |
| 181 | ("one item dropped", quiet(&six[..5])), |
| 182 | ("two items swapped", quiet(&swapped)), |
| 183 | ("label changed", quiet(&relabelled)), |
| 184 | ("href changed", quiet(&rerouted)), |
| 185 | ("label only in the hidden glyph", good.replace(learn, "<a href=\"/learn/\"><span aria-hidden=\"true\">Learn</span></a>")), |
| 186 | ("link inside an aria-hidden index", good.replace("aria-label=\"Destinations\"", "aria-hidden=\"true\"")), |
| 187 | ("link only in a script", good.replace(learn, &format!("<script>document.write('{learn}')</script>"))), |
| 188 | ("link only in a template", good.replace(learn, &format!("<template>{learn}</template>"))), |
| 189 | ("hidden element never closes", good.replace("<nav class=\"quiet-index\"", "<div aria-hidden=\"true\"></div><nav class=\"quiet-index\"").replace("<div aria-hidden=\"true\"></div>", "<div aria-hidden=\"true\">")), |
| 190 | ]; |
| 191 | for (what, html) in cases { |
| 192 | assert!(check_destinations(&html).is_err(), "must reject: {what}"); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | #[test] |
| 197 | fn header_contact_is_one_x_button_and_the_rest_sits_behind_more() { |
| 198 | let html = render_navbar().into_string(); |
| 199 | assert!( |
| 200 | html.contains("class=\"aien-x-link aien-x-button\" href=\"https://x.com/drakestapleton\""), |
| 201 | "header must carry the X contact button" |
| 202 | ); |
| 203 | assert!(html.contains("aria-label=\"Contact me on X (@drakestapleton)\""), "the X button needs a name"); |
| 204 | assert!(!html.contains("href=\"/contact/\""), "Contact and X are one button"); |
| 205 | assert!(!html.contains("<script"), "the X link is a plain link and the menu is native"); |
| 206 | let more = html.find("<details class=\"aien-nav-more\">").expect("one More button"); |
| 207 | assert_eq!(html.matches("<details").count(), 1); |
| 208 | for (label, href) in NAV_SECONDARY { |
| 209 | assert!(html[more..].contains(&format!("href=\"{href}\">{label}<")), "{label} belongs behind More"); |
| 210 | } |
| 211 | let reach = html.find("aien-nav-reach").expect("X button group"); |
| 212 | assert!(reach > html.find("</details>").unwrap(), "X button follows the More button"); |
| 213 | } |
| 214 | |
| 215 | #[test] |
| 216 | fn navbar_has_no_em_or_en_dash() { |
| 217 | let html = render_navbar().into_string(); |
| 218 | assert!(!html.contains('\u{2014}') && !html.contains('\u{2013}')); |
| 219 | } |
| 220 | |
| 221 | #[test] |
| 222 | fn header_has_no_language_list_and_more_ends_before_the_x_button() { |
| 223 | let html = render_navbar().into_string(); |
| 224 | assert!(!html.contains("hreflang"), "no language alternates in the header"); |
| 225 | assert!(!html.contains("aien-nav-lang"), "no language list in the header"); |
| 226 | assert!( |
| 227 | html.contains("</a></li></ul></div></details><ul class=\"aien-nav-secondary aien-nav-reach\""), |
| 228 | "the More panel ends with its last link and the X button follows directly" |
| 229 | ); |
| 230 | } |
| 231 | } |