The brand colours were two identical `:root` blocks — one in the theme, one in
the members area's stylesheet — with a comment in the second reading *"If the
brand colours change, change them in both."* There was no logo anywhere, no
favicon in either `<head>`, and `params.defaultImage` was the empty string with
a comment saying it was waiting for one. Every one of those was a change only
somebody with the repository could make.
`brand.FACTORY` is the single source of truth for the palette now, and
`test_brand.py` parses both stylesheets and fails the build if either drifts
from it. That is what retires the comment: not by merging the two files — they
are served by different things and each has to stand alone — but by making a
divergence fail a test instead of going unnoticed for a month.
**Gestión → Marca**, admins only, saves to two places in one submit, because
the two halves of the site cannot read the same store: SQLite for the members
area, which must render when the git server is down, and `data/brand.yaml` plus
`static/brand/` in the content repository for the public site, which is files
on disk. SQLite is written first and the commits follow — if Gitea is
unreachable the change still takes effect here, `published_at` stays NULL, and
the screen offers to try the publish again. The other order would let a git
outage block a change that does not need git.
The easy half is six colour pickers, each with the name of what it changes, and
a live preview of the real chrome. The three brand shades are worked out from
the brand colour in HLS, so one picked colour gives a coherent set rather than
one red button on an orange background; scaling RGB towards white would have
washed the hue out. A WCAG contrast warning names any pair that will be hard to
read, with its ratio, and saves it anyway: an admin may have a reason, and what
this prevents is shipping an unreadable site without once being told.
The advanced half, behind a fold, is every token as a text field and a free CSS
box appended last so it wins. **The Marca screen deliberately does not load the
generated stylesheet** — every other page does — which is what keeps *Restaurar
lo de fábrica* reachable after somebody writes `* { display: none }` into that
box, and the reason the colours an admin picks do not show on the page where
they pick them. The preview block is where they do.
Only differences from the factory are stored, so a token added later arrives
with its default already in place for every existing install. Both halves serve
a generated stylesheet rather than an inline `<style>`, because the CSP has no
'unsafe-inline' and an inline block would simply not apply.
The logo also fills the gap phase I left: it is the share-card fallback and the
`Organization` logo, ahead of `defaultImage`, and the home page carries
`og:image` for the first time — the front page of the site was the last place
that should share as a bare link.
No SVG and no ICO: the logo takes PNG, JPG or WebP and the favicon PNG, both
identified from their bytes by the sniffer the wall already uses. An SVG is XML
that can carry script and would be served from our own origin.
A new table, so `CREATE TABLE IF NOT EXISTS` is enough and no migration is
involved. `FakeRepo` moved from test_content.py into conftest.py, since two
features commit to the content repository now. Verified by building with Hugo
0.135.0 and the pipeline's flags both ways: with a brand.yaml the second
stylesheet, the favicon and the logo appear, and without one the output is
byte-for-byte identical to the build before any of this existed.
545 tests pass.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NizVpJ2dwzCbjCrTLCjeHn
163 lines
6.5 KiB
HTML
163 lines
6.5 KiB
HTML
{# Gestión → Marca: the colours, the logo and the favicon.
|
||
|
||
**This page deliberately does not load the generated stylesheet.** Every
|
||
other page in the members area does, and the free CSS box below can contain
|
||
anything — including `* { display: none }`. If that CSS applied here, the one
|
||
screen that can undo it would be the one screen you could not read. So the
|
||
block is overridden with nothing and this page is always in the factory
|
||
colours. The live preview below is where the admin sees their own.
|
||
|
||
The consequence is worth stating because it looks like an oversight: the
|
||
colours an admin picks do not show on the page where they pick them. #}
|
||
{% extends "base.html" %}
|
||
{% block title %}Marca{% endblock %}
|
||
{% block brand_css %}{% endblock %}
|
||
|
||
{% block main %}
|
||
<div class="feed-head">
|
||
<h1>Marca</h1>
|
||
<a class="linkish" href="{{ url_for('home.gestion') }}">Volver a Gestión</a>
|
||
</div>
|
||
|
||
<p class="muted">
|
||
Los colores, el logotipo y el icono de la pestaña, para las dos mitades del
|
||
sitio. El área privada cambia al guardar; vienalatina.com se reconstruye en
|
||
un par de minutos.
|
||
</p>
|
||
|
||
{% if state.updated_at and not state.published_at %}
|
||
<section class="panel panel--attention">
|
||
<div class="panel__head">
|
||
<h2>Pendiente de publicar</h2>
|
||
</div>
|
||
<p class="panel__row">
|
||
Lo de aquí está guardado, pero no ha llegado al sitio público: no se pudo
|
||
contactar con el servidor de git la última vez.
|
||
</p>
|
||
<form method="post" action="{{ url_for('brand.publish') }}">
|
||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||
<button class="btn" type="submit">Reintentar publicar en el sitio</button>
|
||
</form>
|
||
</section>
|
||
{% endif %}
|
||
|
||
{% for note in notes %}
|
||
<p class="flash flash--error">{{ note }}</p>
|
||
{% endfor %}
|
||
|
||
<form class="card" method="post" enctype="multipart/form-data"
|
||
action="{{ url_for('brand.edit') }}">
|
||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||
|
||
<h2 class="section-title">Colores</h2>
|
||
<p class="muted small">
|
||
Seis colores. Los demás —los tonos claros y oscuros del principal— se
|
||
calculan a partir de él, para que no haya que acertar con cinco rojos
|
||
parecidos. Están en «Avanzado» si los quieres a mano.
|
||
</p>
|
||
|
||
{# A real colour picker, which every current browser draws natively: no
|
||
dependency, no script, and it works with a keyboard. The text beside each
|
||
one says where that colour shows up, because "--surface-soft" is not a
|
||
question an admin can answer. #}
|
||
<div class="swatches" data-brand-preview>
|
||
{% for name, label, where in simple %}
|
||
<div class="swatch">
|
||
<label for="token-{{ name }}">{{ label }}</label>
|
||
<input id="token-{{ name }}" name="token-{{ name }}" type="color"
|
||
data-token="{{ name }}" value="{{ state.tokens[name] }}">
|
||
<p class="muted small">{{ where }}</p>
|
||
</div>
|
||
{% endfor %}
|
||
</div>
|
||
|
||
{# Restyled by the pickers above, through board.js setting the custom
|
||
properties on this element. The DOM write is not an inline style
|
||
attribute in the HTML, which is why it works under the CSP. #}
|
||
<div class="brand-preview" data-brand-preview-target>
|
||
<div class="brand-preview__bar">Viena Latina</div>
|
||
<div class="brand-preview__card">
|
||
<p class="brand-preview__meta">Ana Pérez · hace dos horas</p>
|
||
<p>Así se verá una tarjeta del muro con estos colores.</p>
|
||
<span class="brand-preview__btn">Un botón</span>
|
||
</div>
|
||
</div>
|
||
|
||
<h2 class="section-title">Logotipo</h2>
|
||
<p class="muted small">
|
||
PNG, JPG o WebP. Aparece en la cabecera de las dos mitades del sitio y es
|
||
la imagen que sale al compartir un enlace que no tiene foto propia.
|
||
{% if state.logo_name %}Ahora hay uno puesto; si eliges otro, lo reemplaza.{% endif %}
|
||
</p>
|
||
{% if state.logo_name %}
|
||
<p><img class="brand-current"
|
||
src="{{ url_for('brand.picture', stored_name=state.logo_name) }}?v={{ state.stamp }}"
|
||
alt="El logotipo actual"></p>
|
||
{% endif %}
|
||
<input id="logo" name="logo" type="file" accept="image/png,image/jpeg,image/webp">
|
||
|
||
<h2 class="section-title">Icono de la pestaña</h2>
|
||
<p class="muted small">
|
||
PNG, y cuadrado: 32×32 o 180×180 van bien. Se sube aparte y no se saca del
|
||
logotipo — recortar un logotipo ancho a un cuadrado da un trozo de letra.
|
||
</p>
|
||
{% if state.favicon_name %}
|
||
<p><img class="brand-current brand-current--small"
|
||
src="{{ url_for('brand.picture', stored_name=state.favicon_name) }}?v={{ state.stamp }}"
|
||
alt="El icono actual"></p>
|
||
{% endif %}
|
||
<input id="favicon" name="favicon" type="file" accept="image/png">
|
||
|
||
<details class="brand-advanced">
|
||
<summary>Avanzado</summary>
|
||
|
||
<p class="muted small">
|
||
Para quien sepa CSS. Todo lo de aquí se aplica después de lo de arriba,
|
||
así que gana. Si algo sale mal, «Restaurar lo de fábrica» está al final
|
||
de esta página y esta página nunca carga este CSS, justamente para que
|
||
se pueda llegar a ese botón.
|
||
</p>
|
||
|
||
<h3 class="section-title">Los demás colores</h3>
|
||
<p class="muted small">
|
||
Déjalos en blanco para que se calculen desde el color principal
|
||
({{ derived|join(', ') }}) o queden como están de fábrica.
|
||
</p>
|
||
<div class="swatches">
|
||
{% for name in advanced %}
|
||
<div class="swatch">
|
||
<label for="token-{{ name }}"><span class="mono">--{{ name }}</span></label>
|
||
<input id="token-{{ name }}" name="token-{{ name }}" type="text"
|
||
value="{{ state.stored.get(name, '') }}"
|
||
placeholder="{{ state.tokens[name] }}"
|
||
pattern="^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$">
|
||
</div>
|
||
{% endfor %}
|
||
</div>
|
||
|
||
<h3 class="section-title">CSS propio</h3>
|
||
<p class="muted small">
|
||
Se añade al final de la hoja de estilos, en las dos mitades del sitio.
|
||
No puede contener «<» ni «>».
|
||
</p>
|
||
<textarea id="custom_css" name="custom_css" rows="10" class="mono"
|
||
placeholder=".site-bar__logo { max-height: 48px; }">{{ state.custom_css }}</textarea>
|
||
</details>
|
||
|
||
<button class="btn" type="submit">Guardar</button>
|
||
</form>
|
||
|
||
{% if state.customised %}
|
||
<form class="card" method="post" action="{{ url_for('brand.restore') }}"
|
||
data-confirm="Se vuelve a los colores originales y se borran el logotipo y el icono. ¿Seguro?">
|
||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||
<h2 class="section-title">Restaurar lo de fábrica</h2>
|
||
<p class="muted small">
|
||
Deja los colores como estaban al principio y quita el logotipo y el icono.
|
||
Esto funciona siempre, incluso si el CSS propio ha roto el resto del sitio.
|
||
</p>
|
||
<button class="btn btn--danger" type="submit">Restaurar lo de fábrica</button>
|
||
</form>
|
||
{% endif %}
|
||
{% endblock %}
|