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 --- build.rs | 20 ++++++++++++++++++++ src/http/landing.rs | 51 +++++++++++++++++++++++++++++++++++++++++++++++--- src/http/nip11.rs | 7 +++++-- templates/landing.html | 21 +++++++++++++++++---- 4 files changed, 90 insertions(+), 9 deletions(-) create mode 100644 build.rs diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..e7d9cba --- /dev/null +++ b/build.rs @@ -0,0 +1,20 @@ +use std::process::Command; + +fn main() { + // Get the short git commit hash + let output = Command::new("git") + .args(["rev-parse", "--short", "HEAD"]) + .output(); + + if let Ok(output) = output { + if output.status.success() { + let commit = String::from_utf8_lossy(&output.stdout); + let commit = commit.trim(); + println!("cargo:rustc-env=GIT_COMMIT_SHORT={}", commit); + } + } + + // Re-run if HEAD changes (new commits) + println!("cargo:rerun-if-changed=.git/HEAD"); + println!("cargo:rerun-if-changed=.git/refs/heads/"); +} \ No newline at end of file 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()], diff --git a/templates/landing.html b/templates/landing.html index a12251c..ae0f31d 100644 --- a/templates/landing.html +++ b/templates/landing.html @@ -125,7 +125,7 @@ }} code {{ padding: 2px 8px; }} .tag-container {{ - margin: 24px 0; + margin: 16px 0; display: flex; flex-wrap: wrap; gap: 8px; @@ -170,6 +170,7 @@ text-decoration: none; }} .footer {{ margin-top: 64px; }} + .footer-separator {{ margin: 0 0.5em; opacity: 0.5; }} @@ -184,14 +185,20 @@ Browse Repositories on GitWorkshop.dev → - -
+ +
+ Curation: + {curation} +
+ +
Supports: GRASP-01 NIP-01 NIP-11 NIP-34
+
@@ -244,7 +251,7 @@
\ No newline at end of file -- cgit v1.2.3