aienos.com
Source of www.aienos.com, served from my own hardware
Brought by drakestapleton
aienos.com / crates / site-builder / src / components / support.rs
| 1 | //! The support page and its CSS are authored in seeded Omega. The only |
| 2 | //! invitation elsewhere is the small header link added by [`enrich`]. |
| 3 | use maud::{html, Markup, PreEscaped}; |
| 4 | |
| 5 | pub const TITLE: &str = "Support my open source work | AienOS"; |
| 6 | pub const DESCRIPTION: &str = "Help Drake Stapleton keep building free and open source software with Bitcoin: the address, a wallet link and a QR code."; |
| 7 | pub const URL: &str = "https://www.aienos.com/support/"; |
| 8 | pub const PAGE: &str = include_str!("../../../../om/support-page/main.html"); |
| 9 | |
| 10 | pub fn render_page() -> Markup { html! { (PreEscaped(PAGE)) } } |
| 11 | |
| 12 | /// All document types get the same plain support link and local CSS. |
| 13 | pub fn enrich(mut page: String) -> String { |
| 14 | let header_end = page.find("</header>").expect("support needs the shared header"); |
| 15 | if !page[..header_end].contains("href=\"/support/\"") { |
| 16 | let nav_end = page[..header_end].rfind("</nav>").expect("support needs the shared nav"); |
| 17 | page.insert_str(nav_end, "<a class=\"aien-support-button\" href=\"/support/\">Support</a>"); |
| 18 | } |
| 19 | if !page.contains("href=\"/assets/support.css\"") { |
| 20 | let end = page.find("</head>").expect("support needs a document head"); |
| 21 | page.insert_str(end, "<link rel=\"stylesheet\" href=\"/assets/support.css\">"); |
| 22 | } |
| 23 | page |
| 24 | } |
| 25 | |
| 26 | #[cfg(test)] |
| 27 | mod tests { |
| 28 | use super::*; |
| 29 | use sha2::{Digest, Sha256}; |
| 30 | #[test] |
| 31 | fn support_artifacts_match_recorded_hashes() { |
| 32 | for (bytes, receipt) in [ |
| 33 | (PAGE.as_bytes(), include_str!("../../../../om/support-page/main.html.sha256")), |
| 34 | (include_bytes!("../../../../public/assets/support.css").as_slice(), include_str!("../../../../om/support-page/support.css.sha256")), |
| 35 | ] { |
| 36 | assert_eq!(format!("{:x}", Sha256::digest(bytes)), receipt.split_whitespace().next().unwrap()); |
| 37 | } |
| 38 | } |
| 39 | #[test] |
| 40 | fn support_is_one_bitcoin_action_with_no_x_money() { |
| 41 | assert!(PAGE.contains("<a class=\"support-button\" href=\"#bitcoin\">Send Bitcoin</a>")); |
| 42 | assert!(PAGE.contains("id=\"bitcoin\"")); |
| 43 | for text in ["Bitcoin is the one way to give", "running low on funds"] { |
| 44 | assert!(PAGE.contains(text), "missing {text}"); |
| 45 | } |
| 46 | for gone in ["X Money", "Send Money", "x.com/drakestapleton", "money.x.com", "github.com/sponsors"] { |
| 47 | assert!(!PAGE.contains(gone), "retired or absent payment rail {gone} is rendered"); |
| 48 | } |
| 49 | assert_eq!(PAGE.matches("class=\"support-button\"").count(), 1, "one primary action"); |
| 50 | assert!(PAGE.find("support-button").unwrap() < PAGE.find("support-card").unwrap(), "action before the steps"); |
| 51 | assert!(!PAGE.contains("<script")); |
| 52 | assert!(!PAGE.contains('—') && !PAGE.contains('–')); |
| 53 | } |
| 54 | #[test] |
| 55 | fn bitcoin_address_text_link_and_qr_agree() { |
| 56 | const ADDR: &str = "bc1qtfzkt7un99e3hrmc6uh3z7ccy6hny7axvxkgd2"; |
| 57 | assert_eq!(PAGE.matches("bc1q").count(), 3, "one address, shown once and linked twice"); |
| 58 | assert!(PAGE.contains(&format!("<code class=\"support-addr\">{ADDR}</code>"))); |
| 59 | assert_eq!(PAGE.matches(&format!("href=\"bitcoin:{ADDR}\"")).count(), 2); |
| 60 | assert!(PAGE.contains("src=\"/assets/support-btc-qr.svg\"")); |
| 61 | // The QR is decoded against bitcoin:ADDR when regenerated; see AGENTS.md. |
| 62 | let qr = include_str!("../../../../public/assets/support-btc-qr.svg"); |
| 63 | assert!(qr.contains("Created with qrencode 4.1.1") && !qr.contains("<script") && !qr.contains("href")); |
| 64 | } |
| 65 | #[test] |
| 66 | fn support_enrichment_is_idempotent_and_in_header() { |
| 67 | let page = "<html><head></head><body><header><nav></nav></header><main></main></body></html>"; |
| 68 | let once = enrich(page.into()); |
| 69 | assert_eq!(enrich(once.clone()), once); |
| 70 | assert!(once.find("href=\"/support/\"").unwrap() < once.find("</header>").unwrap()); |
| 71 | assert!(once.contains("/assets/support.css")); |
| 72 | } |
| 73 | } |