From 2591dbf7498e2300a42928ac9fbec454732e66f0 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Wed, 3 Dec 2025 15:28:01 +0000 Subject: landing page: pull supported nips and grasps from nip11 document --- src/http/landing.rs | 159 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 157 insertions(+), 2 deletions(-) (limited to 'src/http') diff --git a/src/http/landing.rs b/src/http/landing.rs index f9fca5b..c76a7e6 100644 --- a/src/http/landing.rs +++ b/src/http/landing.rs @@ -2,6 +2,8 @@ /// /// Generates HTML landing page for the Nostr relay. use crate::config::Config; +use crate::http::nip11::RelayInformationDocument; +use std::collections::HashMap; /// Get the software version string (version + optional git commit) fn get_version() -> String { @@ -274,10 +276,160 @@ fn get_base_css() -> &'static str { }"# } +/// Metadata for a NIP (title and description for the landing page) +struct NipMetadata { + title: &'static str, + description: &'static str, +} + +/// Metadata for a GRASP (title and description for the landing page) +struct GraspMetadata { + title: &'static str, + description: &'static str, +} + +/// Get known NIP metadata for landing page display +fn get_nip_metadata() -> HashMap { + let mut map = HashMap::new(); + map.insert( + 1, + NipMetadata { + title: "Basic Protocol", + description: "Core Nostr protocol flow and event structure", + }, + ); + map.insert( + 11, + NipMetadata { + title: "Relay Information", + description: "Relay metadata and capabilities document", + }, + ); + map.insert( + 34, + NipMetadata { + title: "Git Events", + description: "Repository announcements and state tracking", + }, + ); + map.insert( + 77, + NipMetadata { + title: "Negentropy Sync", + description: "Efficient set reconciliation protocol", + }, + ); + map +} + +/// Get known GRASP metadata for landing page display +fn get_grasp_metadata() -> HashMap<&'static str, GraspMetadata> { + let mut map = HashMap::new(); + map.insert( + "GRASP-01", + GraspMetadata { + title: "Nostr Authorised HTTP Git Server", + description: "with embedded Nostr Relay", + }, + ); + map +} + +/// Generate hero section tags HTML from NIP-11 document +fn generate_hero_tags(nip11: &RelayInformationDocument) -> String { + let mut html = String::new(); + + // Add GRASP tags + for grasp in &nip11.supported_grasps { + html.push_str(&format!( + r#"{}"#, + grasp + )); + html.push('\n'); + } + + // Add NIP tags + for nip in &nip11.supported_nips { + html.push_str(&format!( + r#"NIP-{:02}"#, + nip + )); + html.push('\n'); + } + + html +} + +/// Generate detailed GRASP cards HTML from NIP-11 document +fn generate_grasp_cards(nip11: &RelayInformationDocument) -> String { + let metadata = get_grasp_metadata(); + let mut html = String::new(); + + for grasp in &nip11.supported_grasps { + if let Some(meta) = metadata.get(grasp.as_str()) { + html.push_str(&format!( + r#"
+
{}{}
+
{}
+
"#, + grasp, meta.title, meta.description + )); + } else { + // Fallback for unknown GRASPs - still show them + html.push_str(&format!( + r#"
+
{}{}
+
"#, + grasp, grasp + )); + } + html.push('\n'); + } + + html +} + +/// Generate detailed NIP cards HTML from NIP-11 document +fn generate_nip_cards(nip11: &RelayInformationDocument) -> String { + let metadata = get_nip_metadata(); + let mut html = String::new(); + + for nip in &nip11.supported_nips { + if let Some(meta) = metadata.get(nip) { + html.push_str(&format!( + r#"
+
NIP-{:02} {}
+
{}
+
"#, + nip, meta.title, meta.description + )); + } else { + // Fallback for unknown NIPs - still show them + html.push_str(&format!( + r#"
+
NIP-{:02}
+
"#, + nip + )); + } + html.push('\n'); + } + + html +} + /// Generate the HTML landing page pub fn get_html(config: &Config) -> String { - // Curation matches NIP-11 document - currently None for this relay - let curation = "None".to_string(); + // Get NIP-11 document for supported NIPs and GRASPs + let nip11 = RelayInformationDocument::from_config(config); + + // Curation matches NIP-11 document + let curation = nip11.curation.as_deref().unwrap_or("None").to_string(); + + // Generate dynamic HTML for NIPs and GRASPs + let hero_tags = generate_hero_tags(&nip11); + let grasp_cards = generate_grasp_cards(&nip11); + let nip_cards = generate_nip_cards(&nip11); format!( include_str!("../../templates/landing.html"), @@ -288,6 +440,9 @@ pub fn get_html(config: &Config) -> String { curation = curation, theme_toggle = get_theme_toggle_html(), theme_script = get_theme_script(), + hero_tags = hero_tags, + grasp_cards = grasp_cards, + nip_cards = nip_cards, ) } -- cgit v1.2.3