7.9 KiB · text History 4fe8b36
{% import "_avatar.html" as ui %}<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <link rel="icon" href="/assets/img/favicon.png"/>
    <link rel="stylesheet" href="/assets/css/app.css"/>
    <script defer src="/assets/js/app.js"></script>
    <title>{{ app_name }}{% if title %} :: {{ title }}{% endif %}</title>
    <style>body { font-family: "B612 Mono", monospace; }</style>
    <script>
      // Apply the saved (or system) theme before first paint to avoid a flash.
      (() => {
        const KEY = "app:theme";
        const SYSTEM_DARK = "dark";
        const SYSTEM_LIGHT = "light";
        const mq = window.matchMedia("(prefers-color-scheme: dark)");
        const systemTheme = () => (mq.matches ? SYSTEM_DARK : SYSTEM_LIGHT);
        window.appSetTheme = (theme) => {
          if (theme === "system") {
            localStorage.removeItem(KEY);
            document.documentElement.setAttribute("data-theme", systemTheme());
          } else {
            localStorage.setItem(KEY, theme);
            document.documentElement.setAttribute("data-theme", theme);
          }
        };
        if (!document.documentElement.hasAttribute("data-theme")) {
          window.appSetTheme(localStorage.getItem(KEY) || "system");
        }
        mq.addEventListener("change", () => {
          if (!localStorage.getItem(KEY)) window.appSetTheme("system");
        });
      })();
    </script>
</head>
<!-- hx-boost turns in-app navigation into AJAX swaps of #content, so the nav
     and page chrome persist and only the main region reloads. hx-select pulls
     just #content out of the full page each route returns. -->
<body hx-boost="true"
      hx-target="#content"
      hx-select="#content"
      hx-swap="outerHTML show:window:top"
      {% if user %}data-authed="1"{% endif %}>
<header class="navbar px-4 sm:px-6 lg:px-8 border-b border-base-300 bg-base-200">
    <div class="flex-1 flex items-center gap-3">
        <a href="/" class="flex w-fit items-center gap-2" title="Categories">
            <span class="font-mono font-bold tracking-[0.16em] text-accent">{{ app_name }}</span>
        </a>
        <form method="get" action="/search" class="join hidden md:flex" role="search">
            <input name="q" placeholder="Search…" aria-label="Search"
                   class="input input-bordered input-sm join-item w-40"/>
            <button class="btn btn-sm join-item" type="submit" aria-label="Search"><i class="fas fa-magnifying-glass"></i></button>
        </form>
    </div>
    <div class="flex-none">
        <ul class="flex flex-row items-center gap-1">
            {% if user %}
                <li>
                    <a href="/tags" class="btn btn-ghost btn-sm" title="Tags">
                        <i class="fas fa-tag fa-fw"></i>
                        <span class="hidden lg:inline">Tags</span>
                    </a>
                </li>
                <li>
                    <a href="/reactions" class="btn btn-ghost btn-sm" title="Topics with reactions">
                        <i class="fas fa-heart fa-fw"></i>
                        <span class="hidden lg:inline">Reacted</span>
                    </a>
                </li>
                <li>
                    <a href="/bookmarks" class="btn btn-ghost btn-sm" title="Bookmarks">
                        <i class="fas fa-bookmark fa-fw"></i>
                        <span class="hidden lg:inline">Bookmarks</span>
                    </a>
                </li>
                <li>
                    {# The badge loads lazily and refreshes; it targets itself and
                       opts out of the body's boosted #content select/target. #}
                    <a href="/notifications" class="btn btn-ghost btn-sm relative" title="Notifications">
                        <i class="fas fa-bell fa-fw"></i>
                        <span hx-get="/notifications/unread" hx-trigger="load, every 60s"
                              hx-target="this" hx-select="unset" hx-swap="innerHTML"></span>
                    </a>
                </li>
                {# Generated only when the cookie-injection stack is included. #}
                {% include "_nav_cookies.html" ignore missing %}
                <li>
                    <a href="/invites" class="btn btn-ghost btn-sm">
                        <i class="fas fa-envelope fa-fw"></i>
                        <span class="hidden lg:inline">Invites</span>
                    </a>
                </li>
                <li><span class="divider divider-horizontal mx-0"></span></li>
                <li>{% include "_theme_toggle.html" %}</li>
                <li>
                    <details class="dropdown dropdown-end">
                        <summary class="btn btn-ghost btn-sm">
                            {{ ui.avatar(user.id, user.username, user.avatar_content_type, "size-6", "text-xs") | safe }}
                            <span class="hidden sm:inline truncate max-w-[12ch]">{{ user.username }}</span>
                        </summary>
                        <ul class="dropdown-content menu bg-base-200 border border-base-300 rounded-box z-10 mt-1 w-48 p-1 shadow-lg">
                            <li class="menu-title font-mono text-xs truncate">{{ user.email }}</li>
                            <li><a href="/profile"><i class="fas fa-cog fa-fw"></i> Profile</a></li>
                            <li><a href="/api-tokens"><i class="fas fa-key fa-fw"></i> API tokens</a></li>
                            {% if user.is_staff %}
                            <li class="menu-title text-xs">Admin</li>
                            <li><a href="/admin/categories"><i class="fas fa-folder-tree fa-fw"></i> Categories</a></li>
                            <li><a href="/admin/reactions"><i class="fas fa-face-smile fa-fw"></i> Reactions</a></li>
                            {% endif %}
                            <li>
                                <form action="/auth/logout" method="post" class="m-0" hx-boost="false">
                                    <button type="submit" class="w-full text-left">
                                        <i class="fas fa-sign-out-alt fa-fw"></i> Log out
                                    </button>
                                </form>
                            </li>
                        </ul>
                    </details>
                </li>
            {% else %}
                <li>
                    <a href="/tags" class="btn btn-ghost btn-sm" title="Tags">
                        <i class="fas fa-tag fa-fw"></i>
                        <span class="hidden lg:inline">Tags</span>
                    </a>
                </li>
                <li>{% include "_theme_toggle.html" %}</li>
                <li><a href="/login" class="btn btn-ghost btn-sm">Log in</a></li>
            {% endif %}
        </ul>
    </div>
</header>

{# `main_class` and `width` let a page fill the viewport, as pin_flip's
   Layouts.app `wide` does (visual mode). #}
<main id="content" class="{% block main_class %}px-4 py-12 sm:px-6 lg:px-8{% endblock %}">
    {# Pages can widen the column (visual mode fills the page). #}
    <div class="mx-auto {% block width %}max-w-3xl{% endblock %} space-y-4">
        {# Unverified accounts can read but not write. Inside #content so a
           boosted navigation re-renders it. #}
        {% if user and require_email_verification and not user.email_verified_at %}
        <div class="alert alert-warning text-sm" role="status" id="verify-banner">
            <i class="fas fa-envelope"></i>
            <span>Verify your email address ({{ user.email }}) to post, reply, react and bookmark — use the link we sent you. Until then you can read everything.</span>
            <form method="post" action="/verify-email/resend" class="m-0" hx-boost="false">
                <button type="submit" class="btn btn-xs">Resend link</button>
            </form>
        </div>
        {% endif %}
        {% block content %}{% endblock %}
    </div>
</main>
</body>
</html>