How a static site goes quiet for a poll blackout

Àgora is our site for following the Spanish general election of 29 November 2026. It is fully static: a Cloudflare Worker that only serves assets, with no server code, no database and no key-value store. Part of what it shows comes from opinion polls: an average of them, and a seat projection built on that average. Spanish electoral law forbids publishing those in the last days before the vote, so on a fixed date the site has to stop showing them.

A server could stop answering. A static site cannot: every file already uploaded keeps being served until someone uploads different files. This post describes what we built for that, from the code at commit 482cf31 of the Àgora repo (4 November 2026). It is not legal advice, and it ends with what the approach cannot control.

The rule, and the dates in the code

The rule is article 69.7 of the Ley Orgánica del Régimen Electoral General (LOREG). We read the consolidated text on the BOE website on 6 November 2026. It says that during the five days before the vote, the “publicación y difusión o reproducción de sondeos electorales” through any media outlet is forbidden.

With the vote on Sunday 29 November, those five days are 24 to 28 November. The law does not spell out the day of the vote itself. Our docs (docs/fonts-de-dades.md, section 7) record that Junta Electoral Central doctrine, as we have it second-hand, keeps results back until the polling stations close, and that we found no official source for the closing time in the Canary Islands, where it is one hour earlier than on the mainland. So we chose a longer window than the law’s five days, and that choice is in the code:

export const BLACKOUT_START = new Date('2026-11-24T00:00:00+01:00');
export const BLACKOUT_END = new Date('2026-11-29T21:00:00+01:00');

That is 24 November at 00:00 until 29 November at 21:00 peninsular time (20:00 in the Canaries). The docs also admit an open question: whether an aggregator site counts as a “medio de comunicación” is not defined by the law, and the docs recommend validating the scope with a lawyer. We did not wait for that answer. If in doubt, the site goes quiet.

One flag, read when the site is built

Astro generates every page at build time, so the question “are we in the blackout?” is asked once per build, not once per visit. The whole decision is one function in src/lib/blackout.ts.

Simplified from src/lib/blackout.ts (comments removed):

export function isPollBlackout(now: Date = new Date()): boolean {
  const forced = typeof process !== 'undefined' ? process.env?.AGORA_BLACKOUT : undefined;
  if (forced === '1') return true;
  if (forced === '0') return false;
  return now >= BLACKOUT_START && now < BLACKOUT_END;
}

Without the environment variable, the clock of the machine that builds decides. AGORA_BLACKOUT=1 forces the quiet build and AGORA_BLACKOUT=0 forces the normal one, which is how we test both sides before the date. The build code and the browser code import the same function, so the window is defined once.

What goes quiet and what stays

When the function returns true, the pages that depend on polls change shape. The polls page (PollsView.astro) does not even load the data: const model = blackout ? null : await getPollsModel();. The projection has the same rule, since getScenario() in src/features/model/scenario.ts returns null and never loads the inputs. The home, model and seats pages keep their routes but show a notice in place of the figures.

Not everything is hidden. The 23 July 2023 election results, the party pages, the legislature section (votes and affinities between parties) and the pact calculator are not derived from polls. In the build with the flag on, data/promises.json, the file with party commitments, is still in dist/; the QA report finds it only because it mentions a media outlet by name. The pact calculator also offers a projection as a seat source. In the quiet build the option does not exist, and if a link arrives with the projection’s m= parameter in the URL hash, mount.ts removes it.

The line we drew is the one our docs write down: from 24 November, show only what is not based on polls, and say so with a notice.

The guard in the browser

A build only knows about the day it ran. A visitor can open a page built on 20 November and leave it open past midnight, or the clock can pass the start date while an old build is still being served. For that, the figures in a normal build sit inside elements marked data-poll-figures, and PollBlackout.astro adds a small inline script.

Simplified from src/components/PollBlackout.astro:

var s = Date.parse('2026-11-23T23:00:00.000Z');
var e = Date.parse('2026-11-29T20:00:00.000Z');
function check() {
  var n = Date.now();
  if (n >= s && n < e) {
    document.querySelectorAll('[data-poll-figures]').forEach(function (el) { el.remove(); });
    document.querySelectorAll('[data-poll-guard-notice]').forEach(function (el) { el.hidden = false; });
    document.documentElement.setAttribute('data-poll-blackout', '1');
    return true;
  }
  return false;
}
if (!check()) setInterval(check, 30000);

It runs as soon as the page is painted, then every 30 seconds. It removes the figures, shows the notice and sets data-poll-blackout on <html>, which the interactive parts (model, pacts) check before mounting.

The comment in the file calls this a safety net, and the QA notes are blunter: the HTML served before the 24th still contains the figures, and anyone who views the source or runs curl sees them. The guard only hides what a person looks at. It also never brings the figures back: when the window ends with a page open, you have to reload.

The redeploy is the real switch

Since the build decides, the legal cut is a deploy. docs/runbook-29n.md fixes the calendar:

When (Spain)WhatCommand
24 Nov, 00:00 (the docs say a few minutes earlier)Build with AGORA_BLACKOUT=1 and deploynode scripts/deploy/scheduled.mjs blackout-on --execute
29 Nov, from 21:00Normal build and deploy; the script refuses to run earliernode scripts/deploy/scheduled.mjs blackout-off --execute

scripts/deploy/scheduled.mjs is a dry run by default and only acts with --execute. It reads the two dates from blackout.ts with a regular expression and starts the blackout --lead-min minutes early (30 by default). The docs explain why: a late redeploy would break the rule, an early one only hides the polls sooner. On the way out there is no margin, and blackout-off exits with an error before 21:00 unless --force is passed.

Between the two, the task auto reconciles: it works out the state the site should be in and deploys only if the last recorded deploy in .deploy/state.json differs.

Simplified from scripts/deploy/scheduled.mjs:

const effectiveStart = new Date(+START - leadMin * 60_000);
const inSilence = now >= effectiveStart && now < END;
// in auto:
const desired = inSilence ? 'blackout' : 'open';
if (st.deployed !== desired) return desired === 'blackout' ? tBlackoutOn() : now >= END ? tBlackoutOff() : tPolls();

If the laptop running it was asleep at midnight, it catches up on waking. The daily polls refresh skips itself inside the window.

Before anything is uploaded, scripts/deploy/predeploy.mjs checks the build against the clock. Inside the window it fails if the polls page contains data-poll-figures, if the model page contains the model-config element, if data/polls.json exists, or if the polls page has no notice. It also fails if AGORA_BLACKOUT is set in the shell, because that could bypass the date. The scheduled script sets it for the build only, unsets it for this check and passes --allow-forced-blackout. Outside the window, a quiet build only produces a warning.

Embeds, share images, open data and caches

Embeds. Other sites can embed the projection from /embed/<lang>/hemicycle/model/ and the cartogram equivalent. Those routes exist in every build, because an iframe that is already placed should not turn into a 404, but in the quiet build they render only the notice. The “Insert” generator stops offering them (embedOptions filters out everything whose source is model).

Share images. Pages with a polls or model section have a generated Open Graph image. In a quiet build ogCatalog() leaves both out for the four languages, and those pages point to the generic home image. share.test.ts asserts that og/<lang>/model.png and og/<lang>/polls.png do not exist.

Open data. The cleaned polls are exported as /data/polls.json under CC BY-SA 4.0. It is a static file, so a browser guard could never hide it. It is generated only outside the window:

export const getStaticPaths = (() => (isPollBlackout() ? [] : [{ params: { name: 'polls' } }])) satisfies GetStaticPaths;

That is why it lives in src/pages/ and not in public/: a file in public/ would be copied in any case. The QA run got HTTP 200 for it in a normal build and 404 in a quiet one.

Sitemap. Nothing changes. The configuration in astro.config.mjs excludes only the 404 page and the embeds and does not read the flag, so the same URLs stay listed; the polls page is just a page with a notice.

Caches. public/_headers gives /og/* a max-age of 86,400 seconds, one day. The QA notes say the browser tests do not cover any CDN or intermediate cache, so after each deploy scripts/ops/verify-site.mjs fetches production with --expect blackout (24th) or --expect open (29th).

How we check it

  1. npm run qa:blackout (scripts/qa/blackout.mjs). Part (a) builds normally and loads the 56 section pages (14 routes times 4 languages) in Playwright with a fake browser clock at three moments: 23 November 23:59, 25 November 12:00 and 29 November 21:01. Inside the window it expects zero data-poll-figures elements and no numeric token that is absent from the same page built with the flag on. It also runs a page opened at 23:59:40 across midnight. Part (b) builds with AGORA_BLACKOUT=1 and searches the output for pollster and media names, the current average, the model’s keys and its seat medians. The last run in the repo (generated 2 November 2026) reports 0 failures: 16 pages carry figures before and after the window (home, polls, model and seats, in four languages) and none carries them inside it, and the 10,041 text files searched contain no poll figure among their matches. The search does match 22 terms in 3,403 files; docs/qa/silenci.md analyses them as methodology text, code identifiers and coincidences with official data.
  2. npm run test:share-blackout builds with the flag into dist-blackout and runs the share tests against it: no projection in the embeds, no OG images for polls and model, and no projection option in the generator.
  3. scripts/integration.mjs with MODE=blackout after a quiet build: /data/polls.json returns 404 and the polls page shows the notice.

The written analysis in docs/qa/silenci.md records what the first runs caught: a model-config script that stayed in the page and carried the full poll averages, and an embed option on the hemicycle page that offered to reproduce the projection.

What we can’t control, and what is open