vienalatina/themes/vienalatina/assets/js/agenda.js
Claude 5e8ee5ad20
Two calendars: one for everybody, one for the members
**Public events are posts.** A new Evento category brings three fields with it —
event_date, event_time, event_location — and the first is required, because a
post's own `date` is when it was announced and an event announced three weeks
early would otherwise land in the agenda on the wrong day. Members propose
events through the same queue as everything else, and the date survives approval
untouched: the event the member described is the event that gets published.

An event's page leads with the day, the time and the place before the title,
shows its picture full width, and offers "añadir a mi calendario" — a real .ics
beside the page, generated because the editor writes `outputs: ["HTML", "ics"]`
into an event's frontmatter and nothing else asks for that format. It carries
Event structured data as well as the BlogPosting it already had, which is what
puts a date beside the result in a search listing.

/page/agenda/ is a month grid per month, every month from the first event to the
last built at build time, with a script that shows one and moves between them.
That arrangement is the point: with JavaScript off every month is on the page as
a list, with it on nothing is fetched to change months, and the month it opens on
is the reader's rather than the one the site was built in. Hugo exposes no
AddDate, so the length of a month is a table plus the leap rule and the first
weekday falls out of formatting the date — it looks like something simpler was
missed, and it is not.

**The private calendar** is a sixth section: rows in SQLite, written by admins,
read by every member, never published. It shows the public events too, marked,
so a member has one place to look rather than two — they come from the
content_cache the editor's listing already fills, which is why migration 5 adds
three columns to it and to submissions. The grid is Python's own
calendar.Calendar: no date arithmetic of mine anywhere in it.

Two things the tests found on the way:

gitea.py let `requests`' own exceptions through. They inherit from OSError, not
from GiteaError, so the calendar's careful "keep working while the git server is
down" would have been defeated by a refused connection — the page would have
500ed instead. Every transport failure is now a GiteaError, raised at the one
place that touches the wire. This is the third bug of exactly that shape in this
module.

An admin's erasure clears events.created_by rather than reassigning it. The
meeting still happens after they leave; the event belongs to the association.

509 tests pass, and the site builds with Hugo 0.135.0 under the pipeline's own
--panicOnWarning.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NizVpJ2dwzCbjCrTLCjeHn
2026-10-03 09:53:54 +00:00

53 lines
1.9 KiB
JavaScript

// Which month the agenda is showing.
//
// Every month is already on the page — the layout builds them all — so this
// only decides which one is visible and moves between them. Three consequences
// worth keeping: a reader with no JavaScript sees every month stacked instead of
// a blank page, moving months makes no request, and the month it starts on is
// decided here rather than when the site was built, so it is right however long
// ago that was.
(function () {
"use strict";
var months = [].slice.call(document.querySelectorAll(".agenda__month"));
if (months.length === 0) return;
var label = document.querySelector("[data-agenda-label]");
var buttons = [].slice.call(document.querySelectorAll("[data-agenda-move]"));
var keys = months.map(function (section) { return section.dataset.month; });
// The month the reader is in, or the nearest one the page has.
var now = new Date();
var current = now.getFullYear() + "-" + ("0" + (now.getMonth() + 1)).slice(-2);
var index = keys.indexOf(current);
if (index === -1) {
index = 0;
for (var i = 0; i < keys.length; i++) {
if (keys[i] <= current) index = i;
}
}
function show(next) {
index = Math.max(0, Math.min(months.length - 1, next));
months.forEach(function (section, i) {
section.hidden = i !== index;
});
if (label) label.textContent = months[index].dataset.label;
buttons.forEach(function (button) {
var step = parseInt(button.dataset.agendaMove, 10);
button.disabled = index + step < 0 || index + step > months.length - 1;
});
}
buttons.forEach(function (button) {
button.addEventListener("click", function () {
show(index + parseInt(button.dataset.agendaMove, 10));
});
});
// Only now: until this runs the page is the no-JavaScript version, every
// month visible, which is what a crawler and a reader without scripts get.
document.documentElement.classList.add("has-agenda-script");
show(index);
})();