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}