openhands openhands commited on
Commit
0813604
·
1 Parent(s): bdd9196

Fix navigation links to use relative paths and match category names

Browse files

1. Add JavaScript to convert absolute navigation hrefs to relative paths
- Fixes issue where links pointed to hf.space domain when accessed via index.openhands.dev
- Navigation now stays on the same domain regardless of proxy configuration

2. Update route paths to match category names:
- Issue Resolution: /bug-fixing → /issue-resolution
- Greenfield: /app-creation → /greenfield
- Frontend: /frontend-development → /frontend
- Testing: /test-generation → /testing

Co-authored-by: openhands <openhands@all-hands.dev>

Files changed (1) hide show
  1. app.py +42 -5
app.py CHANGED
@@ -75,6 +75,43 @@ redirect_script = """
75
  if (window.location.pathname === '/') { window.location.replace('/home'); }
76
  </script>
77
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  tooltip_script = """
79
  <script>
80
  function initializeSmartTooltips() {
@@ -312,23 +349,23 @@ logger.info("Creating Gradio application")
312
  demo = gr.Blocks(
313
  theme=theme,
314
  css=final_css,
315
- head=posthog_script + scroll_script + redirect_script + tooltip_script + dark_mode_script,
316
  title="OpenHands Index",
317
  )
318
 
319
  with demo.route("Home", "/home"):
320
  build_main_page()
321
 
322
- with demo.route("Issue Resolution", "/bug-fixing"):
323
  build_bug_fixing_page()
324
 
325
- with demo.route("Greenfield", "/app-creation"):
326
  build_app_creation_page()
327
 
328
- with demo.route("Frontend", "/frontend-development"):
329
  build_frontend_page()
330
 
331
- with demo.route("Testing", "/test-generation"):
332
  build_test_generation_page()
333
 
334
  with demo.route("Information Gathering", "/information-gathering"):
 
75
  if (window.location.pathname === '/') { window.location.replace('/home'); }
76
  </script>
77
  """
78
+
79
+ # JavaScript to fix navigation links to use relative paths (avoids domain mismatch when behind proxy)
80
+ fix_nav_links_script = """
81
+ <script>
82
+ (function() {
83
+ function fixNavLinks() {
84
+ // Find all navigation links in the nav-holder
85
+ const navLinks = document.querySelectorAll('.nav-holder nav a');
86
+ navLinks.forEach(link => {
87
+ const href = link.getAttribute('href');
88
+ if (href) {
89
+ // Extract the pathname from the href (works with both relative and absolute URLs)
90
+ try {
91
+ const url = new URL(href, window.location.origin);
92
+ // Only update if the pathname starts with /
93
+ if (url.pathname.startsWith('/')) {
94
+ link.setAttribute('href', url.pathname);
95
+ }
96
+ } catch (e) {
97
+ // If URL parsing fails, leave the href as-is
98
+ }
99
+ }
100
+ });
101
+ }
102
+
103
+ // Run when DOM is ready
104
+ if (document.readyState === 'loading') {
105
+ document.addEventListener('DOMContentLoaded', fixNavLinks);
106
+ } else {
107
+ fixNavLinks();
108
+ }
109
+
110
+ // Also run periodically to catch dynamically added links
111
+ setInterval(fixNavLinks, 1000);
112
+ })();
113
+ </script>
114
+ """
115
  tooltip_script = """
116
  <script>
117
  function initializeSmartTooltips() {
 
349
  demo = gr.Blocks(
350
  theme=theme,
351
  css=final_css,
352
+ head=posthog_script + scroll_script + redirect_script + fix_nav_links_script + tooltip_script + dark_mode_script,
353
  title="OpenHands Index",
354
  )
355
 
356
  with demo.route("Home", "/home"):
357
  build_main_page()
358
 
359
+ with demo.route("Issue Resolution", "/issue-resolution"):
360
  build_bug_fixing_page()
361
 
362
+ with demo.route("Greenfield", "/greenfield"):
363
  build_app_creation_page()
364
 
365
+ with demo.route("Frontend", "/frontend"):
366
  build_frontend_page()
367
 
368
+ with demo.route("Testing", "/testing"):
369
  build_test_generation_page()
370
 
371
  with demo.route("Information Gathering", "/information-gathering"):