From 347f17f0f9e3bc791d1fd699467da9fef4dab8ff Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Tue, 2 Dec 2025 15:35:27 +0000 Subject: landing page add commit hash to version and add curation --- src/http/landing.rs | 51 ++++++++++++++++++++++++++++++++++++++++++++++++--- src/http/nip11.rs | 7 +++++-- 2 files changed, 53 insertions(+), 5 deletions(-) (limited to 'src/http') diff --git a/src/http/landing.rs b/src/http/landing.rs index eaba914..8b416f1 100644 --- a/src/http/landing.rs +++ b/src/http/landing.rs @@ -3,6 +3,27 @@ /// Generates HTML landing page for the Nostr relay. use crate::config::Config; +/// Get the software version string (version + optional git commit) +fn get_version() -> String { + let version = env!("CARGO_PKG_VERSION"); + match option_env!("GIT_COMMIT_SHORT") { + Some(commit) if !commit.is_empty() => format!("v{}-{}", version, commit), + _ => format!("v{}", version), + } +} + +/// Generate the footer JavaScript that sets the domain dynamically +fn get_footer_script() -> &'static str { + r#""# +} + /// Generate the common base CSS used across all pages fn get_base_css() -> &'static str { r#":root { @@ -42,6 +63,10 @@ fn get_base_css() -> &'static str { color: var(--text-muted); font-size: 0.875rem; } + .footer-separator { + margin: 0 0.5em; + opacity: 0.5; + } .software-box { display: flex; align-items: flex-start; @@ -93,11 +118,16 @@ fn get_software_box_html() -> &'static str { /// 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(); + format!( include_str!("../../templates/landing.html"), base_css = get_base_css(), relay_name = config.relay_name, relay_description = config.relay_description, + version = get_version(), + curation = curation, ) } @@ -146,6 +176,7 @@ pub fn get_generic_404_html(config: &Config, path: &str) -> String { }} code {{ word-break: break-all; }} .footer {{ margin-top: 48px; }} + .footer-separator {{ margin: 0 0.5em; opacity: 0.5; }} @@ -158,13 +189,16 @@ pub fn get_generic_404_html(config: &Config, path: &str) -> String { {path} ← Back to {relay_name} - + + {footer_script} "##, base_css = get_base_css(), relay_name = config.relay_name, path = path, + version = get_version(), + footer_script = get_footer_script(), ) } @@ -230,6 +264,7 @@ pub fn get_404_html(config: &Config, npub: &str, identifier: &str) -> String { color: var(--text-muted); }} .footer {{ margin-top: 48px; }} + .footer-separator {{ margin: 0 0.5em; opacity: 0.5; }} @@ -249,14 +284,17 @@ pub fn get_404_html(config: &Config, npub: &str, identifier: &str) -> String {
The repository may not have been announced to this server, or the URL may be incorrect.
← Back to {relay_name} - + + {footer_script} "##, base_css = get_base_css(), relay_name = config.relay_name, npub = npub, identifier = identifier, + version = get_version(), + footer_script = get_footer_script(), ) } @@ -363,7 +401,7 @@ pub fn get_repo_html(config: &Config, npub: &str, identifier: &str) -> String { - + "##, @@ -387,5 +431,6 @@ pub fn get_repo_html(config: &Config, npub: &str, identifier: &str) -> String { relay_name = config.relay_name, npub = npub, identifier = identifier, + version = get_version(), ) } diff --git a/src/http/nip11.rs b/src/http/nip11.rs index 593ef9a..901b676 100644 --- a/src/http/nip11.rs +++ b/src/http/nip11.rs @@ -62,8 +62,11 @@ impl RelayInformationDocument { 11, // NIP-11: Relay information document (this!) 34, // NIP-34: Git repository announcements ], - software: env!("CARGO_PKG_NAME").to_string(), - version: env!("CARGO_PKG_VERSION").to_string(), + software: "https://gitworkshop.dev/danconwaydev.com/ngit-grasp".to_string(), + version: match option_env!("GIT_COMMIT_SHORT") { + Some(commit) => format!("{}-{}", env!("CARGO_PKG_VERSION"), commit), + None => env!("CARGO_PKG_VERSION").to_string(), + }, // GRASP-01 Extensions supported_grasps: vec!["GRASP-01".to_string()], -- cgit v1.2.3