upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/http
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-12-03 15:28:01 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-12-03 15:28:01 +0000
commit2591dbf7498e2300a42928ac9fbec454732e66f0 (patch)
tree4a97a1eb9bed6f7a9bae588e8bd3780464c4c017 /src/http
parent8c9fcbcdc1f03df27e5ce9009bde56e7ddfebac2 (diff)
landing page: pull supported nips and grasps from nip11 document
Diffstat (limited to 'src/http')
-rw-r--r--src/http/landing.rs159
1 files changed, 157 insertions, 2 deletions
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 @@
2/// 2///
3/// Generates HTML landing page for the Nostr relay. 3/// Generates HTML landing page for the Nostr relay.
4use crate::config::Config; 4use crate::config::Config;
5use crate::http::nip11::RelayInformationDocument;
6use std::collections::HashMap;
5 7
6/// Get the software version string (version + optional git commit) 8/// Get the software version string (version + optional git commit)
7fn get_version() -> String { 9fn get_version() -> String {
@@ -274,10 +276,160 @@ fn get_base_css() -> &'static str {
274 }"# 276 }"#
275} 277}
276 278
279/// Metadata for a NIP (title and description for the landing page)
280struct NipMetadata {
281 title: &'static str,
282 description: &'static str,
283}
284
285/// Metadata for a GRASP (title and description for the landing page)
286struct GraspMetadata {
287 title: &'static str,
288 description: &'static str,
289}
290
291/// Get known NIP metadata for landing page display
292fn get_nip_metadata() -> HashMap<u16, NipMetadata> {
293 let mut map = HashMap::new();
294 map.insert(
295 1,
296 NipMetadata {
297 title: "Basic Protocol",
298 description: "Core Nostr protocol flow and event structure",
299 },
300 );
301 map.insert(
302 11,
303 NipMetadata {
304 title: "Relay Information",
305 description: "Relay metadata and capabilities document",
306 },
307 );
308 map.insert(
309 34,
310 NipMetadata {
311 title: "Git Events",
312 description: "Repository announcements and state tracking",
313 },
314 );
315 map.insert(
316 77,
317 NipMetadata {
318 title: "Negentropy Sync",
319 description: "Efficient set reconciliation protocol",
320 },
321 );
322 map
323}
324
325/// Get known GRASP metadata for landing page display
326fn get_grasp_metadata() -> HashMap<&'static str, GraspMetadata> {
327 let mut map = HashMap::new();
328 map.insert(
329 "GRASP-01",
330 GraspMetadata {
331 title: "Nostr Authorised HTTP Git Server",
332 description: "with embedded Nostr Relay",
333 },
334 );
335 map
336}
337
338/// Generate hero section tags HTML from NIP-11 document
339fn generate_hero_tags(nip11: &RelayInformationDocument) -> String {
340 let mut html = String::new();
341
342 // Add GRASP tags
343 for grasp in &nip11.supported_grasps {
344 html.push_str(&format!(
345 r#"<span class="tag tag-grasp">{}</span>"#,
346 grasp
347 ));
348 html.push('\n');
349 }
350
351 // Add NIP tags
352 for nip in &nip11.supported_nips {
353 html.push_str(&format!(
354 r#"<span class="tag tag-nip">NIP-{:02}</span>"#,
355 nip
356 ));
357 html.push('\n');
358 }
359
360 html
361}
362
363/// Generate detailed GRASP cards HTML from NIP-11 document
364fn generate_grasp_cards(nip11: &RelayInformationDocument) -> String {
365 let metadata = get_grasp_metadata();
366 let mut html = String::new();
367
368 for grasp in &nip11.supported_grasps {
369 if let Some(meta) = metadata.get(grasp.as_str()) {
370 html.push_str(&format!(
371 r#"<div class="card">
372 <div class="card-title"><span class="badge">{}</span>{}</div>
373 <div class="card-desc">{}</div>
374 </div>"#,
375 grasp, meta.title, meta.description
376 ));
377 } else {
378 // Fallback for unknown GRASPs - still show them
379 html.push_str(&format!(
380 r#"<div class="card">
381 <div class="card-title"><span class="badge">{}</span>{}</div>
382 </div>"#,
383 grasp, grasp
384 ));
385 }
386 html.push('\n');
387 }
388
389 html
390}
391
392/// Generate detailed NIP cards HTML from NIP-11 document
393fn generate_nip_cards(nip11: &RelayInformationDocument) -> String {
394 let metadata = get_nip_metadata();
395 let mut html = String::new();
396
397 for nip in &nip11.supported_nips {
398 if let Some(meta) = metadata.get(nip) {
399 html.push_str(&format!(
400 r#"<div class="card">
401 <div class="card-title"><span class="badge">NIP-{:02}</span> {}</div>
402 <div class="card-desc">{}</div>
403 </div>"#,
404 nip, meta.title, meta.description
405 ));
406 } else {
407 // Fallback for unknown NIPs - still show them
408 html.push_str(&format!(
409 r#"<div class="card">
410 <div class="card-title"><span class="badge">NIP-{:02}</span></div>
411 </div>"#,
412 nip
413 ));
414 }
415 html.push('\n');
416 }
417
418 html
419}
420
277/// Generate the HTML landing page 421/// Generate the HTML landing page
278pub fn get_html(config: &Config) -> String { 422pub fn get_html(config: &Config) -> String {
279 // Curation matches NIP-11 document - currently None for this relay 423 // Get NIP-11 document for supported NIPs and GRASPs
280 let curation = "None".to_string(); 424 let nip11 = RelayInformationDocument::from_config(config);
425
426 // Curation matches NIP-11 document
427 let curation = nip11.curation.as_deref().unwrap_or("None").to_string();
428
429 // Generate dynamic HTML for NIPs and GRASPs
430 let hero_tags = generate_hero_tags(&nip11);
431 let grasp_cards = generate_grasp_cards(&nip11);
432 let nip_cards = generate_nip_cards(&nip11);
281 433
282 format!( 434 format!(
283 include_str!("../../templates/landing.html"), 435 include_str!("../../templates/landing.html"),
@@ -288,6 +440,9 @@ pub fn get_html(config: &Config) -> String {
288 curation = curation, 440 curation = curation,
289 theme_toggle = get_theme_toggle_html(), 441 theme_toggle = get_theme_toggle_html(),
290 theme_script = get_theme_script(), 442 theme_script = get_theme_script(),
443 hero_tags = hero_tags,
444 grasp_cards = grasp_cards,
445 nip_cards = nip_cards,
291 ) 446 )
292} 447}
293 448