12.9 KiB · text History 263b40b
{% 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>

    {# Link previews (src/meta.rs): unfurlers fetch once and read only this
       block. Public pages pass a `meta` (PageMeta), always built as an
       anonymous visitor would see the page. Pages without one (admin, auth,
       profile, devices, moderation, bookmarks, notifications, reactions,
       search) get the site name, the generic description and noindex. #}
    {% set m = meta | default({}) %}
    {% set og_title = m.title | default(app_name) %}
    {% set og_description = m.description | default(site_description(app_name)) %}
    <meta name="description" content="{{ og_description | attr }}"/>
    <meta name="robots" content="{% if m.noindex | default(true) %}noindex, nofollow{% else %}index, follow{% endif %}"/>
    {% if m.url %}<link rel="canonical" href="{{ m.url | attr }}"/>{% endif %}
    <meta property="og:site_name" content="{{ app_name | attr }}"/>
    <meta property="og:type" content="{{ m.kind | default('website') | attr }}"/>
    <meta property="og:title" content="{{ og_title | attr }}"/>
    <meta property="og:description" content="{{ og_description | attr }}"/>
    {% if m.url %}<meta property="og:url" content="{{ m.url | attr }}"/>{% endif %}
    {% if m.image %}
    <meta property="og:image" content="{{ m.image | attr }}"/>
    <meta property="og:image:alt" content="{{ m.image_alt | attr }}"/>
    {% if m.image_width %}<meta property="og:image:width" content="{{ m.image_width }}"/><meta property="og:image:height" content="{{ m.image_height }}"/>{% endif %}
    {% endif %}
    {% if m.kind == "article" %}
    {% if m.published %}<meta property="article:published_time" content="{{ m.published | attr }}"/>{% endif %}
    {% if m.modified %}<meta property="article:modified_time" content="{{ m.modified | attr }}"/>{% endif %}
    {% if m.section %}<meta property="article:section" content="{{ m.section | attr }}"/>{% endif %}
    {% for t in m.tags %}<meta property="article:tag" content="{{ t | attr }}"/>{% endfor %}
    {% if m.author %}<meta name="author" content="{{ m.author | attr }}"/>{% endif %}
    {% endif %}
    <meta name="twitter:card" content="{{ m.twitter_card | default('summary') | attr }}"/>
    <meta name="twitter:title" content="{{ og_title | attr }}"/>
    <meta name="twitter:description" content="{{ og_description | attr }}"/>
    {% if m.image %}<meta name="twitter:image" content="{{ m.image | attr }}"/>{% endif %}
    <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"
      data-shader-default="{{ shader_default }}"
      {% if user %}data-authed="1"{% endif %}>
{# The theme-primary tint for reaction emoji (.emoji-tint in style.css): greyscale
   for the shading, the primary's hue and saturation on top, clipped to the
   glyph. Sized 0 and positioned away rather than display:none, which would
   switch the filter off in some browsers. #}
<svg width="0" height="0" class="absolute" aria-hidden="true" focusable="false">
  <filter id="emoji-tint" color-interpolation-filters="sRGB">
    <feColorMatrix in="SourceGraphic" type="saturate" values="0" result="grey"/>
    <feFlood style="flood-color: oklch(var(--p))" result="primary"/>
    <feComposite in="primary" in2="SourceAlpha" operator="in" result="shape"/>
    <feBlend in="shape" in2="grey" mode="color" result="tinted"/>
    <feComposite in="tinted" in2="SourceAlpha" operator="in"/>
  </filter>
</svg>
<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="Home">
            <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" minlength="3" required title="Type at least 3 characters"
                   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="/c/" class="btn btn-ghost btn-sm" title="Categories">
                        <i class="fas fa-folder-tree fa-fw"></i>
                        <span class="hidden lg:inline">Categories</span>
                    </a>
                </li>
                <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="/devices"><i class="fas fa-mobile-screen fa-fw"></i> Devices</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>
                            <li><a href="/admin/flags"><i class="fas fa-flag fa-fw"></i> Flags</a></li>
                            <li><a href="/admin/users"><i class="fas fa-users fa-fw"></i> Users</a></li>
                            <li><a href="/admin/log"><i class="fas fa-clipboard-list fa-fw"></i> Moderation log</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="/c/" class="btn btn-ghost btn-sm" title="Categories">
                        <i class="fas fa-folder-tree fa-fw"></i>
                        <span class="hidden lg:inline">Categories</span>
                    </a>
                </li>
                <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>

{# Live updates for signed-in users (src/live.rs, f/js/live.js): one socket,
   outside #content so boosted navigation keeps it open. The server swaps
   #live-signal in when a topic this user can see has new activity; the
   page's lists marked data-live then refetch themselves. #}
{% if user %}
<div id="live" hx-ext="ws" ws-connect="/ws" hidden><div id="live-signal"></div></div>
{% endif %}
{# `main_class` and `width` let a page fill the viewport, as pin_flip's
   Layouts.app `wide` does (visual mode). #}
{# `layout` marks Focus pages (data-layout="focus"): with a shader on, their
   panel is sea glass instead of opaque (style.css). #}
<main id="content" data-layout="{% block layout %}classic{% endblock %}" 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 %}
        {% if user %}{% set silenced = silence_notice(user) %}{% if silenced %}
        <div class="alert alert-error text-sm" role="status" id="silence-banner">
            <i class="fas fa-comment-slash"></i><span>{{ silenced }}</span>
        </div>
        {% endif %}{% endif %}
        {% block content %}{% endblock %}
    </div>
</main>
</body>
</html>