feat: reusable navbar with auth check in render

This commit is contained in:
Luis Pereira 2026-01-17 17:42:57 +00:00 committed by Brian O'Reilly
parent 732ff0858e
commit cffb3cf384
2 changed files with 55 additions and 26 deletions

View File

@ -19,33 +19,9 @@
<img src="/asteroid/static/asteroid.png" alt="Asteroid" style="height: 50px; width: auto;">
</h1>
<nav class="nav">
<c:if test="(not framesetp)">
<c:then>
<a href="/asteroid/">Home</a>
<a href="/asteroid/player">Player</a>
<a href="/asteroid/about">About</a>
<a href="/asteroid/status">Status</a>
<a href="/asteroid/profile" data-show-if-logged-in>Profile</a>
<a href="/asteroid/admin" data-show-if-admin>Admin</a>
<a href="/asteroid/login" data-show-if-logged-out>Login</a>
<a href="/asteroid/register" data-show-if-logged-out>Register</a>
<a href="/asteroid/logout" data-show-if-logged-in class="btn-logout">Logout</a>
</c:then>
<c:else>
<a href="/asteroid/content" target="_self">Home</a>
<a href="/asteroid/player-content" target="_self">Player</a>
<a href="/asteroid/about-content" target="_self">About</a>
<a href="/asteroid/status-content" target="_self">Status</a>
<a href="/asteroid/profile" target="_self" data-show-if-logged-in>Profile</a>
<a href="/asteroid/admin" target="_self" data-show-if-admin>Admin</a>
<a href="/asteroid/login" target="_self" data-show-if-logged-out>Login</a>
<a href="/asteroid/register" target="_self" data-show-if-logged-out>Register</a>
<a href="/asteroid/logout" data-show-if-logged-in class="btn-logout">Logout</a>
</c:else>
</c:if>
</nav>
<c:h>(asteroid::load-template "partial/navbar")</c:h>
</header>
<main style="max-width: 800px; margin: 0 auto; padding: 20px;">
<section style="margin-bottom: 30px;">
<h2 style="color: #00ff00; border-bottom: 2px solid #00ff00; padding-bottom: 10px;">🎵 Asteroid Music for Hackers</h2>

View File

@ -0,0 +1,53 @@
<c:let home-href='(if framesetp "content" "")'
player-href='(if framesetp "player-content" "player")'
about-href='(if framesetp "about-content" "about")'
status-href='(if framesetp "status-content" "status")'
current-user='(asteroid::get-current-user)'
framesetp='framesetp'>
<!-- Navbar definition -->
<nav class="nav">
<a lquery='(attr :href (eval (format nil "/asteroid/~a" home-href)) :target (when framesetp "_self"))'>
Home
</a>
<a lquery='(attr :href (eval (format nil "/asteroid/~a" player-href)) :target (when framesetp "_self"))'>
Player
</a>
<a lquery='(attr :href (eval (format nil "/asteroid/~a" about-href)) :target (when framesetp "_self"))'>
About
</a>
<a lquery='(attr :href (eval (format nil "/asteroid/~a" status-href)) :target (when framesetp "_self"))'>
Status
</a>
<c:when test="current-user">
<a href="/asteroid/profile"
lquery='(attr :target (when framesetp "_self"))'>
Profile
</a>
</c:when>
<c:when test='(equal "admin" (clip current-user :role))'>
<a href="/asteroid/admin"
lquery='(attr :target (when framesetp "_self"))'>
Admin
</a>
</c:when>
<c:when test="(not current-user)">
<a href="/asteroid/login"
lquery='(attr :target (when framesetp "_self"))'>
Login
</a>
</c:when>
<c:when test="(not current-user)">
<a href="/asteroid/register"
lquery='(attr :target (when framesetp "_self"))'>
Register
</a>
</c:when>
<c:when test="current-user">
<a href="/asteroid/logout"
lquery='(attr :target (when framesetp "_self"))'
class="btn-logout">
Logout
</a>
</c:when>
</nav>
</c:let>