vienalatina/themes/vienalatina/assets/js/memberbar.js
Claude 8936f296ea
Textos: the words are data now, starting with the navigation
Renaming «Inicio» was six edits — base.html, home.py's section list,
config.yaml three times, an aria-label, and the breadcrumb schema — and
none of them reachable from Gestión. That is the thing Identidad exists
to end for the site's name, and it stopped before it reached the labels.

The mechanism, and the navigation through it. The rest of the ~560
strings follow in later commits; this one is the path proved end to end.

apps/board/strings/*.yaml is the catalogue, shipped in the image through
the Dockerfile's existing COPY. Only the differences are stored, which
is brand.FACTORY's rule and buys the same thing: a wording I improve
later improves for everyone who has not deliberately overridden it.

The `site.` prefix decides everything — one box or three, SQLite or a
commit of data/ui.yaml, this page load or the next pipeline run.

The fallback order is a judgement rather than an accident: an override
for the asked-for language, then the *shipped* word in that language,
then Spanish. Somebody who reworded only the Spanish has said nothing
about German, and showing a German reader Spanish would be reading an
intention into silence. Verified in a real build: with es overridden,
the Spanish menu says «Escritorio» and the German still says «Start».

The screen is generic — it iterates the catalogue, so extracting another
hundred strings costs nothing here. There is no field list in ui.py and
there must never be one.

Two guards are what make a 560-string extraction mechanical rather than
risky: every t("…") used must exist, and every key defined must be used.
A typo renders as nav.incio on a page; an orphan is a box in Gestión
that changes nothing. Both fail the suite instead. I proved all three
guards (including the one holding t.html to the catalogue) by
introducing the bug each describes and watching it go red.

Two things fixed on the way, both found by the extraction rather than
looked for: home.py and base.html held two copies of the same six words,
so a rename would have reached the members area and not the strip on the
public site; and memberbar.js hardcoded two more in a fingerprinted
script, the one surface no setting could ever reach.

No migration — `strings` is a new table, so CREATE TABLE IF NOT EXISTS
makes it, as activity and site arrived. The erase guard caught the new
members(id) reference by itself, which is the mechanism working.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NizVpJ2dwzCbjCrTLCjeHn
2026-10-14 12:35:10 +00:00

92 lines
3.4 KiB
JavaScript

// The signed-in strip on the public site.
//
// vienalatina.com is files on disk. They are the same files for everyone and
// they get cached, so the one thing they cannot contain is who is reading them.
// This asks the members area instead, and draws a bar above the header when the
// answer is somebody.
//
// Three decisions worth knowing before changing anything here:
//
// * **It does nothing without the hint cookie.** `vl_sesion` is set at sign-in
// and cleared at sign-out, holds the digit 1, and exists so that a stranger
// reading one article costs zero requests to the app. It is not trusted for
// anything: the server decides, and a forged hint earns a request that says
// "not signed in".
// * **Every value goes in as text, never as HTML.** A display name is whatever
// somebody typed into a form. textContent makes that a name; innerHTML would
// make it a script.
// * **No frameworks, no build step.** Hugo fingerprints this file and serves it
// from our own domain, which is the only place the site loads anything from.
(function () {
"use strict";
if (document.cookie.indexOf("vl_sesion=1") === -1) {
return;
}
function el(tag, className, text) {
var node = document.createElement(tag);
if (className) node.className = className;
if (text !== undefined) node.textContent = text;
return node;
}
function draw(state) {
var bar = el("div", "member-bar");
bar.setAttribute("role", "navigation");
// From the endpoint, not from here: these were the one part of the
// signed-in strip that no setting could reach, because a word in a
// fingerprinted script is a word only a deploy can change.
var labels = state.labels || {};
bar.setAttribute("aria-label", labels.bar || "Área de miembros");
var inner = el("div", "member-bar__inner");
var links = el("ul", "member-bar__links");
state.sections.forEach(function (section) {
var item = document.createElement("li");
var link = el("a", null, section.label);
link.href = section.url;
item.appendChild(link);
links.appendChild(item);
});
inner.appendChild(links);
var account = el("div", "member-bar__account");
var me = el("a", "member-bar__name", state.name);
me.href = state.profile;
account.appendChild(me);
// A real form, because signing out changes something and a link that
// changes something is a link a prefetching browser will follow by itself.
var form = document.createElement("form");
form.method = "post";
form.action = state.logout;
var token = document.createElement("input");
token.type = "hidden";
token.name = "csrf_token";
token.value = state.csrf;
form.appendChild(token);
var out = el("button", "member-bar__out", labels.logout || "Salir");
out.type = "submit";
form.appendChild(out);
account.appendChild(form);
inner.appendChild(account);
bar.appendChild(inner);
document.body.insertBefore(bar, document.body.firstChild);
document.body.classList.add("has-member-bar");
}
fetch("/comunidad/sesion.json", { credentials: "same-origin" })
.then(function (response) {
return response.ok ? response.json() : null;
})
.then(function (state) {
if (state && state.signed_in) draw(state);
})
.catch(function () {
// The members area being down is not a reason for the public site to
// report anything. No bar, no message, no console noise.
});
})();