No recipes yet. Add one in src/safe_family/urls/recipes_data.py.
+ {% endif %}
+
+{% endblock %}
diff --git a/src/safe_family/urls/miscellaneous.py b/src/safe_family/urls/miscellaneous.py
index bdbced0..0939d4f 100644
--- a/src/safe_family/urls/miscellaneous.py
+++ b/src/safe_family/urls/miscellaneous.py
@@ -2,12 +2,13 @@
from datetime import datetime
-from flask import Blueprint, flash, redirect, render_template, request
+from flask import Blueprint, abort, flash, redirect, render_template, request
from config.settings import settings
from src.safe_family.core.auth import get_current_username, login_required
from src.safe_family.core.extensions import db
from src.safe_family.core.models import CountdownConfig
+from src.safe_family.urls.recipes_data import RECIPES
root_bp = Blueprint("index", __name__)
@@ -41,6 +42,26 @@ def calc_guide():
return render_template("miscellaneous/calc_guide.html")
+@root_bp.route("/recipes")
+@login_required
+def recipes():
+ """Render the recipe list.
+
+ Recipes are static data in recipes_data.py, edited by hand.
+ """
+ return render_template("miscellaneous/recipes.html", recipes=RECIPES)
+
+
+@root_bp.route("/recipes/")
+@login_required
+def recipe_detail(slug: str):
+ """Render one recipe with its ingredients and steps."""
+ recipe = next((r for r in RECIPES if r["slug"] == slug), None)
+ if recipe is None:
+ abort(404)
+ return render_template("miscellaneous/recipe_detail.html", recipe=recipe)
+
+
@root_bp.route("/yaw_calc")
@login_required
def yaw_calc():
diff --git a/src/safe_family/urls/recipes_data.py b/src/safe_family/urls/recipes_data.py
new file mode 100644
index 0000000..9dd35dd
--- /dev/null
+++ b/src/safe_family/urls/recipes_data.py
@@ -0,0 +1,48 @@
+"""Recipes shown on the /recipes page (Sheet section). Edit by hand.
+
+To add a recipe, copy one whole ``{...},`` block below, paste it under the
+last one and change the values:
+
+- ``slug``: short unique id used in the page address (/recipes/), only
+ lowercase letters, digits and dashes.
+- ``image``: a file in src/safe_family/static/recipes/ (JPG, PNG, WEBP or
+ SVG). Leave it as "" for no picture.
+- ``ingredients`` and ``steps``: one string per line, in order.
+- ``servings``, ``time``, ``tags`` and ``notes`` are optional; use "" or [].
+
+``tests/test_recipes.py`` checks this file (required fields, unique slugs,
+pictures that exist), so run ``pytest -q tests/test_recipes.py --no-cov``
+after editing. The app reads it at startup: rebuild with
+``docker compose up -d --build app``.
+"""
+
+RECIPES = [
+ {
+ "slug": "tomato-egg-stir-fry",
+ "title": "Tomato and Egg Stir-Fry",
+ "summary": "Soft scrambled eggs in a sweet-sour tomato sauce. Ready in 15 minutes, great over rice.",
+ "image": "tomato-egg-stir-fry.svg",
+ "servings": "2",
+ "time": "15 min",
+ "tags": ["dinner", "quick", "vegetarian"],
+ "ingredients": [
+ "4 eggs",
+ "3 ripe tomatoes, cut into wedges",
+ "2 green onions, sliced (white and green parts apart)",
+ "1 tbsp ketchup",
+ "1 tsp sugar",
+ "1/2 tsp salt",
+ "3 tbsp cooking oil",
+ "2 tbsp water",
+ ],
+ "steps": [
+ "Beat the eggs with a pinch of salt until smooth.",
+ "Heat 2 tbsp oil in a wok over medium-high heat. Pour in the eggs, stir gently until just set but still soft, then move them to a plate.",
+ "Add the remaining oil, fry the white parts of the green onion for 10 seconds, then add the tomatoes.",
+ "Cook the tomatoes for 2-3 minutes, pressing them a little, until they turn saucy. Stir in the ketchup, sugar, salt and water.",
+ "Return the eggs, fold them through the sauce for 30 seconds, and top with the green onion tops.",
+ "Serve right away with steamed rice.",
+ ],
+ "notes": "Very ripe tomatoes give the best sauce; in winter add 1 extra tbsp ketchup.",
+ },
+]
diff --git a/tests/test_recipes.py b/tests/test_recipes.py
new file mode 100644
index 0000000..3fe84dd
--- /dev/null
+++ b/tests/test_recipes.py
@@ -0,0 +1,115 @@
+"""Tests for the static recipe pages and the hand-edited recipe data."""
+
+import re
+from pathlib import Path
+
+import pytest
+
+from src.safe_family.urls.recipes_data import RECIPES
+
+STATIC_RECIPES = Path(__file__).resolve().parents[1] / "src" / "safe_family" / "static" / "recipes"
+REQUIRED_TEXT = ("slug", "title", "summary")
+OPTIONAL_TEXT = ("image", "servings", "time", "notes")
+
+
+def _article(html):
+ """The recipe article only, without the shared page layout."""
+ return html.split('', 1)[1].split("", 1)[0]
+
+
+def _login(client, monkeypatch):
+ monkeypatch.setattr(
+ "src.safe_family.core.auth.decode_token",
+ lambda token: {"sub": "user"},
+ )
+ with client.session_transaction() as sess:
+ sess["access_token"] = "token"
+
+
+def test_recipes_data_has_an_example():
+ assert RECIPES, "keep at least one recipe so the page has an example to copy"
+
+
+@pytest.mark.parametrize("recipe", RECIPES, ids=lambda r: r.get("slug", "?"))
+def test_recipe_entry_is_well_formed(recipe):
+ allowed = set(REQUIRED_TEXT) | set(OPTIONAL_TEXT) | {"tags", "ingredients", "steps"}
+ assert set(recipe) <= allowed, f"unknown keys: {set(recipe) - allowed}"
+ for key in REQUIRED_TEXT:
+ assert isinstance(recipe.get(key), str), f"{key} must be text"
+ assert recipe[key].strip(), f"{key} is empty"
+ for key in OPTIONAL_TEXT:
+ assert isinstance(recipe.get(key, ""), str), f"{key} must be text"
+ assert re.fullmatch(r"[a-z0-9]+(-[a-z0-9]+)*", recipe["slug"]), "slug: lowercase letters, digits, dashes"
+ for key in ("ingredients", "steps"):
+ items = recipe.get(key)
+ assert isinstance(items, list), f"{key} must be a list of lines"
+ assert items, f"{key} is empty"
+ assert all(isinstance(i, str) and i.strip() for i in items), f"{key} has an empty or non-text line"
+ tags = recipe.get("tags", [])
+ assert isinstance(tags, list), "tags must be a list"
+ assert all(isinstance(t, str) for t in tags), "tags must be text"
+ if recipe.get("image"):
+ assert (STATIC_RECIPES / recipe["image"]).is_file(), f"picture not found: static/recipes/{recipe['image']}"
+
+
+def test_recipe_slugs_are_unique():
+ slugs = [r["slug"] for r in RECIPES]
+ assert len(slugs) == len(set(slugs)), "two recipes share a slug"
+
+
+def test_recipes_require_login(client):
+ resp = client.get("/recipes")
+ assert resp.status_code == 302
+ assert resp.location.endswith("/auth/login-ui")
+
+
+def test_recipes_list_renders_cards(client, monkeypatch):
+ _login(client, monkeypatch)
+ resp = client.get("/recipes")
+ html = resp.get_data(as_text=True)
+ assert resp.status_code == 200
+ for recipe in RECIPES:
+ assert recipe["title"] in html
+ assert f'/recipes/{recipe["slug"]}' in html
+
+
+def test_recipe_detail_shows_ingredients_steps_and_picture(client, monkeypatch):
+ _login(client, monkeypatch)
+ recipe = RECIPES[0]
+ resp = client.get(f"/recipes/{recipe['slug']}")
+ assert resp.status_code == 200
+ article = _article(resp.get_data(as_text=True))
+ assert recipe["title"] in article
+ assert article.count('type="checkbox"') == len(recipe["ingredients"])
+ steps = article.split('', 1)[1].split("", 1)[0]
+ assert steps.count("
") == len(recipe["steps"])
+ if recipe.get("image"):
+ assert f"/static/recipes/{recipe['image']}" in article
+
+
+def test_recipe_detail_unknown_slug_is_404(client, monkeypatch):
+ _login(client, monkeypatch)
+ assert client.get("/recipes/no-such-recipe").status_code == 404
+
+
+def test_recipe_without_picture_or_optional_fields(client, monkeypatch):
+ _login(client, monkeypatch)
+ bare = {
+ "slug": "bare",
+ "title": "Bare Recipe",
+ "summary": "No picture.",
+ "ingredients": ["water"],
+ "steps": ["boil"],
+ }
+ monkeypatch.setattr("src.safe_family.urls.miscellaneous.RECIPES", [bare])
+ listing = client.get("/recipes").get_data(as_text=True)
+ assert "recipe-card-img--empty" in listing
+ detail = client.get("/recipes/bare")
+ assert detail.status_code == 200
+ assert "
Date: Tue, 3 Nov 2026 12:41:09 +0000
Subject: [PATCH 2/3] Fit the top navigation bar on phones
The bar was one fixed row (brand, eight links, user), so on a phone it
made every page about 660px wide and scroll sideways.
- Up to 900px: brand and user stay on the first row; the links move to a
full-width second row that wraps.
- Up to 480px: the links form a balanced grid (4 + 3) and the ZZUSE mark
and user name text are hidden (the avatar shows the initial), keeping
the first row on one line.
Desktop is unchanged. Checked at 320, 360, 390, 430, 768 and 1280px on
the Sheet, recipe, notes, blog and calculator pages, logged in as admin
and logged out: no page is wider than the screen.
Co-Authored-By: Claude Opus 5.5
Claude-Session: https://claude.ai/code/session_01CKZWtPcMA8pSrVvGGwno21
---
src/safe_family/templates/base.html | 50 ++++++++++++++++++++++++++++-
1 file changed, 49 insertions(+), 1 deletion(-)
diff --git a/src/safe_family/templates/base.html b/src/safe_family/templates/base.html
index 2d6357d..0b956ea 100644
--- a/src/safe_family/templates/base.html
+++ b/src/safe_family/templates/base.html
@@ -219,6 +219,54 @@
font-weight: 700;
}
+ /* Phones and narrow windows: brand and user on the first row, the
+ links on their own full-width row that wraps, so the bar never
+ makes the page wider than the screen. */
+ @media (max-width: 900px) {
+ .sf-shell {
+ padding: 0 16px 48px;
+ }
+
+ .sf-topbar {
+ flex-wrap: wrap;
+ row-gap: 10px;
+ }
+
+ .sf-nav {
+ order: 3;
+ width: 100%;
+ flex-wrap: wrap;
+ justify-content: center;
+ gap: 4px;
+ }
+
+ .sf-nav a {
+ padding: 6px 8px;
+ }
+ }
+
+ /* Small phones: keep the first row to one line. The avatar shows the
+ user's initial, so the name text can go. */
+ @media (max-width: 480px) {
+ .sf-brand-tm,
+ .sf-user-name {
+ display: none;
+ }
+
+ /* Balanced rows (4 + 3) instead of one link left alone. */
+ .sf-nav {
+ display: grid;
+ grid-template-columns: repeat(4, max-content);
+ justify-content: center;
+ gap: 4px 6px;
+ }
+
+ .sf-nav a {
+ padding: 6px 8px;
+ text-align: center;
+ }
+ }
+
/* ===== flash ===== */
.flash {
padding: 10px 14px;
@@ -552,7 +600,7 @@
{% if session.access_token %}
{% if session.role == 'admin' %}GAME MASTER{% endif %}
- {{ session.user_name or '' }}
+ {{ session.user_name or '' }}
{{ (session.user_name or 'M')[:1]|upper }}
{% endif %}
From 884461c07b158d1f094fc96c55192bb3189e0a6d Mon Sep 17 00:00:00 2001
From: Claude
Date: Tue, 3 Nov 2026 21:16:58 +0000
Subject: [PATCH 3/3] Top bar: real user initial and name, Logout beside the
avatar
The avatar always showed 'M' and the name was empty: the template read
session.user_name, which login never sets (same for session.role, so the
GAME MASTER badge never appeared). A context processor now looks up the
logged-in user per request (get_current_username) and gives the template
their username, initial and admin flag; admin still requires the
configured ADMIN_IDENTITY, as elsewhere. A missing user or a database
error falls back to '?' instead of failing the page.
Logout moves from the menu to the user area. On phones the six links fit
on one row from 320px up (tighter spacing under 340px), the badge gives
way to an accent ring on the admin's avatar, and the 4-column grid is
gone. Checked at 320-1280px as admin and as a normal user.
Co-Authored-By: Claude Opus 5.5
Claude-Session: https://claude.ai/code/session_01CKZWtPcMA8pSrVvGGwno21
---
src/safe_family/app.py | 27 +++++++-
src/safe_family/templates/base.html | 48 +++++++++----
tests/test_nav_user.py | 101 ++++++++++++++++++++++++++++
3 files changed, 161 insertions(+), 15 deletions(-)
create mode 100644 tests/test_nav_user.py
diff --git a/src/safe_family/app.py b/src/safe_family/app.py
index 33ba210..ed0e947 100644
--- a/src/safe_family/app.py
+++ b/src/safe_family/app.py
@@ -2,13 +2,14 @@
from datetime import timedelta
-from flask import Flask, jsonify
+from flask import Flask, jsonify, session
+from sqlalchemy.exc import SQLAlchemyError
from config.logging import setup_logging
from config.settings import settings
from src.safe_family.api.routes import api_bp
from src.safe_family.auto_git.auto_git import auto_git_bp
-from src.safe_family.core.auth import auth_bp
+from src.safe_family.core.auth import auth_bp, get_current_username
from src.safe_family.core.extensions import db, jwt, mail
from src.safe_family.core.models import User
from src.safe_family.rules.scheduler import schedule_rules_bp
@@ -38,6 +39,26 @@ def _require_strong_secret(name: str, value: str | None) -> None:
raise RuntimeError(msg)
+def inject_nav_user() -> dict:
+ """Give the top bar the logged-in user's name, initial and admin flag."""
+ if not session.get("access_token"):
+ return {"nav_user": None}
+ try:
+ user = get_current_username()
+ except SQLAlchemyError:
+ return {"nav_user": None}
+ if user is None:
+ return {"nav_user": None}
+ name = (user.username or "").strip()
+ return {
+ "nav_user": {
+ "name": name,
+ "initial": name[:1].upper() or "?",
+ "is_admin": user.role == "admin",
+ },
+ }
+
+
def create_app():
"""Create and configure the Flask application."""
_require_strong_secret("FLASK_APP_SECRET_KEY", settings.APP_SECRET_KEY)
@@ -72,6 +93,8 @@ def inject_motto() -> dict:
"""Inject the app motto into all templates."""
return {"motto": settings.APP_MOTTO}
+ app.context_processor(inject_nav_user)
+
app.register_blueprint(root_bp)
app.register_blueprint(notes_bp)
app.register_blueprint(blog_bp)
diff --git a/src/safe_family/templates/base.html b/src/safe_family/templates/base.html
index 0b956ea..13e2e28 100644
--- a/src/safe_family/templates/base.html
+++ b/src/safe_family/templates/base.html
@@ -219,6 +219,19 @@
font-weight: 700;
}
+ .sf-user-logout {
+ padding: 4px 10px;
+ border: 1px solid var(--sf-border-strong);
+ border-radius: 6px;
+ color: var(--sf-ink-muted);
+ text-decoration: none;
+ }
+
+ .sf-user-logout:hover {
+ color: var(--sf-ink);
+ background: var(--sf-surface);
+ }
+
/* Phones and narrow windows: brand and user on the first row, the
links on their own full-width row that wraps, so the bar never
makes the page wider than the screen. */
@@ -246,24 +259,32 @@
}
/* Small phones: keep the first row to one line. The avatar shows the
- user's initial, so the name text can go. */
+ user's initial and, for the admin, a ring in place of the badge. */
@media (max-width: 480px) {
.sf-brand-tm,
- .sf-user-name {
+ .sf-user-name,
+ .sf-user-badge {
display: none;
}
- /* Balanced rows (4 + 3) instead of one link left alone. */
+ .sf-avatar.is-admin {
+ box-shadow: 0 0 0 2px var(--sf-bg), 0 0 0 4px var(--sf-accent);
+ }
+
.sf-nav {
- display: grid;
- grid-template-columns: repeat(4, max-content);
- justify-content: center;
- gap: 4px 6px;
+ gap: 2px;
}
.sf-nav a {
- padding: 6px 8px;
- text-align: center;
+ padding: 6px 7px;
+ }
+ }
+
+ /* Smallest phones (320px): tighter links keep the menu on one row. */
+ @media (max-width: 340px) {
+ .sf-nav a {
+ padding: 6px 4px;
+ font-size: 12px;
}
}
@@ -591,7 +612,6 @@
class="{% if request.endpoint == 'schedule_rules.schedule_rules' %}active{% endif %}">Schedule
Sheet
- Logout
{% else %}
LoginRegister
@@ -599,9 +619,11 @@
{% if session.access_token %}
- {% if session.role == 'admin' %}GAME MASTER{% endif %}
- {{ session.user_name or '' }}
-
{{ (session.user_name or 'M')[:1]|upper }}
+ {% if nav_user and nav_user.is_admin %}GAME MASTER{% endif %}
+ {% if nav_user %}{{ nav_user.name }}{% endif %}
+