From e52c1e4d491b5ef64575d6b9fb826fba0f9e1d05 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 2 Oct 2026 12:19:08 +0000 Subject: [PATCH] A byline, a way in, and the cell that was not a cell MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three things from a round of looking at the deployed site. **The staggered table rows.** content_list.html had ``, and `.actions` is display:flex. A told to be a flex container stops being a table cell: it leaves the row's layout and draws its bottom border at its own content height, so the columns' rules no longer meet. Nothing errors and the page renders, which is how it survived two rounds of somebody looking straight at it — including mine, when I blamed the wrapping on the Miembros table and rebuilt that page as cards. The flex row moves into a
inside the cell, and test_templates.py now fails on any carrying the class, beside the guards for the things the CSP silently drops. **A published post did not say who wrote it.** The commit has named the author since the editor was built; the page never did, so a reader could not tell whose article it was. frontmatter_for writes `author`, and `author_url` only when that member has published their own page — a byline linking to a 404 is worse than one that does not link. publish() fills it from whoever wrote the thing, which for an approved proposal is the member and not the moderator; edit() deliberately does not, so fixing a typo in somebody's article never re-signs it. The hidden field carrying the URL back is checked against a path on this site, because a hidden field is a convention and not a promise. scripts/translate.py needed no change, which I checked rather than assumed: it copies the whole frontmatter and translates only the title and description, so an author reaches the German and Portuguese siblings untranslated, as a name should. The theme's single.html renders it, verified by building the site with Hugo 0.135 — `por Salvador Dalí` with the link, `por Salvador Dalí` without. **Contenido had no way in.** The page worked and nothing linked to it: Gestión offered only the static pages, and the Artículos tab exists only once you are already on that screen — so a moderator, who cannot open Gestión at all, had no route to the published articles. Gestión gains an Artículos card, Publicaciones gains *Ya publicado* beside its button, and the button that read "Nuevo página" now reads "Nueva página", since Spanish gives the article a gender and "Nuevo " + the singular cannot be right for both. 439 tests pass. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01NizVpJ2dwzCbjCrTLCjeHn --- apps/board/content.py | 78 ++++++++++++++++- apps/board/static/board.css | 3 + apps/board/submissions.py | 6 +- apps/board/templates/content_form.html | 8 +- apps/board/templates/content_list.html | 28 +++--- apps/board/templates/gestion.html | 12 +++ apps/board/templates/submissions.html | 9 +- apps/board/tests/test_content.py | 87 +++++++++++++++++++ apps/board/tests/test_navigation.py | 35 ++++++++ apps/board/tests/test_submissions.py | 21 +++++ apps/board/tests/test_templates.py | 18 ++++ docs/server-setup.md | 14 +++ themes/vienalatina/assets/css/main.css | 12 +++ .../vienalatina/layouts/_default/single.html | 17 ++++ 14 files changed, 331 insertions(+), 17 deletions(-) diff --git a/apps/board/content.py b/apps/board/content.py index 42f70d9..3835c8c 100644 --- a/apps/board/content.py +++ b/apps/board/content.py @@ -48,11 +48,13 @@ bp = Blueprint("content", __name__) # structure, and changing "Acerca de" is an administrator's job. COLLECTIONS = { "post": { - "label": "Artículos", "singular": "Artículo", + "label": "Artículos", "singular": "Artículo", "new_label": "Nuevo artículo", "folder": "content/post", "dated": True, "role": "moderator", }, "page": { - "label": "Páginas", "singular": "Página", + # `new_label` spelled out rather than "Nuevo " + the singular: Spanish + # gives the article a gender, and the button read "Nuevo página". + "label": "Páginas", "singular": "Página", "new_label": "Nueva página", "folder": "content/page", "dated": False, "role": "admin", }, } @@ -69,6 +71,11 @@ BODY_MAX = 100_000 # file in the repository — the pipeline and the Caddyfile included. SAFE_NAME = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._-]*\.es\.md$") +# A byline links to a profile on this site or to nothing. Same shape as a +# username, with the leading slash, so no form can turn an author link into a +# link somewhere else. +AUTHOR_URL = re.compile(r"^/[A-Za-z0-9][A-Za-z0-9._-]{0,38}$") + # --- the contract with translate.py -------------------------------------- @@ -114,6 +121,19 @@ def frontmatter_for(collection: str, form: dict) -> dict: fields["description"] = form["description"] if form["image"]: fields["image"] = form["image"] + # Who wrote it, for the page rather than for git. The commit has named + # the author since the editor was built; the article did not, so a + # reader could not tell whose it was or click through to them. + # + # `author_url` is only ever set when that member has published their + # page — a byline linking to a 404 is worse than a byline that does not + # link. translate.py copies both into the German and Portuguese + # siblings by itself: it carries the whole frontmatter and translates + # only title and description, and a name is not translated. + if form.get("author"): + fields["author"] = form["author"] + if form.get("author_url"): + fields["author_url"] = form["author_url"] return fields @@ -211,6 +231,16 @@ def _read_form(collection: str) -> tuple[dict, str, list[str]]: errors.append("La fecha debe tener el formato AAAA-MM-DD.") categories = [c for c in request.form.getlist("categories") if c in CATEGORIES] + + # Carried through the form as hidden fields, the way the date and the image + # path are: they belong to the document being edited, not to whoever is + # editing it, so saving a correction must not re-sign the post. Checked on + # the way back in because a hidden field is only a convention — the URL has + # to be a path on this site and nothing else. + author = request.form.get("author", "").strip()[:80] + author_url = request.form.get("author_url", "").strip() + if author_url and not AUTHOR_URL.match(author_url): + author_url = "" image = request.form.get("image", "").strip() if image and not re.match(r"^/uploads/[A-Za-z0-9._-]+$", image): errors.append("La imagen no es válida.") @@ -226,6 +256,7 @@ def _read_form(collection: str) -> tuple[dict, str, list[str]]: "description": request.form.get("description", "").strip(), "image": image, "manual_translation": request.form.get("manual_translation") == "on", + "author": author, "author_url": author_url, } return fields, body, errors @@ -271,6 +302,40 @@ def _upload_image() -> str: return commit_picture(upload.read(), upload.filename) +def _field(row, name, default=None): + """One lookup that works on a sqlite3.Row and on a plain dict. + + They disagree about what a missing key is — IndexError for one, KeyError for + the other — and `approve` hands this a dict built from a row, so both arrive + here. + """ + try: + return row[name] + except (KeyError, IndexError): + return default + + +def byline(author) -> dict: + """The two frontmatter keys naming a writer, from their member row. + + Takes the row (or the plain dict `submissions.approve` builds from one), so + that a post published through the editor and a proposal approved by somebody + else produce the same two keys from the same code — and in the second case + they name the member, not the moderator who pressed the button. + """ + if author is None: + return {} + login = _field(author, "gitea_login", "") + name = _field(author, "display_name", "") or login + if not name: + return {} + published = _field(author, "profile_published", 0) + return { + "author": name, + "author_url": f"/{login}" if published and login else "", + } + + def publish(collection: str, fields: dict, body: str, author) -> str: """Write one post or page into the repository and return its path. @@ -280,6 +345,7 @@ def publish(collection: str, fields: dict, body: str, author) -> str: the button: `gitea.write_file` sends author and committer per commit, so an approved submission keeps the member's name in git history. """ + fields = dict(fields, **byline(author)) name = filename_for(collection, fields["title"], fields["date"]) path = f"{COLLECTIONS[collection]['folder']}/{name}" document = build_document(frontmatter_for(collection, fields), body) @@ -357,6 +423,12 @@ def edit(collection: str, name: str): "description": fm.get("description", ""), "image": fm.get("image", ""), "manual_translation": bool(fm.get("manual_translation")), + # Carried through the form untouched. Correcting a typo in somebody + # else's post must not re-sign it with the name of whoever is + # fixing it — the same rule the board has about editing other + # people's words, applied to the byline. + "author": fm.get("author", ""), + "author_url": fm.get("author_url", ""), } return render_template("content_form.html", collection=collection, meta=meta, categories=CATEGORIES, item={"name": name, "sha": sha}, @@ -373,6 +445,8 @@ def edit(collection: str, name: str): picture = _upload_image() if picture: fields["image"] = picture + # Deliberately not through publish(): that stamps the byline of whoever + # is publishing, and an edit keeps the author the file already names. document = build_document(frontmatter_for(collection, fields), body) gitea.write_file(path, document.encode("utf-8"), f"content: actualizar «{fields['title']}»", diff --git a/apps/board/static/board.css b/apps/board/static/board.css index 6f1dbc6..c2f6123 100644 --- a/apps/board/static/board.css +++ b/apps/board/static/board.css @@ -112,6 +112,9 @@ button, input, select, textarea { font: inherit; } margin-bottom: 1.5rem; } .feed-head h1 { margin: 0; } +/* Two things on the right of a heading — a link and a button — kept on one + line and aligned to each other rather than to the heading's baseline. */ +.feed-head__actions { display: flex; align-items: center; gap: 1rem; } .card { background: var(--surface); diff --git a/apps/board/submissions.py b/apps/board/submissions.py index 547d9ff..e8152d4 100644 --- a/apps/board/submissions.py +++ b/apps/board/submissions.py @@ -298,7 +298,11 @@ def approve(submission_id: int): return redirect(url_for("submissions.index")) author = {"display_name": row["author"], "email": row["author_email"], - "gitea_login": row["author_login"]} + "gitea_login": row["author_login"], + # For the byline on the published page: it links to their profile + # only if they have one, so an approved post never carries a link + # to a 404. + "profile_published": row["author_published"]} fields = { "title": row["title"], # The day it is published, not the day it was written: Hugo sorts by diff --git a/apps/board/templates/content_form.html b/apps/board/templates/content_form.html index 5cc3183..92ee012 100644 --- a/apps/board/templates/content_form.html +++ b/apps/board/templates/content_form.html @@ -20,8 +20,14 @@ {% endif %} + {# The byline travels with the document, like the date and the image path. + An edit keeps whoever wrote it; only publishing sets it. #} + {% if f and f.author %} + + + {% endif %} -

{{ 'Editar' if item else 'Nuevo' }} {{ meta.singular|lower }}

+

{{ ('Editar ' ~ meta.singular|lower) if item else meta.new_label }}

diff --git a/apps/board/templates/content_list.html b/apps/board/templates/content_list.html index 8a5537c..eaa9ca6 100644 --- a/apps/board/templates/content_list.html +++ b/apps/board/templates/content_list.html @@ -4,9 +4,7 @@ {% block main %}