From b7edb8f0236b4fb63957763f7f6759b7290f5ebe Mon Sep 17 00:00:00 2001 From: tegwick Date: Tue, 29 Sep 2026 17:40:27 +0200 Subject: [PATCH] Sidebar marks the current section on detail pages too Co-Authored-By: Claude Sonnet 5.5 Assistant: claude-code Assistant-Model: sonnet Assistant-Process: 295952@bnt-lap001 Assistant-Session: e93f64ad-516c-46eb-9666-aad8d300c477 --- rtut/ui.py | 5 +++-- tests/test_ui_shell.py | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/rtut/ui.py b/rtut/ui.py index 17a4ef5..47d6a92 100644 --- a/rtut/ui.py +++ b/rtut/ui.py @@ -126,8 +126,9 @@ def page(title: str, body: str) -> bytes: "const f=b.closest('form'),n=f.querySelector('[name=note]'),w=f.querySelector('[data-warn]');" "if(n&&!n.value.trim()&&!b.dataset.warned){ev.preventDefault();b.dataset.warned='1';w.hidden=false;n.focus();}}));" # sidebar: mark where we are; theme switch cycles system -> light -> dark - "const p=location.pathname;document.querySelectorAll('a[data-nav]').forEach(a=>{const h=a.getAttribute('href');" - "if(h==='/'?p==='/':p===h||p.startsWith(h+'/'))a.setAttribute('aria-current','page')});" + "const p=location.pathname;const alias={'/projects':['/project/','/template/'],'/runbooks':['/pack/','/run/'],'/attribute-sets':['/attribute-set/']};" + "document.querySelectorAll('a[data-nav]').forEach(a=>{const h=a.getAttribute('href');" + "if(h==='/'?p==='/':p===h||p.startsWith(h+'/')||(alias[h]||[]).some(x=>p.startsWith(x)))a.setAttribute('aria-current','page')});" "const tb=document.querySelector('[data-theme-toggle]');const cur=()=>{try{return localStorage.getItem('rtut-theme')||'system'}catch(x){return 'system'}};" "const show=()=>{if(tb)tb.textContent='Theme: '+cur()};show();" "if(tb)tb.onclick=()=>{const n={system:'light',light:'dark',dark:'system'}[cur()];" diff --git a/tests/test_ui_shell.py b/tests/test_ui_shell.py index 63e9d3d..a890abc 100644 --- a/tests/test_ui_shell.py +++ b/tests/test_ui_shell.py @@ -71,6 +71,7 @@ def test_the_theme_can_be_chosen_and_is_remembered_and_dark_styles_exist(srv): assert "localStorage.getItem('rtut-theme')" in head and "URLSearchParams" in head # applied before painting; ?theme=dark also works assert "system:'light',light:'dark',dark:'system'" in body # the button cycles system, light, dark assert "aria-current" in body # the current section is marked + assert "'/attribute-sets':['/attribute-set/']" in body and "'/projects':['/project/','/template/']" in body # detail pages mark their section too def test_the_sidebar_shows_the_saved_name(srv):