upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-12-02 15:35:27 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-12-02 15:35:27 +0000
commit347f17f0f9e3bc791d1fd699467da9fef4dab8ff (patch)
tree7734eae9dd006ff8dac352f1caf5c9225a913d63 /src
parent599d032ff8bbb529575067c193ac498cac590de5 (diff)
landing page add commit hash to version and add curation
Diffstat (limited to 'src')
-rw-r--r--src/http/landing.rs51
-rw-r--r--src/http/nip11.rs7
2 files changed, 53 insertions, 5 deletions
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 @@
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;
5 5
6/// Get the software version string (version + optional git commit)
7fn get_version() -> String {
8 let version = env!("CARGO_PKG_VERSION");
9 match option_env!("GIT_COMMIT_SHORT") {
10 Some(commit) if !commit.is_empty() => format!("v{}-{}", version, commit),
11 _ => format!("v{}", version),
12 }
13}
14
15/// Generate the footer JavaScript that sets the domain dynamically
16fn get_footer_script() -> &'static str {
17 r#"<script>
18 (function() {
19 var footerDomain = document.getElementById('footer-domain');
20 if (footerDomain) {
21 footerDomain.textContent = window.location.host;
22 }
23 })();
24 </script>"#
25}
26
6/// Generate the common base CSS used across all pages 27/// Generate the common base CSS used across all pages
7fn get_base_css() -> &'static str { 28fn get_base_css() -> &'static str {
8 r#":root { 29 r#":root {
@@ -42,6 +63,10 @@ fn get_base_css() -> &'static str {
42 color: var(--text-muted); 63 color: var(--text-muted);
43 font-size: 0.875rem; 64 font-size: 0.875rem;
44 } 65 }
66 .footer-separator {
67 margin: 0 0.5em;
68 opacity: 0.5;
69 }
45 .software-box { 70 .software-box {
46 display: flex; 71 display: flex;
47 align-items: flex-start; 72 align-items: flex-start;
@@ -93,11 +118,16 @@ fn get_software_box_html() -> &'static str {
93 118
94/// Generate the HTML landing page 119/// Generate the HTML landing page
95pub fn get_html(config: &Config) -> String { 120pub fn get_html(config: &Config) -> String {
121 // Curation matches NIP-11 document - currently None for this relay
122 let curation = "None".to_string();
123
96 format!( 124 format!(
97 include_str!("../../templates/landing.html"), 125 include_str!("../../templates/landing.html"),
98 base_css = get_base_css(), 126 base_css = get_base_css(),
99 relay_name = config.relay_name, 127 relay_name = config.relay_name,
100 relay_description = config.relay_description, 128 relay_description = config.relay_description,
129 version = get_version(),
130 curation = curation,
101 ) 131 )
102} 132}
103 133
@@ -146,6 +176,7 @@ pub fn get_generic_404_html(config: &Config, path: &str) -> String {
146 }} 176 }}
147 code {{ word-break: break-all; }} 177 code {{ word-break: break-all; }}
148 .footer {{ margin-top: 48px; }} 178 .footer {{ margin-top: 48px; }}
179 .footer-separator {{ margin: 0 0.5em; opacity: 0.5; }}
149 </style> 180 </style>
150</head> 181</head>
151<body> 182<body>
@@ -158,13 +189,16 @@ pub fn get_generic_404_html(config: &Config, path: &str) -> String {
158 <code>{path}</code> 189 <code>{path}</code>
159 </div> 190 </div>
160 <a href="/">&larr; Back to {relay_name}</a> 191 <a href="/">&larr; Back to {relay_name}</a>
161 <div class="footer">Powered by <a href="https://gitworkshop.dev/danconwaydev.com/ngit-grasp"><strong>ngit-grasp</strong></a></div> 192 <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>
162 </div> 193 </div>
194 {footer_script}
163</body> 195</body>
164</html>"##, 196</html>"##,
165 base_css = get_base_css(), 197 base_css = get_base_css(),
166 relay_name = config.relay_name, 198 relay_name = config.relay_name,
167 path = path, 199 path = path,
200 version = get_version(),
201 footer_script = get_footer_script(),
168 ) 202 )
169} 203}
170 204
@@ -230,6 +264,7 @@ pub fn get_404_html(config: &Config, npub: &str, identifier: &str) -> String {
230 color: var(--text-muted); 264 color: var(--text-muted);
231 }} 265 }}
232 .footer {{ margin-top: 48px; }} 266 .footer {{ margin-top: 48px; }}
267 .footer-separator {{ margin: 0 0.5em; opacity: 0.5; }}
233 </style> 268 </style>
234</head> 269</head>
235<body> 270<body>
@@ -249,14 +284,17 @@ pub fn get_404_html(config: &Config, npub: &str, identifier: &str) -> String {
249 </div> 284 </div>
250 <div class="hint">The repository may not have been announced to this server, or the URL may be incorrect.</div> 285 <div class="hint">The repository may not have been announced to this server, or the URL may be incorrect.</div>
251 <a href="/">&larr; Back to {relay_name}</a> 286 <a href="/">&larr; Back to {relay_name}</a>
252 <div class="footer">Powered by <a href="https://gitworkshop.dev/danconwaydev.com/ngit-grasp"><strong>ngit-grasp</strong></a></div> 287 <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>
253 </div> 288 </div>
289 {footer_script}
254</body> 290</body>
255</html>"##, 291</html>"##,
256 base_css = get_base_css(), 292 base_css = get_base_css(),
257 relay_name = config.relay_name, 293 relay_name = config.relay_name,
258 npub = npub, 294 npub = npub,
259 identifier = identifier, 295 identifier = identifier,
296 version = get_version(),
297 footer_script = get_footer_script(),
260 ) 298 )
261} 299}
262 300
@@ -363,7 +401,7 @@ pub fn get_repo_html(config: &Config, npub: &str, identifier: &str) -> String {
363 </div> 401 </div>
364 </div> 402 </div>
365 </div> 403 </div>
366 <div class="footer">Powered by <a href="https://gitworkshop.dev/danconwaydev.com/ngit-grasp"><strong>ngit-grasp</strong></a></div> 404 <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>
367 </div> 405 </div>
368 <script> 406 <script>
369 // Detect protocol and construct relayref 407 // Detect protocol and construct relayref
@@ -380,6 +418,12 @@ pub fn get_repo_html(config: &Config, npub: &str, identifier: &str) -> String {
380 // Construct gitworkshop link: gitworkshop.dev/npub/relayref/identifier 418 // Construct gitworkshop link: gitworkshop.dev/npub/relayref/identifier
381 const gitworkshopLink = document.getElementById('gitworkshop-link'); 419 const gitworkshopLink = document.getElementById('gitworkshop-link');
382 gitworkshopLink.setAttribute('href', 'https://gitworkshop.dev/{npub}/' + relayref + '/{identifier}'); 420 gitworkshopLink.setAttribute('href', 'https://gitworkshop.dev/{npub}/' + relayref + '/{identifier}');
421
422 // Set footer domain
423 var footerDomain = document.getElementById('footer-domain');
424 if (footerDomain) {{
425 footerDomain.textContent = host;
426 }}
383 </script> 427 </script>
384</body> 428</body>
385</html>"##, 429</html>"##,
@@ -387,5 +431,6 @@ pub fn get_repo_html(config: &Config, npub: &str, identifier: &str) -> String {
387 relay_name = config.relay_name, 431 relay_name = config.relay_name,
388 npub = npub, 432 npub = npub,
389 identifier = identifier, 433 identifier = identifier,
434 version = get_version(),
390 ) 435 )
391} 436}
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 {
62 11, // NIP-11: Relay information document (this!) 62 11, // NIP-11: Relay information document (this!)
63 34, // NIP-34: Git repository announcements 63 34, // NIP-34: Git repository announcements
64 ], 64 ],
65 software: env!("CARGO_PKG_NAME").to_string(), 65 software: "https://gitworkshop.dev/danconwaydev.com/ngit-grasp".to_string(),
66 version: env!("CARGO_PKG_VERSION").to_string(), 66 version: match option_env!("GIT_COMMIT_SHORT") {
67 Some(commit) => format!("{}-{}", env!("CARGO_PKG_VERSION"), commit),
68 None => env!("CARGO_PKG_VERSION").to_string(),
69 },
67 70
68 // GRASP-01 Extensions 71 // GRASP-01 Extensions
69 supported_grasps: vec!["GRASP-01".to_string()], 72 supported_grasps: vec!["GRASP-01".to_string()],