From 722dac484301b5841032a0c7cb08c83954f5c9b6 Mon Sep 17 00:00:00 2001 From: Daniel Maksymilian Syrnicki Date: Thu, 27 Aug 2026 12:43:46 +0200 Subject: [PATCH] feat(website): randomise which logo comes first on /logo/ per visit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hugo sorts map keys, so `range (dict "m" … "r" …)` always put M first and gave it the "first thing on the page" vote. The template now ranges over an ordered list (front-matter `order:` can pin it), and a tiny inline script on poll pages coin-flips the visual order before first paint, applied via CSS `order` on every M/R pair and remembered in sessionStorage so a reload or a vote doesn't shuffle the page. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01Y8kPxizsExc95ZhvfJmaCw --- website/assets/css/main.css | 8 ++++++++ website/layouts/partials/head.html | 6 +++++- website/layouts/poll/single.html | 23 ++++++++++++----------- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/website/assets/css/main.css b/website/assets/css/main.css index ca1d234..52a7ad7 100644 --- a/website/assets/css/main.css +++ b/website/assets/css/main.css @@ -559,4 +559,12 @@ main.container { .home-poll:hover { border-color: var(--accent); } .home-poll .pm { height: 1.1rem; width: auto; color: var(--accent); } .home-poll .pm + .pm { color: #af6428; } +/* Random left/right per visit — data-logo-order is set in head.html before first paint. + Every pair container is a grid/flex, so `order` swaps the columns without touching the DOM. */ +[data-logo-order="rm"] .poll-card[data-choice="m"], +[data-logo-order="rm"] .show-cell.show-cell--m, +[data-logo-order="rm"] .poll-final-card[data-choice="m"], +[data-logo-order="mr"] .poll-card[data-choice="r"], +[data-logo-order="mr"] .show-cell.show-cell--r, +[data-logo-order="mr"] .poll-final-card[data-choice="r"] { order: 1; } @media (prefers-reduced-motion: reduce) { .poll-bar i, .poll-btn { transition: none; } } diff --git a/website/layouts/partials/head.html b/website/layouts/partials/head.html index 4c83b53..f32076a 100644 --- a/website/layouts/partials/head.html +++ b/website/layouts/partials/head.html @@ -1,7 +1,11 @@ -{{ if .IsHome }}{{ site.Title }} — {{ site.Params.description }}{{ else }}{{ .Title }} · {{ site.Title }}{{ end }} +{{ if eq .Type "poll" }}{{/* Coin-flip which mark sits left/first, so neither side collects the + "first thing on the page" votes. Decided before first paint (no reflow), applied by CSS `order`, + and kept for the tab session so a reload or a vote doesn't shuffle the page under the visitor. */}} + +{{ end }}{{ if .IsHome }}{{ site.Title }} — {{ site.Params.description }}{{ else }}{{ .Title }} · {{ site.Title }}{{ end }} diff --git a/website/layouts/poll/single.html b/website/layouts/poll/single.html index ae1065a..cf83d34 100644 --- a/website/layouts/poll/single.html +++ b/website/layouts/poll/single.html @@ -1,7 +1,8 @@ {{ define "main" }} {{- $p := .Params -}} -{{- $M := site.Data.logo.m -}} -{{- $R := site.Data.logo.r -}} +{{/* Display order of the two marks; flip via `order: [r, m]` in front matter so neither + side gets the "first thing on the page" advantage for the whole poll. */}} +{{- $order := $p.order | default (slice "m" "r") -}} {{- $s := $p.show -}}