Decap looks like a different product because it cannot be made to look like this one: its maintainer's answer is override the CSS and accept that class names move between releases, or fork it and carry that forever. Neither is worth building on, so editing moves into the app that already has the site's design and this project's tests. Posts are files in git, so the editor is a form that commits a file through Gitea's contents API. No working copy, no queue, no new state, and no way for the pipeline to tell which editor wrote the file — which is what makes running both at once safe. Decap keeps working; nothing here removes it, and the fallback if something is missing is switching tabs. Filenames and frontmatter are not this module's to invent. They are the contract scripts/translate.py reads: `<basename>.es.md` is what split_lang() parses, the date prefix is what keeps two posts with one title off a single URL, and the absence of `translated_from` is what marks a file as something a person wrote. Several tests import translate.py and run its own parser over what the editor produced, because a file it cannot parse publishes in Spanish and is never translated, with nothing reported anywhere. Commits carry the writer's own Gitea account rather than a bot's, so history says who wrote each post and Gitea's permissions apply unchanged. That needs their access token, which lives in the database and never in a cookie: Flask signs cookies but does not encrypt them, and a token is enough to commit as its owner. Gitea expires tokens after about an hour, so they refresh ahead of expiry and retry once on rejection — without that, saving would start failing partway through an afternoon for no reason the writer could see. Publishing is admin-only. Posting to the internal board and publishing to the public site are different permissions, and the second is the larger grant. Listing caches frontmatter against the git blob sha, because the contents API returns names without bodies: that turns one request per post on every page load into one request in total, and needs no invalidation, since a sha changes only when the file does. Verified: 97 checks. The filename translate.py parses, an authored source that is_generated() rejects, the freeze toggle round-tripping, a stale sha refused with the other edit intact, six filename shapes that must 404 including a generated sibling, plain members refused, an SVG rejected as an image, uploads not colliding, the cache reading each file once and refreshing when it changes, and a preview that renders markdown, escapes script tags and publishes nothing. Smoke-tested live: routes register and gate correctly. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NizVpJ2dwzCbjCrTLCjeHn
76 lines
2.7 KiB
HTML
76 lines
2.7 KiB
HTML
{% extends "base.html" %}
|
|
{% block title %}{{ 'Editar' if item else 'Nuevo' }} {{ meta.singular|lower }}{% endblock %}
|
|
|
|
{% set f = fields or {} %}
|
|
|
|
{% block main %}
|
|
{% if preview_html %}
|
|
<article class="card">
|
|
<div class="card__meta"><span class="tag tag--quiet">Vista previa</span></div>
|
|
<h1 class="card__title">{{ f.title }}</h1>
|
|
<div class="prose">{{ preview_html }}</div>
|
|
</article>
|
|
{% endif %}
|
|
|
|
<form class="card" method="post" enctype="multipart/form-data"
|
|
action="{{ url_for('content.edit', collection=collection, name=item.name) if item
|
|
else url_for('content.new', collection=collection) }}">
|
|
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
|
{% if item %}
|
|
<input type="hidden" name="sha" value="{{ item.sha }}">
|
|
<input type="hidden" name="name" value="{{ item.name }}">
|
|
{% endif %}
|
|
|
|
<h1>{{ 'Editar' if item else 'Nuevo' }} {{ meta.singular|lower }}</h1>
|
|
|
|
<label for="title">Título</label>
|
|
<input id="title" name="title" maxlength="140" required value="{{ f.title or '' }}">
|
|
|
|
{% if meta.dated %}
|
|
<label for="date">Fecha</label>
|
|
<input id="date" name="date" type="date" required value="{{ f.date or today }}">
|
|
{% endif %}
|
|
|
|
{% if collection == 'post' %}
|
|
<fieldset class="fieldset">
|
|
<legend>Categorías</legend>
|
|
{% for category in categories %}
|
|
<label class="check">
|
|
<input type="checkbox" name="categories" value="{{ category }}"
|
|
{{ 'checked' if category in (f.categories or []) }}>
|
|
{{ category }}
|
|
</label>
|
|
{% endfor %}
|
|
</fieldset>
|
|
|
|
<label for="description">Resumen</label>
|
|
<textarea id="description" name="description" rows="2">{{ f.description or '' }}</textarea>
|
|
|
|
<label for="picture">Imagen destacada</label>
|
|
{% if f.image %}
|
|
<p class="muted small">Actual: <span class="mono">{{ f.image }}</span> — sube otra para reemplazarla.</p>
|
|
<input type="hidden" name="image" value="{{ f.image }}">
|
|
{% endif %}
|
|
<input id="picture" name="picture" type="file" accept="image/*">
|
|
{% endif %}
|
|
|
|
<label for="body">Cuerpo</label>
|
|
<textarea id="body" name="body" rows="18" required
|
|
placeholder="Markdown: **negrita**, ## títulos, listas, [enlaces](https://…).">{{ body }}</textarea>
|
|
|
|
<label class="check">
|
|
<input type="checkbox" name="manual_translation" {{ 'checked' if f.manual_translation }}>
|
|
Traducción manual — no generar alemán ni portugués para esto
|
|
</label>
|
|
|
|
<div class="actions">
|
|
<button class="btn" type="submit">{{ 'Guardar' if item else 'Publicar' }}</button>
|
|
<button class="linkish" type="submit"
|
|
formaction="{{ url_for('content.preview', collection=collection) }}">
|
|
Vista previa
|
|
</button>
|
|
<a class="linkish" href="{{ url_for('content.index', collection=collection) }}">Cancelar</a>
|
|
</div>
|
|
</form>
|
|
{% endblock %}
|