mirror of
https://relay.ngit.dev/npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit-grasp.git
synced 2026-10-05 15:08:24 +00:00
landing page add commit hash to version and add curation
This commit is contained in:
@@ -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/");
|
||||
}
|
||||
+48
-3
@@ -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#"<script>
|
||||
(function() {
|
||||
var footerDomain = document.getElementById('footer-domain');
|
||||
if (footerDomain) {
|
||||
footerDomain.textContent = window.location.host;
|
||||
}
|
||||
})();
|
||||
</script>"#
|
||||
}
|
||||
|
||||
/// 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; }}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -158,13 +189,16 @@ pub fn get_generic_404_html(config: &Config, path: &str) -> String {
|
||||
<code>{path}</code>
|
||||
</div>
|
||||
<a href="/">← Back to {relay_name}</a>
|
||||
<div class="footer">Powered by <a href="https://gitworkshop.dev/danconwaydev.com/ngit-grasp"><strong>ngit-grasp</strong></a></div>
|
||||
<div class="footer"><span id="footer-domain"></span><span class="footer-separator">•</span>powered by <a href="https://gitworkshop.dev/danconwaydev.com/ngit-grasp"><strong>ngit-grasp</strong></a><span class="footer-separator">•</span>{version}<span class="footer-separator">•</span>MIT Licensed</div>
|
||||
</div>
|
||||
{footer_script}
|
||||
</body>
|
||||
</html>"##,
|
||||
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; }}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -249,14 +284,17 @@ pub fn get_404_html(config: &Config, npub: &str, identifier: &str) -> String {
|
||||
</div>
|
||||
<div class="hint">The repository may not have been announced to this server, or the URL may be incorrect.</div>
|
||||
<a href="/">← Back to {relay_name}</a>
|
||||
<div class="footer">Powered by <a href="https://gitworkshop.dev/danconwaydev.com/ngit-grasp"><strong>ngit-grasp</strong></a></div>
|
||||
<div class="footer"><span id="footer-domain"></span><span class="footer-separator">•</span>powered by <a href="https://gitworkshop.dev/danconwaydev.com/ngit-grasp"><strong>ngit-grasp</strong></a><span class="footer-separator">•</span>{version}<span class="footer-separator">•</span>MIT Licensed</div>
|
||||
</div>
|
||||
{footer_script}
|
||||
</body>
|
||||
</html>"##,
|
||||
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 {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer">Powered by <a href="https://gitworkshop.dev/danconwaydev.com/ngit-grasp"><strong>ngit-grasp</strong></a></div>
|
||||
<div class="footer"><span id="footer-domain"></span><span class="footer-separator">•</span>powered by <a href="https://gitworkshop.dev/danconwaydev.com/ngit-grasp"><strong>ngit-grasp</strong></a><span class="footer-separator">•</span>{version}<span class="footer-separator">•</span>MIT Licensed</div>
|
||||
</div>
|
||||
<script>
|
||||
// Detect protocol and construct relayref
|
||||
@@ -380,6 +418,12 @@ pub fn get_repo_html(config: &Config, npub: &str, identifier: &str) -> String {
|
||||
// Construct gitworkshop link: gitworkshop.dev/npub/relayref/identifier
|
||||
const gitworkshopLink = document.getElementById('gitworkshop-link');
|
||||
gitworkshopLink.setAttribute('href', 'https://gitworkshop.dev/{npub}/' + relayref + '/{identifier}');
|
||||
|
||||
// Set footer domain
|
||||
var footerDomain = document.getElementById('footer-domain');
|
||||
if (footerDomain) {{
|
||||
footerDomain.textContent = host;
|
||||
}}
|
||||
</script>
|
||||
</body>
|
||||
</html>"##,
|
||||
@@ -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(),
|
||||
)
|
||||
}
|
||||
|
||||
+5
-2
@@ -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()],
|
||||
|
||||
+17
-4
@@ -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; }}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -184,14 +185,20 @@
|
||||
<a id="browse-link" href="https://gitworkshop.dev" class="browse-link" target="_blank">
|
||||
Browse Repositories on GitWorkshop.dev →
|
||||
</a>
|
||||
|
||||
<div class="tag-container">
|
||||
|
||||
<div class="tag-container" style="margin-bottom: 12px;">
|
||||
<span class="tag-label">Curation:</span>
|
||||
<span class="tag-label">{curation}</span>
|
||||
</div>
|
||||
|
||||
<div class="tag-container" style="margin-top: 12px;">
|
||||
<span class="tag-label">Supports:</span>
|
||||
<span class="tag tag-grasp">GRASP-01</span>
|
||||
<span class="tag tag-nip">NIP-01</span>
|
||||
<span class="tag tag-nip">NIP-11</span>
|
||||
<span class="tag tag-nip">NIP-34</span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="card">
|
||||
<div class="software-box">
|
||||
@@ -244,7 +251,7 @@
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
Powered by <a href="https://gitworkshop.dev/danconwaydev.com/ngit-grasp"><strong>ngit-grasp</strong></a>
|
||||
<span id="footer-domain"></span><span class="footer-separator">•</span>powered by <a href="https://gitworkshop.dev/danconwaydev.com/ngit-grasp"><strong>ngit-grasp</strong></a><span class="footer-separator">•</span>{version}<span class="footer-separator">•</span>MIT Licensed
|
||||
</div>
|
||||
</main>
|
||||
<script>
|
||||
@@ -259,6 +266,12 @@
|
||||
// Update the browse link to point to the relay on gitworkshop
|
||||
const browseLink = document.getElementById('browse-link');
|
||||
browseLink.setAttribute('href', 'https://gitworkshop.dev/relay/' + relayref);
|
||||
|
||||
// Set footer domain
|
||||
var footerDomain = document.getElementById('footer-domain');
|
||||
if (footerDomain) {{
|
||||
footerDomain.textContent = host;
|
||||
}}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user